mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +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 { 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
|
// eslint-disable-next-line import/prefer-default-export
|
||||||
export async function homeController(req, res) {
|
export async function homeController(req, res) {
|
||||||
const payload = {
|
const payload = {
|
||||||
title: 'Linux Odyssey Admin',
|
title: 'Linux Odyssey Admin',
|
||||||
userCount: await userCount(),
|
userCount: await userCount(),
|
||||||
sessionCount: await sessionCount(),
|
questCount: await questCount(),
|
||||||
sessionCompleted: await sessionCompleted(),
|
questCompleted: await questCompleted(),
|
||||||
}
|
}
|
||||||
payload.completedRate =
|
payload.completedRate =
|
||||||
Math.round((payload.sessionCompleted / payload.sessionCount) * 10000) / 100
|
Math.round((payload.questCompleted / payload.questCount) * 10000) / 100
|
||||||
res.render('home', payload)
|
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>
|
<td>{{userCount}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Session Count</th>
|
<th>Total Started Quests</th>
|
||||||
<td>{{sessionCount}}</td>
|
<td>{{questCount}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Completed Session</th>
|
<th>Completed Quests</th>
|
||||||
<td>{{sessionCompleted}}</td>
|
<td>{{questCompleted}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Completed Rate</th>
|
<th>Completed Rate</th>
|
||||||
|
|||||||
Reference in new issue
Block a user