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

Tweak Activity Widget #41

Merged
merged 1 commit into from
Feb 7, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { children, createEffect, createMemo, type JSX, type ParentProps } from "

export function Tooltip(props: ParentProps<{ content: string; class?: string }>) {
return (
<KTooltip.Root gutter={2}>
<KTooltip.Root gutter={2} openDelay={0.1} closeDelay={0} ignoreSafeArea={true}>
<KTooltip.Trigger class={`outline-none ${props.class}`}>{props.children}</KTooltip.Trigger>
<KTooltip.Portal>
<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">
Expand Down
15 changes: 14 additions & 1 deletion src/components/widgets/PlayerActivity.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/models/MatchParticipantPlayerResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
/* eslint-disable */
export type MatchParticipantPlayerResponse = {
player_id: string
nickname: string
nickname_discriminator: string
nickname?: string | null
nickname_discriminator?: string | null
}
3 changes: 2 additions & 1 deletion src/lib/api/models/PlayerActivityStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerStatsEntry>
races: Array<PlayerActivityStatsRace>
}
1 change: 1 addition & 0 deletions src/lib/api/models/PlayerResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type PlayerResponse = {
nickname?: string | null
nickname_discriminator?: string | null
leaderboard_entries: Array<LeaderboardEntryResponse>
last_match_ended_at?: string | null
}
15 changes: 15 additions & 0 deletions src/lib/api/models/PlayerStatsEntryAggregated.ts
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions src/lib/api/models/PlayerStatsEntryNumBreakdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
export type PlayerStatsEntryNumBreakdown = {
max?: number | null
min?: number | null
median?: number | null
average?: number | null
}
5 changes: 3 additions & 2 deletions src/lib/api/services/PlayersApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -130,7 +131,7 @@ export class PlayersApi {
})
}
/**
* @returns MatchResponse Player found successfully
* @returns PlayerActivityStats Player found successfully
* @throws ApiError
*/
public static getPlayerStatisticsActivity({
Expand All @@ -140,7 +141,7 @@ export class PlayersApi {
* Player ID
*/
playerId: string
}): CancelablePromise<MatchResponse> {
}): CancelablePromise<PlayerActivityStats> {
return __request(OpenAPI, {
method: "GET",
url: "/v0/players/{player_id}/statistics/activity",
Expand Down
Loading