Add rating algs to the session view.

This commit is contained in:
zkldi
2022-03-25 23:16:17 +00:00
parent f37ae7124f
commit 7056191db5
2 changed files with 51 additions and 0 deletions
@@ -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 (
<>
<StatThing name="Scores" value={session.scoreInfo.length} />
@@ -26,6 +30,33 @@ export default function SessionOverview({
value={FormatDuration(session.timeEnded - session.timeStarted)}
/>
<StatThing md12 name="Highlights" value={scores.filter(e => e.highlight).length} />
<Col xs={12}>
<Divider />
<div className="card">
<div className="card-body">
<div className="display-4 text-center">Ratings</div>
<Divider />
<div
className="d-flex text-center"
style={{ justifyContent: "space-evenly" }}
>
{gptConfig.sessionRatingAlgs.map(e => (
<div key={e}>
<div className="display-4">{UppercaseFirst(e)}</div>
<div style={{ fontSize: "1.2rem" }}>
{FormatSessionRating(
session.game,
session.playtype,
e,
session.calculatedData[e]
)}
</div>
</div>
))}
</div>
</div>
</div>
</Col>
<Col xs={12}>
<Divider />
<Card header="Highlights">
+20
View File
@@ -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<I extends IDStrings = IDStrings>(
game: Game,
playtype: Playtype,