Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve sorting logic #31

Merged
merged 1 commit into from
Jul 6, 2023
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 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>;