Skip to content

Commit d001942

Browse files
authored
Merge pull request #41 from stormgateworld/tweak-activity-widget
Tweak Activity Widget
2 parents 0b71044 + 8f3ae5a commit d001942

10 files changed

+41
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"start": "astro dev",
88
"build": "astro build",
99
"astro": "astro",
10-
"build-api": "openapi --input https://api.stormgateworld.com/api-docs/openapi.json --output ./src/lib/api --postfixServices Api --useOptions --indent 2",
10+
"build-api": "openapi --input https://api.stormgateworld.com/api-docs/openapi.json --output ./src/lib/api --postfixServices Api --useOptions --indent 2 && pnpm format",
1111
"format": "prettier --write --plugin-search-dir=. .",
1212
"prepare": "husky"
1313
},

src/components/ui/Tooltip.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { children, createEffect, createMemo, type JSX, type ParentProps } from "
33

44
export function Tooltip(props: ParentProps<{ content: string; class?: string }>) {
55
return (
6-
<KTooltip.Root gutter={2}>
6+
<KTooltip.Root gutter={2} openDelay={0.1} closeDelay={0} ignoreSafeArea={true}>
77
<KTooltip.Trigger class={`outline-none ${props.class}`}>{props.children}</KTooltip.Trigger>
88
<KTooltip.Portal>
99
<KTooltip.Content class="rounded-sm border border-gray-700/50 bg-gray-800 px-1.5 py-1 text-gray-200 shadow-sm animate-in fade-in slide-in-from-bottom-1">

src/components/widgets/PlayerActivity.astro

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ function getWinrateClass(winrate: number) {
1818
return "bg-red-500"
1919
}
2020
21+
function getDaySize(dayMatches: number, medianMatches: number) {
22+
if (dayMatches === 0 || medianMatches == 0) return 0
23+
24+
const minSize = 50
25+
const maxSize = 100
26+
const size = (dayMatches / medianMatches) * 100
27+
28+
console.log(dayMatches, medianMatches)
29+
console.log(size)
30+
31+
return Math.max(minSize, Math.min(size, maxSize))
32+
}
33+
2134
const maxMatches = Math.max(...activity.history.map((d) => d.matches))
2235
type Day = { date: Date; win_rate: number; games_count: number; size: number; tooltip: string }
2336
type Week = Day[]
@@ -35,7 +48,7 @@ for (let i = 0; i < 12; i++) {
3548
date,
3649
win_rate: (day?.win_rate ?? 0) / 100,
3750
games_count: day?.matches ?? 0,
38-
size: day?.matches ? Math.max(50, Math.min((day.matches / maxMatches) * 150, 100)) : 0,
51+
size: getDaySize(day?.matches ?? 0, activity.aggregated?.matches_per_day?.median ?? 0),
3952
tooltip: day?.matches
4053
? `${date.toLocaleDateString("en", { dateStyle: "long" })}\n${day.matches} Games\n${Math.round(
4154
day.win_rate

src/lib/api/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export type { PlayerMatchesResponse } from "./models/PlayerMatchesResponse"
2525
export type { PlayerPreferences } from "./models/PlayerPreferences"
2626
export type { PlayerResponse } from "./models/PlayerResponse"
2727
export type { PlayerStatsEntry } from "./models/PlayerStatsEntry"
28+
export type { PlayerStatsEntryAggregated } from "./models/PlayerStatsEntryAggregated"
2829
export type { PlayerStatsEntryNumBreakdown } from "./models/PlayerStatsEntryNumBreakdown"
2930
export { ProfilePrivacy } from "./models/ProfilePrivacy"
3031
export { Race } from "./models/Race"

src/lib/api/models/MatchParticipantPlayerResponse.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
/* eslint-disable */
55
export type MatchParticipantPlayerResponse = {
66
player_id: string
7-
nickname: string
8-
nickname_discriminator: string
7+
nickname?: string | null
8+
nickname_discriminator?: string | null
99
}

src/lib/api/models/PlayerActivityStats.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
/* eslint-disable */
55
import type { PlayerActivityStatsRace } from "./PlayerActivityStatsRace"
66
import type { PlayerStatsEntry } from "./PlayerStatsEntry"
7+
import type { PlayerStatsEntryAggregated } from "./PlayerStatsEntryAggregated"
78
export type PlayerActivityStats = {
89
updated_at: string
9-
aggregated?: PlayerStatsEntry | null
10+
aggregated?: PlayerStatsEntryAggregated | null
1011
history: Array<PlayerStatsEntry>
1112
races: Array<PlayerActivityStatsRace>
1213
}

src/lib/api/models/PlayerResponse.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type PlayerResponse = {
99
nickname?: string | null
1010
nickname_discriminator?: string | null
1111
leaderboard_entries: Array<LeaderboardEntryResponse>
12+
last_match_ended_at?: string | null
1213
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* generated using openapi-typescript-codegen -- do no edit */
2+
/* istanbul ignore file */
3+
/* tslint:disable */
4+
/* eslint-disable */
5+
import type { PlayerStatsEntryNumBreakdown } from "./PlayerStatsEntryNumBreakdown"
6+
export type PlayerStatsEntryAggregated = {
7+
matches: number
8+
matches_per_day: PlayerStatsEntryNumBreakdown
9+
wins: number
10+
losses: number
11+
win_rate: number
12+
mmr: PlayerStatsEntryNumBreakdown
13+
points: PlayerStatsEntryNumBreakdown
14+
match_length: PlayerStatsEntryNumBreakdown
15+
}

src/lib/api/models/PlayerStatsEntryNumBreakdown.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
export type PlayerStatsEntryNumBreakdown = {
66
max?: number | null
77
min?: number | null
8+
median?: number | null
89
average?: number | null
910
}

src/lib/api/services/PlayersApi.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* tslint:disable */
44
/* eslint-disable */
55
import type { MatchResponse } from "../models/MatchResponse"
6+
import type { PlayerActivityStats } from "../models/PlayerActivityStats"
67
import type { PlayerMatchesResponse } from "../models/PlayerMatchesResponse"
78
import type { PlayerPreferences } from "../models/PlayerPreferences"
89
import type { PlayerResponse } from "../models/PlayerResponse"
@@ -130,7 +131,7 @@ export class PlayersApi {
130131
})
131132
}
132133
/**
133-
* @returns MatchResponse Player found successfully
134+
* @returns PlayerActivityStats Player found successfully
134135
* @throws ApiError
135136
*/
136137
public static getPlayerStatisticsActivity({
@@ -140,7 +141,7 @@ export class PlayersApi {
140141
* Player ID
141142
*/
142143
playerId: string
143-
}): CancelablePromise<MatchResponse> {
144+
}): CancelablePromise<PlayerActivityStats> {
144145
return __request(OpenAPI, {
145146
method: "GET",
146147
url: "/v0/players/{player_id}/statistics/activity",

0 commit comments

Comments
 (0)