Skip to content

Commit 93048a3

Browse files
committed
fix weird issues with inconsistent section info
1 parent b37f35a commit 93048a3

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

pages/uscf/tournament/[id].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div v-for="section in gameData.sections" :key="section.id" class="col-md-12 mb-3">
1616
<h3>{{ titleize(section.name) }}</h3>
1717

18-
<div class="row">
18+
<div v-if="section.stats" class="row">
1919
<div class="col-md-6">
2020
<h4>Stats</h4>
2121
<p>
@@ -25,7 +25,7 @@
2525
</div>
2626
</div>
2727

28-
<v-data-table v-model:expanded="expanded[section.id - 1]" show-expand
28+
<v-data-table v-if="section.stats && section.players.length > 0" v-model:expanded="expanded[section.id - 1]" show-expand
2929
:items-per-page="section.players.length > 10 ? 10 : -1"
3030
:headers="buildHeaders(section.stats.rounds)" :items="section.players"
3131
theme="dark" item-value="pairNumber" :search="search">

server/api/uscf/tournament/[id].ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,31 @@ export default defineEventHandler(async (event) => {
5252

5353
const sectionID = sectionInfo[0][0]
5454

55-
const processedData = sectionInfo[2][1]
55+
const processedData = findElement(sectionInfo, 'Processed')
5656

57-
const processedInfo = {
57+
const processedInfo = processedData ? {
5858
received: processedData.split('Received: ')[1].split(' ')[0],
5959
entered: processedData.split('Entered: ')[1].split(' ')[0],
6060
rated: processedData.split('Rated: ')[1].split(' ')[0],
6161
reRated: undefined as string | undefined
62-
}
62+
} : undefined
6363

64-
if (processedData.includes('Re-Rated')) {
64+
if (processedData?.includes('Re-Rated') && processedInfo) {
6565
processedInfo.reRated = processedData.split('Re-Rated: ')[1].split(' ')[0]
6666
}
6767

68-
const statsData = sectionInfo[3][1]
68+
const statsData = findElement(sectionInfo, 'Stats')
69+
if (statsData == null) {
70+
sections.push({
71+
id: parseInt(sectionID.split(' - ')[0].split('Section ')[1]),
72+
name: sectionID.split(' - ')[1],
73+
processed: processedInfo,
74+
stats: undefined,
75+
players: []
76+
})
77+
continue
78+
}
79+
6980
const statsInfo = {
7081
rounds: parseInt(statsData.split(' ')[0]),
7182
players: parseInt(statsData.split(' Rounds, ')[1].split(' Players')[0]),
@@ -76,7 +87,17 @@ export default defineEventHandler(async (event) => {
7687
}
7788

7889
const players: USCFTournamentSectionPlayer[] = []
79-
const playerInfo = section[5][0].split('\n')
90+
const playerInfo = findElement(section, '---------------', false, 0)?.split('\n')
91+
if (!playerInfo) {
92+
sections.push({
93+
id: parseInt(sectionID.split(' - ')[0].split('Section ')[1]),
94+
name: sectionID.split(' - ')[1],
95+
processed: processedInfo,
96+
stats: statsInfo,
97+
players: []
98+
})
99+
continue
100+
}
80101
const base = 13
81102
let rowsOfData = 0
82103
while (!playerInfo[base + (rowsOfData)].includes('---------')) {

types/uscf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ export interface USCFTournamentSectionPlayer {
125125
export interface USCFTournamentSection {
126126
id: number;
127127
name: string;
128-
processed: {
128+
processed?: {
129129
received: string;
130130
entered: string;
131131
rated: string;
132132
reRated?: string
133133
};
134-
stats: {
134+
stats?: {
135135
rounds: number;
136136
players: number;
137137
kFactor: string;

utils/elements.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ export function gatherElements(data: HTMLElement) {
4141
* @param elements The elements
4242
* @param text The string to find in the first box
4343
* @param exact Whether or not to match the text exactly
44+
* @param key The key to return
4445
*/
45-
export function findElement(elements: string[][], text: string, exact: boolean = true) {
46+
export function findElement(elements: string[][], text: string, exact: boolean = true, key: number = 1) {
4647
const element = elements.find(element => exact ? element[0] === text : element[0].includes(text))
4748

4849
if (!element) {
4950
return null
5051
}
5152

52-
return element[1]
53+
return element[key]
5354
}
5455

5556
/**

0 commit comments

Comments
 (0)