From e26139276686d12063c6090e8e778b2ae331414a Mon Sep 17 00:00:00 2001 From: Patrick Dougherty Date: Wed, 5 Jul 2023 21:43:32 -0500 Subject: [PATCH] Improve sorting logic --- src/services/gql/types-and-hooks.tsx | 2 +- src/utils/startGG.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/services/gql/types-and-hooks.tsx b/src/services/gql/types-and-hooks.tsx index 64676a8..91ce848 100644 --- a/src/services/gql/types-and-hooks.tsx +++ b/src/services/gql/types-and-hooks.tsx @@ -2306,4 +2306,4 @@ export type GetSetsQueryVariables = Exact<{ }>; -export type GetSetsQuery = { __typename?: 'Query', event: { __typename?: 'Event', id: string | null, name: string | null, sets: { __typename?: 'SetConnection', pageInfo: { __typename?: 'PageInfo', total: number | null, totalPages: number | null, page: number | null, perPage: number | null, sortBy: string | null, filter: any | null } | null, nodes: Array<{ __typename?: 'Set', id: string | null, completedAt: any | null, fullRoundText: string | null, state: number | null, slots: Array<{ __typename?: 'SetSlot', entrant: { __typename?: 'Entrant', initialSeedNum: number | null, name: string | null } | null, standing: { __typename?: 'Standing', stats: { __typename?: 'StandingStats', score: { __typename?: 'Score', value: number | null } | null } | null } | null } | null> | null, phaseGroup: { __typename?: 'PhaseGroup', bracketUrl: string | null, phase: { __typename?: 'Phase', name: string | null, phaseOrder: number | null } | null } | null } | null> | null } | null } | null }; +export type GetSetsQuery = { __typename?: 'Query', event: { __typename?: 'Event', id: string | null, name: string | null, sets: { __typename?: 'SetConnection', pageInfo: { __typename?: 'PageInfo', total: number | null, totalPages: number | null, page: number | null, perPage: number | null, sortBy: string | null, filter: any | null } | null, nodes: Array<{ __typename?: 'Set', id: string | null, completedAt: any | null, fullRoundText: string | null, state: number | null, round: number | null, slots: Array<{ __typename?: 'SetSlot', entrant: { __typename?: 'Entrant', initialSeedNum: number | null, name: string | null } | null, standing: { __typename?: 'Standing', stats: { __typename?: 'StandingStats', score: { __typename?: 'Score', value: number | null } | null } | null } | null } | null> | null, phaseGroup: { __typename?: 'PhaseGroup', bracketUrl: string | null, phase: { __typename?: 'Phase', name: string | null, phaseOrder: number | null } | null } | null } | null> | null } | null } | null }; diff --git a/src/utils/startGG.ts b/src/utils/startGG.ts index 06deb95..2c695bc 100644 --- a/src/utils/startGG.ts +++ b/src/utils/startGG.ts @@ -143,6 +143,7 @@ export class Startgg { } } } + round phaseGroup { phase { name @@ -201,6 +202,15 @@ const convertSet = (set: SetType): SetData => { winner = 1; loser = 0; } + + // Build a number to sort sets + // (phase) + (3 digits round) + (12 digits seconds since epoch) + // ex. (4)(012)(001234567890) + // round logic follow below ordering pattern: + // 1/-3 < -4 < 2/-5 < -6 < 3/-7 < -8 < 4/-9 < -10 < 5... + const sortPhaseOrder = set.phaseGroup.phase.phaseOrder * 1e15; + const sortRound = (set.round > 0 ? set.round : ((set.round + 1) / -2)) * 1e12; + const sortOrder = sortPhaseOrder + sortRound + set.completedAt; return { id: set.id, @@ -213,8 +223,7 @@ const convertSet = (set: SetType): SetData => { roundName: set.fullRoundText, phaseName: set.phaseGroup.phase.name, url: set.phaseGroup.bracketUrl, - // Somewhat hacky but cheap ordering - order: set.phaseGroup.phase.phaseOrder * set.completedAt, + order: sortOrder, } } @@ -228,4 +237,4 @@ type DeepNonNullable = // Object case : T extends object ? { [K in keyof T]: DeepNonNullable; } // Primitive case - : NonNullable; \ No newline at end of file + : NonNullable;