@rasifix/orienteering-utils 2.0.24 → 2.0.27
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/analyzis.d.ts +2 -0
- package/lib/utils/analyzis.js +27 -0
- package/lib/utils/ranking.d.ts +2 -0
- package/lib/utils/ranking.js +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorTime = errorTime;
|
|
4
|
+
var time_1 = require("../time");
|
|
5
|
+
function errorTime(runner, options) {
|
|
6
|
+
var thresholdRelative = options.thresholdRelative || 1.2;
|
|
7
|
+
var thresholdAbsolute = options.thresholdAbsolute || 10;
|
|
8
|
+
var perfindices = runner.splits.filter(function (perfidx) { return perfidx; }).map(function (split) { return split.performanceIndex; }).sort(function (s1, s2) { return s1 - s2; });
|
|
9
|
+
var middle = calculateMedian(perfindices);
|
|
10
|
+
var errorTime = 0;
|
|
11
|
+
runner.splits.filter(function (split) { return split.splitTime; }).forEach(function (split) {
|
|
12
|
+
var errorFreeTime = Math.round(split.splitTime * (split.performanceIndex / middle));
|
|
13
|
+
if (split.splitTime / errorFreeTime > thresholdRelative && (split.splitTime - errorFreeTime) > thresholdAbsolute) {
|
|
14
|
+
split.timeLoss = split.splitTime - errorFreeTime;
|
|
15
|
+
errorTime += split.timeLoss;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return (0, time_1.formatTime)(errorTime);
|
|
19
|
+
}
|
|
20
|
+
function calculateMedian(perfindices) {
|
|
21
|
+
if (perfindices.length % 2 === 1) {
|
|
22
|
+
return perfindices[Math.floor(perfindices.length / 2)];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return (perfindices[perfindices.length / 2] + perfindices[perfindices.length / 2 + 1]) / 2;
|
|
26
|
+
}
|
|
27
|
+
}
|
package/lib/utils/ranking.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export interface RankingRunner {
|
|
|
39
39
|
rank?: number;
|
|
40
40
|
fullName: string;
|
|
41
41
|
time?: string;
|
|
42
|
+
errorTime: string;
|
|
42
43
|
yearOfBirth?: string;
|
|
43
44
|
city?: string;
|
|
44
45
|
club?: string;
|
|
@@ -49,6 +50,7 @@ export interface RankingSplit {
|
|
|
49
50
|
legCode: string;
|
|
50
51
|
time?: number;
|
|
51
52
|
splitTime?: number;
|
|
53
|
+
timeLoss?: number;
|
|
52
54
|
overall: RankingInfo;
|
|
53
55
|
leg: SplitInfo;
|
|
54
56
|
performanceIndex: number | undefined;
|
package/lib/utils/ranking.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseRanking = parseRanking;
|
|
4
4
|
var time_1 = require("../time");
|
|
5
|
+
var analyzis_1 = require("./analyzis");
|
|
5
6
|
function invalidTime(time) {
|
|
6
7
|
return time === undefined || time < 0;
|
|
7
8
|
}
|
|
@@ -40,9 +41,26 @@ function assignLegInfoToSplits(runners, legs) {
|
|
|
40
41
|
}
|
|
41
42
|
split.weight = leg.weight;
|
|
42
43
|
});
|
|
44
|
+
runner.errorTime = (0, analyzis_1.errorTime)(runner, { thresholdRelative: 1.2, thresholdAbsolute: 10 });
|
|
43
45
|
});
|
|
44
46
|
}
|
|
45
47
|
function rank(runners) {
|
|
48
|
+
runners.sort(function (r1, r2) {
|
|
49
|
+
var t1 = (0, time_1.parseTime)(r1.time);
|
|
50
|
+
var t2 = (0, time_1.parseTime)(r2.time);
|
|
51
|
+
if (invalidTime(t1) && invalidTime(t2)) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
else if (invalidTime(t1)) {
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
else if (invalidTime(t2)) {
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return t1 - t2;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
46
64
|
runners.forEach(function (runner, idx) {
|
|
47
65
|
if (idx === 0) {
|
|
48
66
|
runner.rank = 1;
|
|
@@ -238,6 +256,7 @@ function defineRunners(runners) {
|
|
|
238
256
|
city: runner.city,
|
|
239
257
|
club: runner.club,
|
|
240
258
|
splits: splits,
|
|
259
|
+
errorTime: '00:00'
|
|
241
260
|
};
|
|
242
261
|
});
|
|
243
262
|
}
|