Skip to content

Commit

Permalink
Merge pull request #31 from simkinsw/sorting
Browse files Browse the repository at this point in the history
Improve sorting logic
  • Loading branch information
patrickdoc authored Jul 6, 2023
2 parents b9eff1f + e261392 commit 44545ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/services/gql/types-and-hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
15 changes: 12 additions & 3 deletions src/utils/startGG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Startgg {
}
}
}
round
phaseGroup {
phase {
name
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}

Expand All @@ -228,4 +237,4 @@ type DeepNonNullable<T> =
// Object case
: T extends object ? { [K in keyof T]: DeepNonNullable<T[K]>; }
// Primitive case
: NonNullable<T>;
: NonNullable<T>;

0 comments on commit 44545ac

Please # to comment.