Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): use the rating formatter specified in tachi-common for history graphs #1189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateUserMap } from "util/data";
import { ToFixedFloor, UppercaseFirst } from "util/misc";
import { FormatGPTProfileRating, UppercaseFirst } from "util/misc";
import { NumericSOV, StrSOV } from "util/sorts";
import ClassBadge from "components/game/ClassBadge";
import ScoreLeaderboard from "components/game/ScoreLeaderboard";
Expand Down Expand Up @@ -68,7 +68,7 @@

const SelectComponent =
Object.keys(gptConfig.profileRatingAlgs).length > 1 ? (
<Form.Select value={alg} onChange={(e) => setAlg(e.target.value as any)}>

Check warning on line 71 in client/src/app/pages/dashboard/games/_game/_playtype/GPTLeaderboardsPage.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
{Object.keys(gptConfig.profileRatingAlgs).map((e) => (
<option key={e} value={e}>
{UppercaseFirst(e)}
Expand Down Expand Up @@ -142,9 +142,7 @@
).map((e) => (
<td key={e}>
{r.ratings[e]
? gptConfig.profileRatingAlgs[e].formatter
? gptConfig.profileRatingAlgs[e].formatter!(r.ratings[e]!)
: ToFixedFloor(r.ratings[e]!, 2)
? FormatGPTProfileRating(game, playtype, e, r.ratings[e]!)
: "No Data."}
</td>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClumpActivity } from "util/activity";
import { ToFixedFloor, UppercaseFirst } from "util/misc";
import { FormatGPTProfileRating, UppercaseFirst } from "util/misc";
import { FormatDate, MillisToSince } from "util/time";
import TimelineChart from "components/charts/TimelineChart";
import useSetSubheader from "components/layout/header/useSetSubheader";
Expand All @@ -17,7 +16,14 @@ import SelectButton from "components/util/SelectButton";
import { useProfileRatingAlg } from "components/util/useScoreRatingAlg";
import { DateTime } from "luxon";
import React, { useMemo, useState } from "react";
import { FormatGame, GetGameConfig, GetGamePTConfig, UserGameStats } from "tachi-common";
import {
FormatGame,
Game,
GetGameConfig,
GetGamePTConfig,
Playtype,
UserGameStats,
} from "tachi-common";
import { UGPTHistory } from "types/api-returns";
import { GamePT, SetState, UGPT } from "types/react";
import FormSelect from "react-bootstrap/FormSelect";
Expand Down Expand Up @@ -110,7 +116,13 @@ function UserHistory({

const currentPropValue = useMemo(() => {
if (mode === "rating" && rating) {
return data[0].ratings[rating] ? ToFixedFloor(data[0].ratings[rating]!, 2) : "N/A";
const ratingValue = data[0].ratings[rating];

if (!ratingValue) {
return "N/A";
}

return FormatGPTProfileRating(game, playtype, rating, ratingValue);
} else if (mode === "ranking") {
return (
<>
Expand Down Expand Up @@ -228,17 +240,21 @@ function UserHistory({
</div>
)}

<RatingTimeline {...{ data, rating }} />
<RatingTimeline {...{ game, playtype, data, rating }} />
</>
)}
</>
);
}

function RatingTimeline({
game,
playtype,
data,
rating,
}: {
game: Game;
playtype: Playtype;
data: UGPTHistory;
rating: keyof UserGameStats["ratings"];
}) {
Expand All @@ -259,12 +275,19 @@ function RatingTimeline({
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
format: (y) => (y ? ToFixedFloor(y, 2) : "N/A"),
format: (y) => (y ? FormatGPTProfileRating(game, playtype, rating, y) : "N/A"),
}}
tooltip={(p) => (
<ChartTooltip>
<div>
{p.point.data.y ? ToFixedFloor(p.point.data.y as number, 2) : "N/A"}{" "}
{p.point.data.y
? FormatGPTProfileRating(
game,
playtype,
rating,
p.point.data.y as number
)
: "N/A"}{" "}
{UppercaseFirst(rating)}
</div>
<small className="text-body-secondary">
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/charts/TimelineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function TimelineChart({
<div style={graphStyle}>
<ResponsiveLine
data={data}
margin={{ top: 40, bottom: 40, left: 40, right: 40 }}
margin={{ top: 40, bottom: 40, left: 60, right: 40 }}
xScale={{ type: "time", format: "%Q" }}
xFormat="time:%Q"
gridXValues={3}
Expand Down
1 change: 1 addition & 0 deletions common/src/config/game-support/museca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const MUSECA_SINGLE_CONF = {
curatorSkill: {
description:
"The sum of your best 20 Curator Skills. This is identical to how it's calculated in-game.",
formatter: NoDecimalPlace,
},
},

Expand Down
Loading