Skip to content

Commit

Permalink
Chartbase end date (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
nour-massri authored Jan 9, 2025
1 parent c46b9a0 commit caf8eb9
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/siarnaq/api/episodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Meta:
"name_long",
"blurb",
"game_release",
"game_archive",
"language",
"scaffold",
"artifact_name",
Expand Down
4 changes: 4 additions & 0 deletions frontend/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,9 @@ components:
game_release:
type: string
format: date-time
game_archive:
type: string
format: date-time
language:
$ref: "#/components/schemas/LanguageEnum"
scaffold:
Expand Down Expand Up @@ -2267,6 +2270,7 @@ components:
required:
- eligibility_criteria
- frozen
- game_archive
- game_release
- language
- name_long
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/api/_autogen/models/Episode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export interface Episode {
* @memberof Episode
*/
game_release: Date;
/**
*
* @type {Date}
* @memberof Episode
*/
game_archive: Date;
/**
*
* @type {LanguageEnum}
Expand Down Expand Up @@ -114,6 +120,7 @@ export function instanceOfEpisode(value: object): boolean {
isInstance = isInstance && "name_short" in value;
isInstance = isInstance && "name_long" in value;
isInstance = isInstance && "game_release" in value;
isInstance = isInstance && "game_archive" in value;
isInstance = isInstance && "language" in value;
isInstance = isInstance && "eligibility_criteria" in value;
isInstance = isInstance && "frozen" in value;
Expand All @@ -135,6 +142,7 @@ export function EpisodeFromJSONTyped(json: any, ignoreDiscriminator: boolean): E
'name_long': json['name_long'],
'blurb': !exists(json, 'blurb') ? undefined : json['blurb'],
'game_release': (new Date(json['game_release'])),
'game_archive': (new Date(json['game_archive'])),
'language': LanguageEnumFromJSON(json['language']),
'scaffold': !exists(json, 'scaffold') ? undefined : json['scaffold'],
'artifact_name': !exists(json, 'artifact_name') ? undefined : json['artifact_name'],
Expand All @@ -159,6 +167,7 @@ export function EpisodeToJSON(value?: Episode | null): any {
'name_long': value.name_long,
'blurb': value.blurb,
'game_release': (value.game_release.toISOString()),
'game_archive': (value.game_archive.toISOString()),
'language': LanguageEnumToJSON(value.language),
'scaffold': value.scaffold,
'artifact_name': value.artifact_name,
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/compete/chart/ChartBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ChartBaseProps {
loadingMessage?: string;
plotLines?: PlotLine[];
crownTop?: boolean;
xAxisEndDate?: Date;
}

const ChartBase: React.FC<ChartBaseProps> = ({
Expand All @@ -27,6 +28,7 @@ const ChartBase: React.FC<ChartBaseProps> = ({
loadingMessage,
plotLines,
crownTop = false,
xAxisEndDate = new Date(),
}) => {
// Translate values into Highcharts compatible options
const [myChart, setChart] = useState<Highcharts.Chart>();
Expand Down Expand Up @@ -170,6 +172,7 @@ const ChartBase: React.FC<ChartBaseProps> = ({
},
},
})),
max: Math.min(xAxisEndDate.getTime(), Date.now()),
},
};

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/compete/chart/TeamChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQueryClient } from "@tanstack/react-query";
import { useTournamentList } from "api/episode/useEpisode";
import { useEpisodeInfo, useTournamentList } from "api/episode/useEpisode";
import { useEpisodeId } from "contexts/EpisodeContext";
import type React from "react";
import { useMemo } from "react";
Expand Down Expand Up @@ -38,6 +38,9 @@ const TeamChart: React.FC<TeamChartProps> = ({
return formatTournamentList(tournamentList.data.results ?? []);
}, [tournamentList]);

const episode = useEpisodeInfo({ id: episodeId });
const xAxisEndDate = episode.data?.game_archive;

return (
<ChartBase
yAxisLabel="Rating"
Expand All @@ -46,6 +49,7 @@ const TeamChart: React.FC<TeamChartProps> = ({
loadingMessage="Loading rating data..."
plotLines={tournamentData}
crownTop={crownTop}
xAxisEndDate={xAxisEndDate}
/>
);
};
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/compete/chart/UserChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type React from "react";
import { useMemo, useState } from "react";
import { useEpisodeList, useTournamentList } from "api/episode/useEpisode";
import {
useEpisodeInfo,
useEpisodeList,
useTournamentList,
} from "api/episode/useEpisode";
import SelectMenu from "../../elements/SelectMenu";
import ChartBase from "./ChartBase";
import { useTeamRatingHistory } from "api/compete/useCompete";
Expand Down Expand Up @@ -102,6 +106,9 @@ const ChartSection: React.FC<ChartSectionProps> = ({ episodeId, teamId }) => {
return formatTournamentList(tournamentList.data.results ?? []);
}, [tournamentList]);

const episode = useEpisodeInfo({ id: episodeId });
const xAxisEndDate = episode.data?.game_archive;

return (
<ChartBase
yAxisLabel="Rating"
Expand All @@ -110,6 +117,7 @@ const ChartSection: React.FC<ChartSectionProps> = ({ episodeId, teamId }) => {
loadingMessage="Loading rating data..."
plotLines={tournamentData}
crownTop={false}
xAxisEndDate={xAxisEndDate}
/>
);
};
Expand Down

0 comments on commit caf8eb9

Please sign in to comment.