@rasifix/orienteering-utils 2.0.62 → 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.
@@ -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.split(",");
43
+ var tokens = parseCSVLine(line);
44
44
  if (tokens.length < 50) {
45
45
  return;
46
46
  }
@@ -61,7 +61,6 @@ var PicoeventsFormat = /** @class */ (function () {
61
61
  result.categories.push(category);
62
62
  }
63
63
  var status = tokens[statusIdx];
64
- console.log("Parsing runner ".concat(idx + 1, ": ").concat(tokens[firstNameIdx], " ").concat(tokens[familyNameIdx], " with status ").concat(status, " in category ").concat(name));
65
64
  if (status !== "5" && status !== "2") {
66
65
  return;
67
66
  }
@@ -100,3 +99,35 @@ var PicoeventsFormat = /** @class */ (function () {
100
99
  return PicoeventsFormat;
101
100
  }());
102
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
+ }
@@ -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.log("invalid weight for leg ", code, leg.idealSplit, idealTime);
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.log("no times at position ", split.position, split.weight, " for runner ", runner.fullName, runner.time, times.length);
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.log("invalid ideal split calculated for leg " + code, leg.idealSplit, selected);
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.log("no valid splits for leg " + code + " found, setting ideal split to 30s");
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.log("cannot calculate performance index for runner ", runner.fullName, " on leg ", code);
444
+ console.warn("cannot calculate performance index for runner ", runner.fullName, " on leg ", code);
446
445
  }
447
446
  });
448
447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasifix/orienteering-utils",
3
- "version": "2.0.62",
3
+ "version": "2.0.63",
4
4
  "description": "utility functions for orienteering result analyzis",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",