@rasifix/orienteering-utils 2.0.61 → 2.0.63
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/formats/picoevents.js +33 -1
- package/lib/utils/ranking.js +5 -6
- package/package.json +1 -1
|
@@ -40,7 +40,7 @@ var PicoeventsFormat = /** @class */ (function () {
|
|
|
40
40
|
var clubIdx = header.indexOf("[CLUB]");
|
|
41
41
|
var runtimeNetIdx = header.indexOf("[RUNTIMENET]");
|
|
42
42
|
lines.forEach(function (line, idx) {
|
|
43
|
-
var tokens = line
|
|
43
|
+
var tokens = parseCSVLine(line);
|
|
44
44
|
if (tokens.length < 50) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
@@ -99,3 +99,35 @@ var PicoeventsFormat = /** @class */ (function () {
|
|
|
99
99
|
return PicoeventsFormat;
|
|
100
100
|
}());
|
|
101
101
|
exports.PicoeventsFormat = PicoeventsFormat;
|
|
102
|
+
function parseCSVLine(line) {
|
|
103
|
+
var fields = [];
|
|
104
|
+
var current = '';
|
|
105
|
+
var inQuotes = false;
|
|
106
|
+
var i = 0;
|
|
107
|
+
while (i < line.length) {
|
|
108
|
+
var char = line[i];
|
|
109
|
+
if (char === '"') {
|
|
110
|
+
if (inQuotes && i + 1 < line.length && line[i + 1] === '"') {
|
|
111
|
+
// Escaped quote
|
|
112
|
+
current += '"';
|
|
113
|
+
i++; // Skip next quote
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// Toggle quote state
|
|
117
|
+
inQuotes = !inQuotes;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (char === ',' && !inQuotes) {
|
|
121
|
+
// Field separator
|
|
122
|
+
fields.push(current);
|
|
123
|
+
current = '';
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
current += char;
|
|
127
|
+
}
|
|
128
|
+
i++;
|
|
129
|
+
}
|
|
130
|
+
// Add the last field
|
|
131
|
+
fields.push(current);
|
|
132
|
+
return fields;
|
|
133
|
+
}
|
package/lib/utils/ranking.js
CHANGED
|
@@ -94,7 +94,7 @@ function parseRanking(runners) {
|
|
|
94
94
|
leg.weight = leg.idealSplit / idealTime;
|
|
95
95
|
}
|
|
96
96
|
if (!leg.weight || isNaN(leg.weight)) {
|
|
97
|
-
console.
|
|
97
|
+
console.warn("invalid weight for leg ", code, leg.idealSplit, idealTime);
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
// now assing the leg information (such as idealTime, weight, ...) to the individual splits of the runners
|
|
@@ -174,7 +174,7 @@ function parseRanking(runners) {
|
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
176
|
if (!times || times.length === 0) {
|
|
177
|
-
console.
|
|
177
|
+
console.warn("no times at position ", split.position, split.weight, " for runner ", runner.fullName, runner.time, times.length);
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
var rank = 1;
|
|
@@ -273,7 +273,6 @@ function defineCourses(runners) {
|
|
|
273
273
|
courses[course].runners.push(runner.id);
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
|
-
console.log("defined courses: ", Object.keys(courses));
|
|
277
276
|
return Object.keys(courses).map(function (key) { return courses[key]; });
|
|
278
277
|
}
|
|
279
278
|
function defineRunners(runners) {
|
|
@@ -412,12 +411,12 @@ function defineLegProperties(legs) {
|
|
|
412
411
|
if (selected.length > 0) {
|
|
413
412
|
leg.idealSplit = Math.round(selected.reduce(sum, 0) / selected.length);
|
|
414
413
|
if (leg.idealSplit < 0 || isNaN(leg.idealSplit)) {
|
|
415
|
-
console.
|
|
414
|
+
console.warn("invalid ideal split calculated for leg " + code, leg.idealSplit, selected);
|
|
416
415
|
leg.idealSplit = 30;
|
|
417
416
|
}
|
|
418
417
|
}
|
|
419
418
|
else {
|
|
420
|
-
console.
|
|
419
|
+
console.warn("no valid splits for leg " + code + " found, setting ideal split to 30s");
|
|
421
420
|
leg.idealSplit = 30;
|
|
422
421
|
}
|
|
423
422
|
// only if there are valid splits for this leg
|
|
@@ -442,7 +441,7 @@ function defineLegProperties(legs) {
|
|
|
442
441
|
runner.performanceIndex = Math.round(((1.0 * leg.idealSplit) / runner.split) * 100);
|
|
443
442
|
}
|
|
444
443
|
else {
|
|
445
|
-
console.
|
|
444
|
+
console.warn("cannot calculate performance index for runner ", runner.fullName, " on leg ", code);
|
|
446
445
|
}
|
|
447
446
|
});
|
|
448
447
|
}
|