Fix: Allow progressive results
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1e7c8ad504
commit
4074e268b2
2 changed files with 57 additions and 47 deletions
|
@ -14,8 +14,8 @@ interface CompetitionList {
|
||||||
* A class for dealing with the digitalrock api
|
* A class for dealing with the digitalrock api
|
||||||
*/
|
*/
|
||||||
export class DigitalrockAPi {
|
export class DigitalrockAPi {
|
||||||
private BASE_URL = 'https://www.digitalrock.de/egroupware/ranking/json.php?';
|
// private BASE_URL = 'https://www.digitalrock.de/egroupware/ranking/json.php?';
|
||||||
// private BASE_URL = '/test.json?';
|
private BASE_URL = '/test.json?';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to get competitions
|
* function to get competitions
|
||||||
|
|
|
@ -57,7 +57,6 @@ function getRoundName(
|
||||||
*/
|
*/
|
||||||
function getRoundRank(name: string): number {
|
function getRoundRank(name: string): number {
|
||||||
const match = name.match(/1\/([842])/);
|
const match = name.match(/1\/([842])/);
|
||||||
console.log(match);
|
|
||||||
if (match === undefined || match === null || match.length !== 2) {
|
if (match === undefined || match === null || match.length !== 2) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -76,6 +75,8 @@ function computeWinnerOfPair(pair: SpeedRoundPair, roundIndex: number) {
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
console.log('Conputing winner of round ', roundIndex);
|
||||||
|
|
||||||
pair.laneA.result = pair.laneA.participant.results[roundIndex];
|
pair.laneA.result = pair.laneA.participant.results[roundIndex];
|
||||||
pair.laneB.result = pair.laneB.participant.results[roundIndex];
|
pair.laneB.result = pair.laneB.participant.results[roundIndex];
|
||||||
|
|
||||||
|
@ -99,9 +100,11 @@ function getWinnerOfPair(
|
||||||
roundNumber: number,
|
roundNumber: number,
|
||||||
): Participant | undefined {
|
): Participant | undefined {
|
||||||
computeWinnerOfPair(pair, roundNumber);
|
computeWinnerOfPair(pair, roundNumber);
|
||||||
return pair.winner === 'A'
|
return {
|
||||||
? pair.laneA?.participant
|
['A']: pair.laneA?.participant,
|
||||||
: pair.laneB?.participant;
|
['B']: pair.laneB?.participant,
|
||||||
|
['']: undefined,
|
||||||
|
}[pair.winner ?? ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,9 +118,11 @@ function getLooserOfPair(
|
||||||
roundNumber: number,
|
roundNumber: number,
|
||||||
): Participant | undefined {
|
): Participant | undefined {
|
||||||
computeWinnerOfPair(pair, roundNumber);
|
computeWinnerOfPair(pair, roundNumber);
|
||||||
return pair.winner === 'A'
|
return {
|
||||||
? pair.laneB?.participant
|
['A']: pair.laneB?.participant,
|
||||||
: pair.laneA?.participant;
|
['B']: pair.laneA?.participant,
|
||||||
|
['']: undefined,
|
||||||
|
}[pair.winner ?? ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,6 +130,7 @@ function getLooserOfPair(
|
||||||
* @param {number} roundIndex index of the new round
|
* @param {number} roundIndex index of the new round
|
||||||
* @param {string} roundName name of the new round
|
* @param {string} roundName name of the new round
|
||||||
* @param {SpeedRound} previousRound
|
* @param {SpeedRound} previousRound
|
||||||
|
* @param {number} roundRank
|
||||||
* @param {boolean} takeLooser
|
* @param {boolean} takeLooser
|
||||||
* @return {SpeedRound}
|
* @return {SpeedRound}
|
||||||
*/
|
*/
|
||||||
|
@ -132,38 +138,37 @@ function computeRoundFromPreviousRound(
|
||||||
roundIndex: number,
|
roundIndex: number,
|
||||||
roundName: string,
|
roundName: string,
|
||||||
previousRound: SpeedRound,
|
previousRound: SpeedRound,
|
||||||
|
roundRank: number,
|
||||||
takeLooser = false,
|
takeLooser = false,
|
||||||
): SpeedRound {
|
): SpeedRound {
|
||||||
const getAdvancingParticipant = takeLooser
|
const getAdvancingParticipant = takeLooser
|
||||||
? getLooserOfPair
|
? getLooserOfPair
|
||||||
: getWinnerOfPair;
|
: getWinnerOfPair;
|
||||||
const nextRoundPairs = new Array(previousRound.pairs.length / 2)
|
const nextRoundPairs = new Array(roundRank / 2).fill(0).map((_, i) => {
|
||||||
.fill(0)
|
const laneAParticipant = getAdvancingParticipant(
|
||||||
.map((_, i) => {
|
previousRound.pairs[i * 2],
|
||||||
const laneAParticipant = getAdvancingParticipant(
|
previousRound.roundIndex,
|
||||||
previousRound.pairs[i * 2],
|
);
|
||||||
previousRound.roundIndex,
|
const laneBParticipant = getAdvancingParticipant(
|
||||||
);
|
previousRound.pairs[i * 2 + 1],
|
||||||
const laneBParticipant = getAdvancingParticipant(
|
previousRound.roundIndex,
|
||||||
previousRound.pairs[i * 2 + 1],
|
);
|
||||||
previousRound.roundIndex,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
laneA:
|
laneA:
|
||||||
laneAParticipant === undefined
|
laneAParticipant === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
participant: laneAParticipant,
|
participant: laneAParticipant,
|
||||||
},
|
},
|
||||||
laneB:
|
laneB:
|
||||||
laneBParticipant === undefined
|
laneBParticipant === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
participant: laneBParticipant,
|
participant: laneBParticipant,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pairs: nextRoundPairs,
|
pairs: nextRoundPairs,
|
||||||
|
@ -190,16 +195,14 @@ export function convertResultsToSpeedFlowchartResult(
|
||||||
.map(number => parseInt(number))
|
.map(number => parseInt(number))
|
||||||
.filter(number => number > 0);
|
.filter(number => number > 0);
|
||||||
|
|
||||||
console.log(`Have final rounds:`, roundIndices);
|
|
||||||
|
|
||||||
// process first round
|
// process first round
|
||||||
const firstRoundName = getRoundName(roundIndices[0], result.route_names);
|
const firstRoundName = getRoundName(roundIndices[0], result.route_names);
|
||||||
const firstRoundNumber = getRoundRank(
|
const firstRoundRank = getRoundRank(
|
||||||
getRoundName(roundIndices[0], result.route_names) ?? '',
|
getRoundName(roundIndices[0], result.route_names) ?? '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const getOpponent = (ofRank: number): Participant => {
|
const getOpponent = (ofRank: number): Participant => {
|
||||||
return convertedParticipants[firstRoundNumber * 2 - 1 - ofRank];
|
return convertedParticipants[firstRoundRank * 2 - 1 - ofRank];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Should be:
|
// Should be:
|
||||||
|
@ -213,8 +216,7 @@ export function convertResultsToSpeedFlowchartResult(
|
||||||
[1, 2],
|
[1, 2],
|
||||||
[1, 4, 2, 3],
|
[1, 4, 2, 3],
|
||||||
[1, 8, 4, 5, 2, 7, 3, 6],
|
[1, 8, 4, 5, 2, 7, 3, 6],
|
||||||
][firstRoundNumber / 4];
|
][firstRoundRank / 4];
|
||||||
console.log(ranksOfLaneAInOrder);
|
|
||||||
|
|
||||||
const firstRoundPairs = ranksOfLaneAInOrder.map(rank => {
|
const firstRoundPairs = ranksOfLaneAInOrder.map(rank => {
|
||||||
return {
|
return {
|
||||||
|
@ -231,33 +233,41 @@ export function convertResultsToSpeedFlowchartResult(
|
||||||
|
|
||||||
rounds.push(firstRound);
|
rounds.push(firstRound);
|
||||||
|
|
||||||
|
console.log(firstRound);
|
||||||
|
|
||||||
// compute following rounds
|
// compute following rounds
|
||||||
for (let i = 1; i < roundIndices.length - 2; i++) {
|
let roundIndex = roundIndices[1];
|
||||||
|
for (let roundRank = firstRoundRank; roundRank > 2; roundRank /= 2) {
|
||||||
|
console.log('Processing rank', roundRank);
|
||||||
rounds.push(
|
rounds.push(
|
||||||
computeRoundFromPreviousRound(
|
computeRoundFromPreviousRound(
|
||||||
roundIndices[i],
|
roundIndex,
|
||||||
result.route_names[roundIndices[i]] ?? '',
|
result.route_names[roundIndex] ?? '',
|
||||||
rounds[i - 1],
|
rounds[rounds.length - 1],
|
||||||
|
roundRank,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
roundIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute final and semi final
|
// compute final and semi final
|
||||||
const semifinalRoundIndex = roundIndices[roundIndices.length - 2];
|
const semifinalRoundIndex = roundIndex++;
|
||||||
const semifinal = computeRoundFromPreviousRound(
|
const semifinal = computeRoundFromPreviousRound(
|
||||||
semifinalRoundIndex,
|
semifinalRoundIndex,
|
||||||
result.route_names[semifinalRoundIndex] ?? '',
|
result.route_names[semifinalRoundIndex] ?? '',
|
||||||
rounds[rounds.length - 1],
|
rounds[rounds.length - 1],
|
||||||
|
2,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
computeWinnerOfPair(semifinal.pairs[0], semifinalRoundIndex);
|
computeWinnerOfPair(semifinal.pairs[0], semifinalRoundIndex);
|
||||||
rounds.push(semifinal);
|
rounds.push(semifinal);
|
||||||
|
|
||||||
const finalRoundIndex = roundIndices[roundIndices.length - 1];
|
const finalRoundIndex = roundIndex;
|
||||||
const final = computeRoundFromPreviousRound(
|
const final = computeRoundFromPreviousRound(
|
||||||
finalRoundIndex,
|
finalRoundIndex,
|
||||||
result.route_names[finalRoundIndex] ?? '',
|
result.route_names[finalRoundIndex] ?? '',
|
||||||
rounds[rounds.length - 2],
|
rounds[rounds.length - 2],
|
||||||
|
2,
|
||||||
);
|
);
|
||||||
computeWinnerOfPair(final.pairs[0], finalRoundIndex);
|
computeWinnerOfPair(final.pairs[0], finalRoundIndex);
|
||||||
rounds.push(final);
|
rounds.push(final);
|
||||||
|
|
Loading…
Reference in a new issue