mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
fix: re-calculate completed rate in analytics
This commit is contained in:
1 parent
b625abae68
commit
c243e29002
3 files changed
+28
-8
No files matched your search
@@ -1,15 +1,15 @@
|
||||
import { userCount } from '../models/users.js'
|
||||
import { sessionCount, sessionCompleted } from '../models/sessions.js'
|
||||
import { questCount, questCompleted } from '../models/profiles.js'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function homeController(req, res) {
|
||||
const payload = {
|
||||
title: 'Linux Odyssey Admin',
|
||||
userCount: await userCount(),
|
||||
sessionCount: await sessionCount(),
|
||||
sessionCompleted: await sessionCompleted(),
|
||||
questCount: await questCount(),
|
||||
questCompleted: await questCompleted(),
|
||||
}
|
||||
payload.completedRate =
|
||||
Math.round((payload.sessionCompleted / payload.sessionCount) * 10000) / 100
|
||||
Math.round((payload.questCompleted / payload.questCount) * 10000) / 100
|
||||
res.render('home', payload)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/* eslint-disable object-shorthand */
|
||||
/* eslint-disable func-names */
|
||||
import { UserProfile } from '@linux-odyssey/models'
|
||||
|
||||
export function questCount() {
|
||||
return UserProfile.find().count()
|
||||
}
|
||||
|
||||
export function questCompleted() {
|
||||
return UserProfile.find({
|
||||
$where: function () {
|
||||
for (const key in this.progress) {
|
||||
if (this.progress[key].completed === true) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
}).count()
|
||||
}
|
||||
@@ -7,12 +7,12 @@
|
||||
<td>{{userCount}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Session Count</th>
|
||||
<td>{{sessionCount}}</td>
|
||||
<th>Total Started Quests</th>
|
||||
<td>{{questCount}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Completed Session</th>
|
||||
<td>{{sessionCompleted}}</td>
|
||||
<th>Completed Quests</th>
|
||||
<td>{{questCompleted}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Completed Rate</th>
|
||||
|
||||
Reference in new issue
Block a user