@rasifix/orienteering-utils 2.0.58 → 2.0.60

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.
@@ -65,7 +65,7 @@ var SolvFormat = /** @class */ (function () {
65
65
  };
66
66
  if (tokens.length - 12 < category.controls * 2) {
67
67
  // some crappy SOLV data...
68
- console.log("fix crappy data from SOLV - not enough tokens on line for runner " +
68
+ console.debug("fix crappy data from SOLV - not enough tokens on line for runner " +
69
69
  runner.fullName);
70
70
  for (var i = tokens.length; i < category.controls * 2 + 12; i++) {
71
71
  if (i % 2 === 0) {
@@ -92,7 +92,6 @@ var SolvFormat = /** @class */ (function () {
92
92
  }
93
93
  runner.splits.push({ code: tokens[i_1], time: time });
94
94
  }
95
- console.log("adding Zi split for runner " + runner.fullName, runner.time);
96
95
  runner.splits.push({ code: "Zi", time: runner.time });
97
96
  category.runners.push(runner);
98
97
  });
@@ -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.58",
3
+ "version": "2.0.60",
4
4
  "description": "utility functions for orienteering result analyzis",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",