diff --git a/package.json b/package.json index 9e25a08..b3b94ea 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "astro dev", "build": "astro build", "astro": "astro", - "build-api": "openapi --input https://api.stormgateworld.com/api-docs/openapi.json --output ./src/lib/api --postfixServices Api --useOptions --indent 2", + "build-api": "openapi --input https://api.stormgateworld.com/api-docs/openapi.json --output ./src/lib/api --postfixServices Api --useOptions --indent 2 && pnpm format", "format": "prettier --write --plugin-search-dir=. .", "prepare": "husky" }, diff --git a/src/components/ui/Tooltip.tsx b/src/components/ui/Tooltip.tsx index 7ca65cc..7963f23 100644 --- a/src/components/ui/Tooltip.tsx +++ b/src/components/ui/Tooltip.tsx @@ -3,7 +3,7 @@ import { children, createEffect, createMemo, type JSX, type ParentProps } from " export function Tooltip(props: ParentProps<{ content: string; class?: string }>) { return ( - + {props.children} diff --git a/src/components/widgets/PlayerActivity.astro b/src/components/widgets/PlayerActivity.astro index 0ba4b20..de14ae8 100644 --- a/src/components/widgets/PlayerActivity.astro +++ b/src/components/widgets/PlayerActivity.astro @@ -18,6 +18,19 @@ function getWinrateClass(winrate: number) { return "bg-red-500" } +function getDaySize(dayMatches: number, medianMatches: number) { + if (dayMatches === 0 || medianMatches == 0) return 0 + + const minSize = 50 + const maxSize = 100 + const size = (dayMatches / medianMatches) * 100 + + console.log(dayMatches, medianMatches) + console.log(size) + + return Math.max(minSize, Math.min(size, maxSize)) +} + const maxMatches = Math.max(...activity.history.map((d) => d.matches)) type Day = { date: Date; win_rate: number; games_count: number; size: number; tooltip: string } type Week = Day[] @@ -35,7 +48,7 @@ for (let i = 0; i < 12; i++) { date, win_rate: (day?.win_rate ?? 0) / 100, games_count: day?.matches ?? 0, - size: day?.matches ? Math.max(50, Math.min((day.matches / maxMatches) * 150, 100)) : 0, + size: getDaySize(day?.matches ?? 0, activity.aggregated?.matches_per_day?.median ?? 0), tooltip: day?.matches ? `${date.toLocaleDateString("en", { dateStyle: "long" })}\n${day.matches} Games\n${Math.round( day.win_rate diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 3556c42..f9be721 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -25,6 +25,7 @@ export type { PlayerMatchesResponse } from "./models/PlayerMatchesResponse" export type { PlayerPreferences } from "./models/PlayerPreferences" export type { PlayerResponse } from "./models/PlayerResponse" export type { PlayerStatsEntry } from "./models/PlayerStatsEntry" +export type { PlayerStatsEntryAggregated } from "./models/PlayerStatsEntryAggregated" export type { PlayerStatsEntryNumBreakdown } from "./models/PlayerStatsEntryNumBreakdown" export { ProfilePrivacy } from "./models/ProfilePrivacy" export { Race } from "./models/Race" diff --git a/src/lib/api/models/MatchParticipantPlayerResponse.ts b/src/lib/api/models/MatchParticipantPlayerResponse.ts index 1b4558d..f9ddebd 100644 --- a/src/lib/api/models/MatchParticipantPlayerResponse.ts +++ b/src/lib/api/models/MatchParticipantPlayerResponse.ts @@ -4,6 +4,6 @@ /* eslint-disable */ export type MatchParticipantPlayerResponse = { player_id: string - nickname: string - nickname_discriminator: string + nickname?: string | null + nickname_discriminator?: string | null } diff --git a/src/lib/api/models/PlayerActivityStats.ts b/src/lib/api/models/PlayerActivityStats.ts index ae8ef14..10e9953 100644 --- a/src/lib/api/models/PlayerActivityStats.ts +++ b/src/lib/api/models/PlayerActivityStats.ts @@ -4,9 +4,10 @@ /* eslint-disable */ import type { PlayerActivityStatsRace } from "./PlayerActivityStatsRace" import type { PlayerStatsEntry } from "./PlayerStatsEntry" +import type { PlayerStatsEntryAggregated } from "./PlayerStatsEntryAggregated" export type PlayerActivityStats = { updated_at: string - aggregated?: PlayerStatsEntry | null + aggregated?: PlayerStatsEntryAggregated | null history: Array races: Array } diff --git a/src/lib/api/models/PlayerResponse.ts b/src/lib/api/models/PlayerResponse.ts index 09757d2..11daed6 100644 --- a/src/lib/api/models/PlayerResponse.ts +++ b/src/lib/api/models/PlayerResponse.ts @@ -9,4 +9,5 @@ export type PlayerResponse = { nickname?: string | null nickname_discriminator?: string | null leaderboard_entries: Array + last_match_ended_at?: string | null } diff --git a/src/lib/api/models/PlayerStatsEntryAggregated.ts b/src/lib/api/models/PlayerStatsEntryAggregated.ts new file mode 100644 index 0000000..146cfda --- /dev/null +++ b/src/lib/api/models/PlayerStatsEntryAggregated.ts @@ -0,0 +1,15 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { PlayerStatsEntryNumBreakdown } from "./PlayerStatsEntryNumBreakdown" +export type PlayerStatsEntryAggregated = { + matches: number + matches_per_day: PlayerStatsEntryNumBreakdown + wins: number + losses: number + win_rate: number + mmr: PlayerStatsEntryNumBreakdown + points: PlayerStatsEntryNumBreakdown + match_length: PlayerStatsEntryNumBreakdown +} diff --git a/src/lib/api/models/PlayerStatsEntryNumBreakdown.ts b/src/lib/api/models/PlayerStatsEntryNumBreakdown.ts index 151495d..ab2824f 100644 --- a/src/lib/api/models/PlayerStatsEntryNumBreakdown.ts +++ b/src/lib/api/models/PlayerStatsEntryNumBreakdown.ts @@ -5,5 +5,6 @@ export type PlayerStatsEntryNumBreakdown = { max?: number | null min?: number | null + median?: number | null average?: number | null } diff --git a/src/lib/api/services/PlayersApi.ts b/src/lib/api/services/PlayersApi.ts index c8492b4..4dffb9b 100644 --- a/src/lib/api/services/PlayersApi.ts +++ b/src/lib/api/services/PlayersApi.ts @@ -3,6 +3,7 @@ /* tslint:disable */ /* eslint-disable */ import type { MatchResponse } from "../models/MatchResponse" +import type { PlayerActivityStats } from "../models/PlayerActivityStats" import type { PlayerMatchesResponse } from "../models/PlayerMatchesResponse" import type { PlayerPreferences } from "../models/PlayerPreferences" import type { PlayerResponse } from "../models/PlayerResponse" @@ -130,7 +131,7 @@ export class PlayersApi { }) } /** - * @returns MatchResponse Player found successfully + * @returns PlayerActivityStats Player found successfully * @throws ApiError */ public static getPlayerStatisticsActivity({ @@ -140,7 +141,7 @@ export class PlayersApi { * Player ID */ playerId: string - }): CancelablePromise { + }): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/v0/players/{player_id}/statistics/activity",