@rasifix/orienteering-utils 2.0.59 → 2.0.61

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.
@@ -29,7 +29,7 @@ var PicoeventsFormat = /** @class */ (function () {
29
29
  };
30
30
  var header = lines.splice(0, 1)[0].split(",");
31
31
  var sortKeyIdx = header.indexOf("[SORTKEY]");
32
- var statusIdx = header.indexOf("[IOFRESSTATTEXT]");
32
+ var statusIdx = header.indexOf("[RESPERSIDX]");
33
33
  var startTimeIdx = header.indexOf("[STARTFULLPREC]");
34
34
  var noOfSplitsIdx = header.indexOf("[NOFSPLITS]");
35
35
  var termIdx = header.indexOf("[TERM]");
@@ -61,7 +61,7 @@ var PicoeventsFormat = /** @class */ (function () {
61
61
  result.categories.push(category);
62
62
  }
63
63
  var status = tokens[statusIdx];
64
- if (status !== "OK") {
64
+ if (status !== "5" && status !== "2") {
65
65
  return;
66
66
  }
67
67
  var startTime = parseInt(tokens[startTimeIdx]);
@@ -36,6 +36,7 @@ export interface Ranking {
36
36
  export interface RankingRunner {
37
37
  id: string;
38
38
  category: string;
39
+ course?: string;
39
40
  rank?: number;
40
41
  fullName: string;
41
42
  time?: string;
@@ -197,6 +197,42 @@ function parseRanking(runners) {
197
197
  });
198
198
  // calculate the overall rank
199
199
  rank(rankingRunners);
200
+ // assign course property
201
+ var runnerToCourse = new Map();
202
+ courses.forEach(function (course) {
203
+ course.runners.forEach(function (runnerId) {
204
+ runnerToCourse.set(runnerId, course.code);
205
+ });
206
+ });
207
+ var categoryGroups = new Map();
208
+ rankingRunners.forEach(function (runner) {
209
+ if (!categoryGroups.has(runner.category)) {
210
+ categoryGroups.set(runner.category, []);
211
+ }
212
+ categoryGroups.get(runner.category).push(runner);
213
+ });
214
+ categoryGroups.forEach(function (runnersInCat, category) {
215
+ var courseCodes = new Set();
216
+ runnersInCat.forEach(function (runner) {
217
+ var courseCode = runnerToCourse.get(runner.id);
218
+ if (courseCode) {
219
+ courseCodes.add(courseCode);
220
+ }
221
+ });
222
+ if (courseCodes.size > 1) {
223
+ var sortedCourses = Array.from(courseCodes).sort();
224
+ var courseMap_1 = new Map();
225
+ sortedCourses.forEach(function (code, index) {
226
+ courseMap_1.set(code, category + String.fromCharCode(65 + index)); // A, B, C...
227
+ });
228
+ runnersInCat.forEach(function (runner) {
229
+ var courseCode = runnerToCourse.get(runner.id);
230
+ if (courseCode) {
231
+ runner.course = courseMap_1.get(courseCode);
232
+ }
233
+ });
234
+ }
235
+ });
200
236
  Object.values(legs).forEach(function (leg) {
201
237
  var ideal = leg.idealSplit;
202
238
  var min = leg.runners.filter(function (runner) { return !isNaN(runner.split) && runner.split !== undefined; }).map(function (runner) { return runner.split; }).reduce(function (min, split) { return Math.min(min, split - ideal); }, Number.MAX_VALUE);
@@ -237,6 +273,7 @@ function defineCourses(runners) {
237
273
  courses[course].runners.push(runner.id);
238
274
  }
239
275
  });
276
+ console.log("defined courses: ", Object.keys(courses));
240
277
  return Object.keys(courses).map(function (key) { return courses[key]; });
241
278
  }
242
279
  function defineRunners(runners) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasifix/orienteering-utils",
3
- "version": "2.0.59",
3
+ "version": "2.0.61",
4
4
  "description": "utility functions for orienteering result analyzis",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",