Skip to content

Commit 2c6bc47

Browse files
committed
impr(account page): add average accuracy and average consistency to the activity graph
1 parent f6d9b7c commit 2c6bc47

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

frontend/src/ts/controllers/chart-controller.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import chartAnnotation, {
3131
type LabelOptions,
3232
} from "chartjs-plugin-annotation";
3333
import chartTrendline from "chartjs-plugin-trendline";
34-
34+
import { get as getTypingSpeedUnit } from "../utils/typing-speed-units";
3535
import * as ActivePage from "../states/active-page";
3636

3737
Chart.register(
@@ -299,6 +299,9 @@ export type ActivityChartDataPoint = {
299299
x: number;
300300
y: number;
301301
amount?: number;
302+
avgWpm?: number;
303+
avgAcc?: number;
304+
avgCon?: number;
302305
};
303306

304307
export const accountHistory = new ChartWithUpdateColors<
@@ -695,6 +698,9 @@ export const accountActivity = new ChartWithUpdateColors<
695698
animation: { duration: 250 },
696699
intersect: false,
697700
mode: "index",
701+
filter: (tooltipItem): boolean => {
702+
return tooltipItem.datasetIndex === 0;
703+
},
698704
callbacks: {
699705
title: function (tooltipItem): string {
700706
const firstItem = tooltipItem[0] as TooltipItem<"bar" | "line">;
@@ -707,20 +713,22 @@ export const accountActivity = new ChartWithUpdateColors<
707713
const resultData = tooltipItem.dataset.data[
708714
tooltipItem.dataIndex
709715
] as ActivityChartDataPoint;
710-
switch (tooltipItem.datasetIndex) {
711-
case 0:
712-
return `Time Typing: ${DateTime.secondsToString(
713-
Math.round(resultData.y * 60),
714-
true,
715-
true
716-
)}\nTests Completed: ${resultData.amount}`;
717-
case 1:
718-
return `Average ${Config.typingSpeedUnit}: ${Numbers.roundTo2(
719-
resultData.y
720-
)}`;
721-
default:
722-
return "";
723-
}
716+
const typingSpeedUnit = getTypingSpeedUnit(
717+
Config.typingSpeedUnit
718+
);
719+
return `Time Typing: ${DateTime.secondsToString(
720+
Math.round(resultData.y * 60),
721+
true,
722+
true
723+
)}\nTests Completed: ${
724+
resultData.amount
725+
}\nAverage ${Config.typingSpeedUnit.toUpperCase()}: ${Numbers.roundTo2(
726+
typingSpeedUnit.fromWpm(resultData.avgWpm ?? 0)
727+
)}\nAverage Accuracy: ${Numbers.roundTo2(
728+
resultData.avgAcc ?? 0
729+
)}%\nAverage Consistency: ${Numbers.roundTo2(
730+
resultData.avgCon ?? 0
731+
)}%`;
724732
},
725733
label: function (): string {
726734
return "";

frontend/src/ts/pages/account.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ async function fillContent(): Promise<void> {
268268
amount: number;
269269
time: number;
270270
totalWpm: number;
271+
totalAcc: number;
272+
totalCon: number;
271273
}
272274
>;
273275

@@ -529,6 +531,8 @@ async function fillContent(): Promise<void> {
529531
(result.incompleteTestSeconds ?? 0) -
530532
(result.afkDuration ?? 0);
531533
dataForTimestamp.totalWpm += result.wpm;
534+
dataForTimestamp.totalAcc += result.acc;
535+
dataForTimestamp.totalCon += result.consistency ?? 0;
532536
} else {
533537
activityChartData[resultTimestamp] = {
534538
amount: 1,
@@ -537,6 +541,8 @@ async function fillContent(): Promise<void> {
537541
(result.incompleteTestSeconds ?? 0) -
538542
(result.afkDuration ?? 0),
539543
totalWpm: result.wpm,
544+
totalAcc: result.acc,
545+
totalCon: result.consistency ?? 0,
540546
};
541547
}
542548

@@ -682,14 +688,16 @@ async function fillContent(): Promise<void> {
682688
x: dateInt,
683689
y: dataPoint.time / 60,
684690
amount: dataPoint.amount,
691+
avgWpm: Numbers.roundTo2(dataPoint.totalWpm / dataPoint.amount),
692+
avgAcc: Numbers.roundTo2(dataPoint.totalAcc / dataPoint.amount),
693+
avgCon: Numbers.roundTo2(dataPoint.totalCon / dataPoint.amount),
685694
});
686695
activityChartData_avgWpm.push({
687696
x: dateInt,
688697
y: Numbers.roundTo2(
689698
typingSpeedUnit.fromWpm(dataPoint.totalWpm) / dataPoint.amount
690699
),
691700
});
692-
// lastTimestamp = date;
693701
}
694702

695703
const accountActivityScaleOptions = (

0 commit comments

Comments
 (0)