Skip to content

Commit 0daeb0c

Browse files
committed
small fix to ordering of HJ results when athlete has no jumps
1 parent 892fb9a commit 0daeb0c

2 files changed

Lines changed: 71 additions & 14 deletions

File tree

js/src/highjump.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ function Jumper(kwds) {
102102
failuresAtHeight = failuresBeforeAndAtHeight = this.attemptsByHeight[x].split('x').length - 1;
103103
for (i = 0; i < x; i++) failuresBeforeAndAtHeight += this.attemptsByHeight[i].split('x').length - 1;
104104
}
105+
if (this.highestCleared === 0 && this.attemptsByHeight.length === 0) {
106+
return [3, -0, 0, 0];
107+
}
105108

106109
return [
107110
this.eliminated ? (x < 0 ? 3 : 2) : (x < 0 ? 1 : 0),
@@ -175,6 +178,7 @@ function cmpKeys(a, b) {
175178
let ai;
176179
let bi;
177180

181+
// console.log('a, b', a, b);
178182
for (let i = 0; i < a.length; i++) {
179183
ai = a[i];
180184
bi = b[i];
@@ -222,7 +226,7 @@ function HighJumpCompetition() {
222226
);
223227
}
224228

225-
j._place = this.jumpers.length + 1;
229+
// j._place = this.jumpers.length + 1;
226230

227231
this.jumpersByBib[j.bib] = j;
228232
this.jumpers[this.jumpers.length] = j;
@@ -353,10 +357,18 @@ function HighJumpCompetition() {
353357
const rankjlen = rankj.length;
354358
let i;
355359

360+
// console.log('rankj before', rankj);
361+
356362
for (i = 0; i < rankjlen; i++) rankj[i]._oldPos = i;
357-
rankj.sort((a, b) =>
358-
cmpKeys([a.rankingKey, a._oldPos], [b.rankingKey, b._oldPos])
359-
);
363+
rankj.sort(function (a, b) {
364+
var r;
365+
366+
// console.log(a.first_name, b.first_name);
367+
r = cmpKeys([a.rankingKey, a._oldPos], [b.rankingKey, b._oldPos]);
368+
369+
// console.log('result', r);
370+
return r;
371+
});
360372

361373
let pk = null;
362374
let pj = null;
@@ -365,6 +377,8 @@ function HighJumpCompetition() {
365377
const j = rankj[i];
366378
const k = j.rankingKey;
367379

380+
// console.log(j);
381+
368382
delete j._oldPos;
369383
if (i === 0) {
370384
j._place = 1;
@@ -374,6 +388,7 @@ function HighJumpCompetition() {
374388
pk = k;
375389
pj = j;
376390
}
391+
// console.log('rankj after', rankj);
377392
return rankj;
378393
},
379394

@@ -424,7 +439,16 @@ function HighJumpCompetition() {
424439
'won' :
425440
'finished';
426441
}
442+
} else {
443+
// Check for any athletes without jumps (should be eliminated)
444+
rankj.forEach(j => {
445+
// console.log(j.first_name + j.last_name, j.highestCleared === 0, j.attemptsByHeight.length === 0);
446+
if (this.state === 'finished' && j.highestCleared === 0 && j.attemptsByHeight.length === 0) {
447+
j.eliminated = true;
448+
}
449+
});
427450
}
451+
// console.log('this.rankedJumpers', this.rankedJumpers);
428452
},
429453

430454
displayBarHeight() {

js/test/highjump.spec.js

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ const matrix_a = [
5858
["A", "o", "xxx", "o", "x", "r"],
5959
["B", "o", "xxx", "o", "x", "r"],
6060
]
61+
62+
const BELGRADE_INDOOR_HJ = [ // from here /en-gb/x/2022/SRB/belgradeindoor/event/F3/1/1/
63+
["place", "order", "bib", "first_name", "last_name", "team", "category", "5.01", "5.16", "5.31", "5.46", "5.61", "5.71", "5.81", "5.85", "6", "6.19", "best", "note"],
64+
["1", 1, 148, "Armand", "DUPLANTIS", "SWE", "M", "", "", "", "", "o", "", "", "o", "o", "xxo", 6.19, ""],
65+
["1", 1, 149, "Emanuoil", "KARALIS", "GRE", "M", "", "", "", "", "", "", "", "", "", "", 0, ""],
66+
["1", 1, 152, "Robert", "RENNER", "SLO", "M", "", "xo", "xxo", "xxx", "", "", "", "", "", "", 5.31, ""],
67+
["1", 1, 153, "Ivan", "PARAVAC", "CRO", "M", "o", "o", "xxx", "", "", "", "", "", "", "", 5.16, ""],
68+
["1", 1, 150, "Bokai", "HUANG", "CHN", "M", "", "", "", "xxx", "", "", "", "", "", "", 0, ""],
69+
["1", 1, 151, "Wenwen", "CHEN", "CHN", "M", "", "", "xxx", "", "", "", "", "", "", "", 0, ""],
70+
];
6171

6272
function createEmptyCompetition(matrix){
6373
//Creates from an array similar to above; named athletes with bibs
@@ -73,18 +83,18 @@ function createEmptyCompetition(matrix){
7383

7484
describe('Given an instance of Athlib.HighJumpCompetition', function(){
7585
describe('Tests basic creation of athletes with names and bibs', function(){
76-
var c=createEmptyCompetition(ESAA_2015_HJ);
77-
it('last of jumpers should be named Dwyer',()=>{
78-
expect(c.jumpers[c.jumpers.length-1].last_name).to.be.equal('Dwyer');
79-
});
80-
it('jumpersByBib[85] should be named Maslen',()=>{
81-
expect(c.jumpersByBib[85].last_name).to.be.equal('Maslen');
82-
});
86+
var c=createEmptyCompetition(ESAA_2015_HJ);
87+
it('last of jumpers should be named Dwyer',()=>{
88+
expect(c.jumpers[c.jumpers.length-1].last_name).to.be.equal('Dwyer');
89+
});
90+
it('jumpersByBib[85] should be named Maslen',()=>{
91+
expect(c.jumpersByBib[85].last_name).to.be.equal('Maslen');
92+
});
8393
});
8494
describe('Tests progression',function(){
85-
var c = createEmptyCompetition(ESAA_2015_HJ);
86-
var h1 = 1.81;
87-
c.setBarHeight(h1);
95+
var c = createEmptyCompetition(ESAA_2015_HJ);
96+
var h1 = 1.81;
97+
c.setBarHeight(h1);
8898

8999
// round 1
90100
c.cleared(85);
@@ -526,4 +536,27 @@ describe('Given an instance of Athlib.HighJumpCompetition', function(){
526536
check("175 place 1, 193 place 1", 'r', 'r', 1, 1);
527537
check("175 place 1, 193 place 1", 'x', 'x', 1, 1);
528538
});
539+
540+
describe('test result for BELGRADE INDOOR MEETING 2022',function(){
541+
const c = Athlib.HighJumpCompetition.fromMatrix(BELGRADE_INDOOR_HJ);
542+
c.state = 'finished' // pretend we simulated a HJ competition
543+
// console.log(c)
544+
c._rank()
545+
var rank_aths = c.rankedJumpers
546+
547+
var emanuoil_karalis = rank_aths.find(ath => ath.bib === "149")
548+
var wenwen_chen = rank_aths.find(ath => ath.bib === "151")
549+
550+
551+
it("test ordering correct",()=>{ expect(rank_aths.map(r => r.bib)).deep.to.be.equal(["148", "152", "153", "150", "151", "149"]) });
552+
553+
it("test correct calc rankingKey", ()=>{ expect(emanuoil_karalis.rankingKey).deep.to.be.equal([ 3, -0, 0, 0 ]) })
554+
555+
it("test athlete is eliminated", ()=>{ expect(wenwen_chen.eliminated).to.be.equal(true) })
556+
557+
// athletes with no jump will be set as eliminted once the state is set to 'finished'
558+
it("test athlete with no jumps is eliminated", ()=>{ expect(emanuoil_karalis.eliminated).to.be.equal(true) })
559+
560+
561+
});
529562
});

0 commit comments

Comments
 (0)