@rasifix/orienteering-utils 2.0.67 → 2.0.69

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.
@@ -76,6 +76,7 @@ export interface RankingInfo {
76
76
  idealBehind?: number;
77
77
  }
78
78
  export interface SplitInfo extends RankingInfo {
79
+ idealSplit: number;
79
80
  performanceIndex?: number;
80
81
  }
81
82
  export declare function parseRanking(runners: Runner[]): Ranking;
@@ -29,19 +29,28 @@ function assignLegInfoToSplits(runners, legs) {
29
29
  .forEach(function (split) {
30
30
  var leg = legs[split.legCode];
31
31
  if (!leg) {
32
- throw "leg with code " + split.leg + " not defined!";
32
+ throw "leg with code " + split.legCode + " not defined!";
33
33
  }
34
34
  split.legCode = leg.code;
35
35
  var legRunner = leg.runners.find(function (r) { return r.id === runner.id; });
36
36
  if (legRunner) {
37
+ split.leg.idealSplit = leg.idealSplit;
37
38
  split.leg.idealBehind = leg.idealSplit && legRunner.split - leg.idealSplit;
38
39
  split.leg.behind = legRunner.splitBehind;
39
40
  split.leg.rank = legRunner.splitRank;
40
41
  split.performanceIndex = legRunner.performanceIndex;
41
42
  }
42
- split.weight = leg.weight;
43
+ else {
44
+ console.warn("runner ", runner.fullName, " not found in leg ", leg.code);
45
+ }
43
46
  });
44
47
  runner.errorTime = (0, analyzis_1.errorTime)(runner, { thresholdRelative: 1.2, thresholdAbsolute: 10 });
48
+ var idealTime = runner.splits.reduce(function (sum, split) {
49
+ return sum + (split.leg.idealSplit || 0);
50
+ }, 0);
51
+ runner.splits.forEach(function (split) {
52
+ split.weight = split.leg.idealSplit / idealTime;
53
+ });
45
54
  });
46
55
  }
47
56
  function rank(runners) {
@@ -82,22 +91,17 @@ function parseRanking(runners) {
82
91
  var rankingRunners = defineRunners(runners);
83
92
  // prepare auxiliary data about the legs needed to calculate ideal times, weights, ...
84
93
  var legs = defineLegs(rankingRunners);
85
- // calculate the ideal time [s]
86
- var idealTime = Object.keys(legs)
87
- .map(function (code) { return legs[code].idealSplit; })
88
- .filter(function (time) { return time !== undefined; })
89
- .reduce(sum, 0);
90
94
  // each leg's weight is calculated regarding as a ratio of the ideal split time to the ideal time
91
- Object.keys(legs).forEach(function (code) {
92
- var leg = legs[code];
93
- if (leg.idealSplit && idealTime > 0) {
94
- leg.weight = leg.idealSplit / idealTime;
95
- }
96
- if (!leg.weight || isNaN(leg.weight)) {
97
- console.warn("invalid weight for leg ", code, leg.idealSplit, idealTime);
98
- }
99
- });
100
- // now assing the leg information (such as idealTime, weight, ...) to the individual splits of the runners
95
+ /*Object.keys(legs).forEach((code) => {
96
+ let leg = legs[code];
97
+ if (leg.idealSplit && idealTime > 0) {
98
+ leg.weight = leg.idealSplit / idealTime;
99
+ }
100
+ if (!leg.weight || isNaN(leg.weight)) {
101
+ console.warn("invalid weight for leg ", code, leg.idealSplit, idealTime);
102
+ }
103
+ });*/
104
+ // now assing the leg information (such as idealTime, ...) to the individual splits of the runners
101
105
  assignLegInfoToSplits(rankingRunners, legs);
102
106
  rankingRunners.forEach(function (runner) {
103
107
  var behind = 0;
@@ -162,9 +166,11 @@ function parseRanking(runners) {
162
166
  memo.set(pos, result);
163
167
  return result;
164
168
  };
169
+ // now calculate the split ranks and behinds for each split of each runner
165
170
  rankingRunners.forEach(function (runner) {
166
171
  runner.splits.forEach(function (split) {
167
- var times = timesAtPosition(split.position)
172
+ var tap = timesAtPosition(split.position);
173
+ var times = tap
168
174
  .filter(function (entry) { return entry.time && entry.time > 0; })
169
175
  .map(function (entry) {
170
176
  return { id: entry.id, time: entry.time };
@@ -173,8 +179,8 @@ function parseRanking(runners) {
173
179
  if (!split.position || isNaN(split.position)) {
174
180
  return;
175
181
  }
176
- if (!times || times.length === 0) {
177
- console.warn("no times at position ", split.position, split.weight, " for runner ", runner.fullName, runner.time, times.length);
182
+ if (times.length === 0) {
183
+ console.warn("no times at position ", split.position, " for runner ", runner.team || runner.fullName, runner.time, times.length);
178
184
  return;
179
185
  }
180
186
  var rank = 1;
@@ -324,7 +330,8 @@ function defineRunnerLegSplit(split, idx, runner) {
324
330
  leg: {
325
331
  rank: undefined,
326
332
  behind: 0,
327
- idealBehind: undefined
333
+ idealBehind: undefined,
334
+ idealSplit: 0
328
335
  },
329
336
  overall: {
330
337
  rank: undefined,
@@ -367,7 +374,6 @@ function defineLegs(runners) {
367
374
  }, {});
368
375
  runners.forEach(function (runner) {
369
376
  runner.splits
370
- //.filter((s) => validTime(s.time))
371
377
  .forEach(function (split, idx) {
372
378
  var from = idx === 0 ? "St" : runner.splits[idx - 1].code;
373
379
  var to = split.code;
@@ -407,6 +413,7 @@ function defineLegProperties(legs) {
407
413
  });
408
414
  // calculate the ideal time: take up to 5 fastest on that leg
409
415
  var selected = leg.runners
416
+ .filter(function (runner) { return runner.split > 0; })
410
417
  .slice(0, Math.min(leg.runners.length, 5))
411
418
  .map(function (runner) { return runner.split; });
412
419
  // only if there are valid splits for this leg
@@ -56,6 +56,7 @@ function parseRelayRanking(runners) {
56
56
  id: firstRunner.id,
57
57
  category: firstRunner.category,
58
58
  fullName: teamRunners.map(function (r) { return r.fullName; }).join(' / '),
59
+ club: teamRunners.filter(function (r) { return r.club && r.club.trim().length > 0; }).map(function (r) { return r.club; }).join(' / '),
59
60
  startTime: firstRunner.startTime,
60
61
  startNumber: startNumber,
61
62
  team: firstRunner.team,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rasifix/orienteering-utils",
3
- "version": "2.0.67",
3
+ "version": "2.0.69",
4
4
  "description": "utility functions for orienteering result analyzis",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",