Skip to content
Open
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
40 changes: 28 additions & 12 deletions js/src/highjump.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function Jumper(kwds) {
'category',
'OPEN',
'order',
1
1,
'non_scorer',
false
];

const options = _options || {};
Expand Down Expand Up @@ -207,6 +209,7 @@ function HighJumpCompetition() {
this.inJumpOff = false;
this.actions = []; // log for replay purposes.
this.state = 'scheduled';
this.sortNonScorersLast = false;
},

addJumper(kwds) {
Expand Down Expand Up @@ -351,22 +354,35 @@ function HighJumpCompetition() {
return cmpKeys(a, b);
},

_rankj() {
_rankj(verbose = false) {
// sort them
const self = this;
const rankj = this.rankedJumpers;
const rankjlen = rankj.length;
let i;

// console.log('rankj before', rankj);

if (verbose) {
console.log('rankj before', rankj);
}
for (i = 0; i < rankjlen; i++) rankj[i]._oldPos = i;
rankj.sort(function (a, b) {
var r;

// console.log(a.first_name, b.first_name);
r = cmpKeys([a.rankingKey, a._oldPos], [b.rankingKey, b._oldPos]);

// console.log('result', r);
var r,
aKeys = [a.rankingKey, a._oldPos],
bKeys = [b.rankingKey, b._oldPos];

if (self.sortNonScorersLast) {
if (a.non_scorer) {
aKeys = [[3, ...a.rankingKey.splice(1)], a._oldPos];
} else if (b.non_scorer) {
bKeys = [[3, ...b.rankingKey.splice(1)], b._oldPos];
}
r = cmpKeys(aKeys, bKeys);
} else {
r = cmpKeys(aKeys, bKeys);
}
if (verbose) {
console.log(a.first_name, aKeys, b.first_name, bKeys, 'result', r);
}
return r;
});

Expand All @@ -392,11 +408,11 @@ function HighJumpCompetition() {
return rankj;
},

_rank() {
_rank(verbose = false) {
var nc;

// Determine who is winning
const rankj = this._rankj();
const rankj = this._rankj(verbose);

if (rankj.length === 0) return;

Expand Down
33 changes: 33 additions & 0 deletions js/test/highjump.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,38 @@ describe('Given an instance of Athlib.HighJumpCompetition', function(){
it("test athlete with no jumps is eliminated", ()=>{ expect(emanuoil_karalis.eliminated).to.be.equal(true) })


});

describe('test ranking order of result with non scorer',function(){
// add disqualification
BELGRADE_INDOOR_HJ.push(["1", 1, 1999, "Llewellyn", "BRUNSDON-HALAND", "SWE", "M", "", "", "", "", "", "", "", "", "", "", "DNS", ""])
const c = Athlib.HighJumpCompetition.fromMatrix(BELGRADE_INDOOR_HJ);
c.state = 'finished' // pretend we simulated a HJ competition
// console.log(c)

c.sortNonScorersLast = true

// ["1", 1, 148, "Armand", "DUPLANTIS", "SWE", "M", "", "", "", "", "o", "", "", "o", "o", "xxo", 6.19, ""],
c.jumpers[0].non_scorer = true



c._rank(true)
var rank_aths = c.rankedJumpers

var armand_duplantis = rank_aths.find(ath => ath.bib === "148")

it("test armand_duplantis placed last but infront of any disqualifications",()=>{ expect(rank_aths[2]).deep.to.be.equal(armand_duplantis) });

it("test ordering correct",()=>{ expect(rank_aths.map(r => r.bib)).deep.to.be.equal(["152", "153", "148", "150", "151", "149", "1999"]) });

// it("test correct calc rankingKey", ()=>{ expect(emanuoil_karalis.rankingKey).deep.to.be.equal([ 3, -0, 0, 0 ]) })

// it("test athlete is eliminated", ()=>{ expect(wenwen_chen.eliminated).to.be.equal(true) })

// // athletes with no jump will be set as eliminted once the state is set to 'finished'
// it("test athlete with no jumps is eliminated", ()=>{ expect(emanuoil_karalis.eliminated).to.be.equal(true) })


});
});