mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix dashboard cards
This commit is contained in:
@@ -23,7 +23,7 @@ const props = defineProps<{
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col grow">
|
<div class="flex flex-col grow">
|
||||||
<div class="flex items-end gap-2">
|
<div class="flex items-end gap-2">
|
||||||
<div class="brockmann text-text-dirty text-[1.6rem] 2xl:text-[2rem]"> {{ value }} </div>
|
<div class="brockmann text-text-dirty text-[1.6rem] 2xl:text-[1.9rem]"> {{ value }} </div>
|
||||||
<div class="poppins text-text-sub text-[.7rem] 2xl:text-[.85rem] mb-2"> {{ avg }} </div>
|
<div class="poppins text-text-sub text-[.7rem] 2xl:text-[.85rem] mb-2"> {{ avg }} </div>
|
||||||
</div>
|
</div>
|
||||||
<div class="poppins text-text-sub text-[.9rem] 2xl:text-base"> {{ text }} </div>
|
<div class="poppins text-text-sub text-[.9rem] 2xl:text-base"> {{ text }} </div>
|
||||||
|
|||||||
@@ -72,9 +72,11 @@ async function loadData(timelineEndpointName: string, target: Data) {
|
|||||||
const pool = [...response.map(e => e.count)];
|
const pool = [...response.map(e => e.count)];
|
||||||
pool.pop();
|
pool.pop();
|
||||||
const avg = pool.reduce((a, e) => a + e, 0) / pool.length;
|
const avg = pool.reduce((a, e) => a + e, 0) / pool.length;
|
||||||
const diffPercent = (100 / avg * (response.at(-1)?.count || 0)) - 100;
|
|
||||||
target.trend = diffPercent;
|
const diffPercent: number = (100 / avg * (response.at(-1)?.count || 0)) - 100;
|
||||||
|
|
||||||
|
target.trend = Math.max(Math.min(diffPercent, 99), -99);
|
||||||
|
|
||||||
target.ready = true;
|
target.ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
|||||||
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
import { SessionModel } from "@schema/metrics/SessionSchema";
|
import { SessionModel } from "@schema/metrics/SessionSchema";
|
||||||
import { COUNTS_EXPIRE_TIME, COUNTS_SESSIONS_EXPIRE_TIME, Redis } from "~/server/services/CacheService";
|
import { COUNTS_EXPIRE_TIME, COUNTS_SESSIONS_EXPIRE_TIME, Redis } from "~/server/services/CacheService";
|
||||||
|
import { EventModel } from "@schema/metrics/EventSchema";
|
||||||
|
import { VisitModel } from "@schema/metrics/VisitSchema";
|
||||||
|
|
||||||
export type MetricsCounts = {
|
export type MetricsCounts = {
|
||||||
eventsCount: number,
|
eventsCount: number,
|
||||||
@@ -54,19 +56,16 @@ export default defineEventHandler(async event => {
|
|||||||
const totalSessionsTime = sessionsVisitsCount.reduce((a, e) => a + e.time, 0);
|
const totalSessionsTime = sessionsVisitsCount.reduce((a, e) => a + e.time, 0);
|
||||||
const avgSessionDuration = totalSessionsTime / totalSessions;
|
const avgSessionDuration = totalSessionsTime / totalSessions;
|
||||||
|
|
||||||
const year = new Date().getFullYear();
|
const firstEvent = await EventModel.findOne({ project_id: project._id }, { created_at: 1 });
|
||||||
const month = new Date().getMonth();
|
const firstView = await VisitModel.findOne({ project_id: project._id }, { created_at: 1 });
|
||||||
|
|
||||||
const firstEventDate = new Date(year, month, 0, 0, 0, 0, 0).getTime();
|
|
||||||
const firstViewDate = new Date(year, month, 0, 0, 0, 0, 0).getTime();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
eventsCount: count[0].events,
|
eventsCount: count[0].events,
|
||||||
visitsCount: count[0].visits,
|
visitsCount: count[0].visits,
|
||||||
sessionsVisitsCount: totalSessions || 0,
|
sessionsVisitsCount: totalSessions || 0,
|
||||||
avgSessionDuration,
|
avgSessionDuration,
|
||||||
firstEventDate,
|
firstEventDate: firstEvent?.created_at.getTime() || Date.now(),
|
||||||
firstViewDate,
|
firstViewDate: firstView?.created_at.getTime() || Date.now(),
|
||||||
} as MetricsCounts;
|
} as MetricsCounts;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user