fix: analytics modify

This commit is contained in:
Chen, Tai-Lin committed 2023-12-10 02:21:02 +08:00
1 parent c243e29002
commit 9200336b49
5 files changed
+20 -16

No files matched your search

+4 -4
View File
@@ -1,15 +1,15 @@
import { userCount } from '../models/users.js'
import { questCount, questCompleted } from '../models/profiles.js'
import { totalQuests, totalCompleted } 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(),
questCount: await questCount(),
questCompleted: await questCompleted(),
totalQuests: await totalQuests(),
totalCompleted: await totalCompleted(),
}
payload.completedRate =
Math.round((payload.questCompleted / payload.questCount) * 10000) / 100
Math.round((payload.totalCompleted / payload.totalQuests) * 10000) / 100
res.render('home', payload)
}
+6 -2
View File
@@ -2,11 +2,11 @@
/* eslint-disable func-names */
import { UserProfile } from '@linux-odyssey/models'
export function questCount() {
export function totalQuests() {
return UserProfile.find().count()
}
export function questCompleted() {
export function totalCompleted() {
return UserProfile.find({
$where: function () {
for (const key in this.progress) {
@@ -18,3 +18,7 @@ export function questCompleted() {
},
}).count()
}
export function userProfileList() {
return UserProfile.find()
}
+3 -3
View File
@@ -1,6 +1,6 @@
<h1>Welcome to {{title}}</h1>
<div>
<h2>Users</h2>
<h2>Overview</h2>
<table>
<tr>
<th>Registered Users</th>
@@ -8,11 +8,11 @@
</tr>
<tr>
<th>Total Started Quests</th>
<td>{{questCount}}</td>
<td>{{totalQuests}}</td>
</tr>
<tr>
<th>Completed Quests</th>
<td>{{questCompleted}}</td>
<td>{{totalCompleted}}</td>
</tr>
<tr>
<th>Completed Rate</th>
@@ -36,20 +36,20 @@
<table>
<tr>
<th>Command</th>
<th>Stage</th>
<th>PWD</th>
<th>Input</th>
<th>Output</th>
<th>Error</th>
<th>Stage</th>
<th>Created At</th>
<th>Input Time</th>
</tr>
{{#each commands}}
<tr>
<td>{{command}}</td>
<td>{{stage}}</td>
<td>{{pwd}}</td>
<td>{{command}}</td>
<td>{{output}}</td>
<td>{{error}}</td>
<td>{{stage}}</td>
<td>{{createdAt}}</td>
</tr>
{{/each}}
+2 -2
View File
@@ -4,23 +4,23 @@
<tr>
<th>User</th>
<th>Quest</th>
<th></th>
<th>Status</th>
<th>Created At</th>
<th>Finished At</th>
<th>Used Time</th>
<th>Command Count</th>
<th>Session</th>
</tr>
{{#each sessions}}
<tr>
<td>{{user}}</td>
<td>{{quest}}</td>
<td><a href='/sessions/{{_id}}'>Detail</a></td>
<td>{{status}}</td>
<td>{{createdAt}}</td>
<td>{{finishedAt}}</td>
<td>{{usedTime}}</td>
<td>{{commandCount}}</td>
<td><a href='/sessions/{{_id}}'>Detail</a></td>
</tr>
{{/each}}
</table>