@rasifix/orienteering-utils 2.0.68 → 2.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utils/ranking.d.ts +1 -0
- package/lib/utils/ranking.js +27 -20
- package/lib/utils/relay.js +1 -1
- package/package.json +1 -1
package/lib/utils/ranking.d.ts
CHANGED
package/lib/utils/ranking.js
CHANGED
|
@@ -34,14 +34,23 @@ function assignLegInfoToSplits(runners, legs) {
|
|
|
34
34
|
split.legCode = leg.code;
|
|
35
35
|
var legRunner = leg.runners.find(function (r) { return r.id === runner.id; });
|
|
36
36
|
if (legRunner) {
|
|
37
|
+
split.leg.idealSplit = leg.idealSplit;
|
|
37
38
|
split.leg.idealBehind = leg.idealSplit && legRunner.split - leg.idealSplit;
|
|
38
39
|
split.leg.behind = legRunner.splitBehind;
|
|
39
40
|
split.leg.rank = legRunner.splitRank;
|
|
40
41
|
split.performanceIndex = legRunner.performanceIndex;
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
else {
|
|
44
|
+
console.warn("runner ", runner.fullName, " not found in leg ", leg.code);
|
|
45
|
+
}
|
|
43
46
|
});
|
|
44
47
|
runner.errorTime = (0, analyzis_1.errorTime)(runner, { thresholdRelative: 1.2, thresholdAbsolute: 10 });
|
|
48
|
+
var idealTime = runner.splits.reduce(function (sum, split) {
|
|
49
|
+
return sum + (split.leg.idealSplit || 0);
|
|
50
|
+
}, 0);
|
|
51
|
+
runner.splits.forEach(function (split) {
|
|
52
|
+
split.weight = split.leg.idealSplit / idealTime;
|
|
53
|
+
});
|
|
45
54
|
});
|
|
46
55
|
}
|
|
47
56
|
function rank(runners) {
|
|
@@ -82,22 +91,17 @@ function parseRanking(runners) {
|
|
|
82
91
|
var rankingRunners = defineRunners(runners);
|
|
83
92
|
// prepare auxiliary data about the legs needed to calculate ideal times, weights, ...
|
|
84
93
|
var legs = defineLegs(rankingRunners);
|
|
85
|
-
// calculate the ideal time [s]
|
|
86
|
-
var idealTime = Object.keys(legs)
|
|
87
|
-
.map(function (code) { return legs[code].idealSplit; })
|
|
88
|
-
.filter(function (time) { return time !== undefined; })
|
|
89
|
-
.reduce(sum, 0);
|
|
90
94
|
// each leg's weight is calculated regarding as a ratio of the ideal split time to the ideal time
|
|
91
|
-
Object.keys(legs).forEach(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
// now assing the leg information (such as idealTime,
|
|
95
|
+
/*Object.keys(legs).forEach((code) => {
|
|
96
|
+
let leg = legs[code];
|
|
97
|
+
if (leg.idealSplit && idealTime > 0) {
|
|
98
|
+
leg.weight = leg.idealSplit / idealTime;
|
|
99
|
+
}
|
|
100
|
+
if (!leg.weight || isNaN(leg.weight)) {
|
|
101
|
+
console.warn("invalid weight for leg ", code, leg.idealSplit, idealTime);
|
|
102
|
+
}
|
|
103
|
+
});*/
|
|
104
|
+
// now assing the leg information (such as idealTime, ...) to the individual splits of the runners
|
|
101
105
|
assignLegInfoToSplits(rankingRunners, legs);
|
|
102
106
|
rankingRunners.forEach(function (runner) {
|
|
103
107
|
var behind = 0;
|
|
@@ -162,9 +166,11 @@ function parseRanking(runners) {
|
|
|
162
166
|
memo.set(pos, result);
|
|
163
167
|
return result;
|
|
164
168
|
};
|
|
169
|
+
// now calculate the split ranks and behinds for each split of each runner
|
|
165
170
|
rankingRunners.forEach(function (runner) {
|
|
166
171
|
runner.splits.forEach(function (split) {
|
|
167
|
-
var
|
|
172
|
+
var tap = timesAtPosition(split.position);
|
|
173
|
+
var times = tap
|
|
168
174
|
.filter(function (entry) { return entry.time && entry.time > 0; })
|
|
169
175
|
.map(function (entry) {
|
|
170
176
|
return { id: entry.id, time: entry.time };
|
|
@@ -173,8 +179,8 @@ function parseRanking(runners) {
|
|
|
173
179
|
if (!split.position || isNaN(split.position)) {
|
|
174
180
|
return;
|
|
175
181
|
}
|
|
176
|
-
if (
|
|
177
|
-
console.warn("no times at position ", split.position,
|
|
182
|
+
if (times.length === 0) {
|
|
183
|
+
console.warn("no times at position ", split.position, " for runner ", runner.team || runner.fullName, runner.time, times.length);
|
|
178
184
|
return;
|
|
179
185
|
}
|
|
180
186
|
var rank = 1;
|
|
@@ -324,7 +330,8 @@ function defineRunnerLegSplit(split, idx, runner) {
|
|
|
324
330
|
leg: {
|
|
325
331
|
rank: undefined,
|
|
326
332
|
behind: 0,
|
|
327
|
-
idealBehind: undefined
|
|
333
|
+
idealBehind: undefined,
|
|
334
|
+
idealSplit: 0
|
|
328
335
|
},
|
|
329
336
|
overall: {
|
|
330
337
|
rank: undefined,
|
package/lib/utils/relay.js
CHANGED
|
@@ -56,7 +56,7 @@ function parseRelayRanking(runners) {
|
|
|
56
56
|
id: firstRunner.id,
|
|
57
57
|
category: firstRunner.category,
|
|
58
58
|
fullName: teamRunners.map(function (r) { return r.fullName; }).join(' / '),
|
|
59
|
-
club: teamRunners.map(function (r) { return r.club; }).join(' / '),
|
|
59
|
+
club: teamRunners.filter(function (r) { return r.club && r.club.trim().length > 0; }).map(function (r) { return r.club; }).join(' / '),
|
|
60
60
|
startTime: firstRunner.startTime,
|
|
61
61
|
startNumber: startNumber,
|
|
62
62
|
team: firstRunner.team,
|