From 7056191db55be6873f49116df9708d62e99a3ef8 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Fri, 25 Mar 2022 23:16:17 +0000 Subject: [PATCH] Add rating algs to the session view. --- .../components/sessions/SessionOverview.tsx | 31 +++++++++++++++++++ client/src/util/misc.ts | 20 ++++++++++++ 2 files changed, 51 insertions(+) diff --git a/client/src/components/sessions/SessionOverview.tsx b/client/src/components/sessions/SessionOverview.tsx index dc28f388f..fc5ddd961 100644 --- a/client/src/components/sessions/SessionOverview.tsx +++ b/client/src/components/sessions/SessionOverview.tsx @@ -1,4 +1,5 @@ import { FormatDuration } from "util/time"; +import { FormatSessionRating, UppercaseFirst } from "util/misc"; import Card from "components/layout/page/Card"; import ScoreTable from "components/tables/scores/ScoreTable"; import Divider from "components/util/Divider"; @@ -7,6 +8,7 @@ import React, { useContext } from "react"; import { Col } from "react-bootstrap"; import { SessionReturns } from "types/api-returns"; import { ScoreDataset } from "types/tables"; +import { GetGamePTConfig } from "tachi-common"; export default function SessionOverview({ sessionData, @@ -18,6 +20,8 @@ export default function SessionOverview({ const { scores, session } = sessionData; const { user } = useContext(UserContext); + const gptConfig = GetGamePTConfig(session.game, session.playtype); + return ( <> @@ -26,6 +30,33 @@ export default function SessionOverview({ value={FormatDuration(session.timeEnded - session.timeStarted)} /> e.highlight).length} /> + + +
+
+
Ratings
+ +
+ {gptConfig.sessionRatingAlgs.map(e => ( +
+
{UppercaseFirst(e)}
+
+ {FormatSessionRating( + session.game, + session.playtype, + e, + session.calculatedData[e] + )} +
+
+ ))} +
+
+
+ diff --git a/client/src/util/misc.ts b/client/src/util/misc.ts index 9fc11f78b..3f9e54174 100644 --- a/client/src/util/misc.ts +++ b/client/src/util/misc.ts @@ -11,6 +11,7 @@ import { integer, ScoreCalculatedDataLookup, ScoreDocument, + SessionDocument, } from "tachi-common"; import { Playtype } from "types/tachi"; @@ -246,6 +247,25 @@ export function FormatScoreRating( return formatter(value); } +export function FormatSessionRating( + game: Game, + playtype: Playtype, + rating: keyof SessionDocument["calculatedData"], + value: number | null | undefined +) { + if (value === null || value === undefined) { + return "No Data."; + } + + const formatter = GetGamePTConfig(game, playtype).sessionRatingAlgFormatters[rating]; + + if (!formatter) { + return value.toFixed(2); + } + + return formatter(value); +} + export function GetGradeFromPercent( game: Game, playtype: Playtype,