mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: add quest page in analytics
This commit is contained in:
1 parent
a578d4f910
commit
61f627b125
9 files changed
+152
-72
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { userCount } from '../models/users.js'
|
||||
import { totalQuests, totalCompleted } from '../models/profiles.js'
|
||||
import { totalQuests, totalCompleted } from '../models/quests.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function homeController(req, res) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { questList } from '../models/quests.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function questListController(req, res) {
|
||||
const quests = await questList()
|
||||
res.render('quests', { quests })
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
/* eslint-disable func-names */
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
|
||||
export function totalQuests() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function totalCompleted() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
'progress.v.completed': true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function userProfileList() {
|
||||
return UserProfile.find()
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
/* eslint-disable func-names */
|
||||
import { UserProfile, Quest } from '@linux-odyssey/models'
|
||||
|
||||
export function totalQuests() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function totalCompleted() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
progress: { $objectToArray: '$progress' },
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
'progress.v.completed': true,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalCount: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
]).then((results) => {
|
||||
if (results.length === 0) {
|
||||
throw new Error('No documents found')
|
||||
}
|
||||
return results[0].totalCount
|
||||
})
|
||||
}
|
||||
|
||||
export function questList() {
|
||||
return UserProfile.aggregate([
|
||||
{
|
||||
$project: {
|
||||
progress: {
|
||||
$objectToArray: '$progress',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: '$progress',
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: '$progress.v.quest',
|
||||
started: {
|
||||
$sum: 1,
|
||||
},
|
||||
completed: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $eq: ['$progress.v.completed', true] },
|
||||
then: 1,
|
||||
else: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
started: 1,
|
||||
completed: 1,
|
||||
completedRate: {
|
||||
$cond: {
|
||||
if: { $eq: ['$started', 0] },
|
||||
then: 0,
|
||||
else: {
|
||||
$round: [
|
||||
{ $multiply: [{ $divide: ['$completed', '$started'] }, 100] },
|
||||
2,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
_id: 1, // 按任务ID升序排序
|
||||
},
|
||||
},
|
||||
])
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { Router } from 'express'
|
||||
|
||||
import { homeController } from './controllers/index.js'
|
||||
import { userListController } from './controllers/users.js'
|
||||
import { questListController } from './controllers/quests.js'
|
||||
import { commandListController } from './controllers/commands.js'
|
||||
import {
|
||||
sessionDetailController,
|
||||
@@ -12,6 +13,7 @@ const router = Router()
|
||||
|
||||
router.get('/', homeController)
|
||||
router.get('/users', userListController)
|
||||
router.get('/quests', questListController)
|
||||
router.get('/commands', commandListController)
|
||||
router.get('/sessions', sessionListController)
|
||||
router.get('/sessions/:id', sessionDetailController)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<ul>
|
||||
<li><a href='/'>Home</a></li>
|
||||
<li><a href='/users'>Users</a></li>
|
||||
<li><a href='/quests'>Quests</a></li>
|
||||
<li><a href='/commands'>Commands</a></li>
|
||||
<li><a href='/sessions'>Sessions</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<h1>Quests</h1>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Started</th>
|
||||
<th>Completed</th>
|
||||
<th>Completed Rate</th>
|
||||
</tr>
|
||||
{{#each quests}}
|
||||
<tr>
|
||||
<td>{{_id}}</td>
|
||||
<td>{{started}}</td>
|
||||
<td>{{completed}}</td>
|
||||
<td>{{completedRate}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
Whitespace-only changes.
@@ -3,20 +3,20 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Registration Method</th>
|
||||
<th>Registration Time</th>
|
||||
<th>Sessions Count</th>
|
||||
<th>Last Activity</th>
|
||||
<th>Sessions Count</th>
|
||||
<th>Email</th>
|
||||
<th>Registration Time</th>
|
||||
<th>Registration Method</th>
|
||||
</tr>
|
||||
{{#each users}}
|
||||
<tr>
|
||||
<td>{{username}}</td>
|
||||
<td>{{email}}</td>
|
||||
<td>{{method}}</td>
|
||||
<td>{{createdAt}}</td>
|
||||
<td>{{sessionCount}}</td>
|
||||
<td href='/users/{{_id}}'>{{username}}</td>
|
||||
<td>{{lastActivityAt}}</td>
|
||||
<td>{{sessionCount}}</td>
|
||||
<td>{{email}}</td>
|
||||
<td>{{createdAt}}</td>
|
||||
<td>{{method}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
|
||||
Reference in new issue
Block a user