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