@rasifix/orienteering-utils 2.0.63 → 2.0.65
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 +12 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/model/competition.d.ts +1 -0
- package/lib/model/runner.d.ts +3 -0
- package/lib/utils/relay.d.ts +21 -0
- package/lib/utils/relay.js +93 -0
- package/package.json +1 -1
|
@@ -39,12 +39,19 @@ var PicoeventsFormat = /** @class */ (function () {
|
|
|
39
39
|
var townIdx = header.indexOf("[TOWN]");
|
|
40
40
|
var clubIdx = header.indexOf("[CLUB]");
|
|
41
41
|
var runtimeNetIdx = header.indexOf("[RUNTIMENET]");
|
|
42
|
+
var startNumIdx = header.indexOf("[STARTNUM]");
|
|
43
|
+
var runOrLegIdx = header.indexOf("[RUNORLEG]");
|
|
44
|
+
var baseClassIdx = header.indexOf("[BASECLASS]");
|
|
45
|
+
var teamIdx = header.indexOf("[GROUPNAME]");
|
|
42
46
|
lines.forEach(function (line, idx) {
|
|
43
47
|
var tokens = parseCSVLine(line);
|
|
44
48
|
if (tokens.length < 50) {
|
|
45
49
|
return;
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
if (idx === 0) {
|
|
52
|
+
result.relay = tokens[0].endsWith("=R");
|
|
53
|
+
}
|
|
54
|
+
var name = tokens[baseClassIdx];
|
|
48
55
|
if (name.indexOf("TW") !== -1 || name.indexOf("TM") !== -1) {
|
|
49
56
|
return;
|
|
50
57
|
}
|
|
@@ -74,6 +81,9 @@ var PicoeventsFormat = /** @class */ (function () {
|
|
|
74
81
|
club: clean(tokens[clubIdx]),
|
|
75
82
|
time: (0, time_1.formatTime)(parseInt(tokens[runtimeNetIdx])),
|
|
76
83
|
startTime: (0, time_1.formatTime)(startTime),
|
|
84
|
+
startNumber: clean(tokens[startNumIdx]),
|
|
85
|
+
runOrLeg: tokens[runOrLegIdx] ? parseInt(tokens[runOrLegIdx]) : undefined,
|
|
86
|
+
team: clean(tokens[teamIdx]),
|
|
77
87
|
splits: [],
|
|
78
88
|
};
|
|
79
89
|
for (var i = termIdx + 3; i < tokens.length - 2; i += 2) {
|
|
@@ -88,10 +98,7 @@ var PicoeventsFormat = /** @class */ (function () {
|
|
|
88
98
|
return result;
|
|
89
99
|
};
|
|
90
100
|
PicoeventsFormat.prototype.serialize = function (event) {
|
|
91
|
-
|
|
92
|
-
result += "EXTCLASS=[DATATYPE],[SORTKEY],[ACTITEM],[NOFITEMS],[POINTER],[POSSPLITS],[RUNORLEG],[CLASSSORT],[BASECLASS],[FULLCLASS],[SUBSTCLASS],[COURSE],[MULTIHEATNUM],[REGTIME],[ISCLIQUE],[FAMILYNAME],[FIRSTNAME],[YOB],[SEX],[SEXLOC],[ZIP],[TOWN],[REGION],[COUNTRY],[FEDNR],[CLUB],[CLUBID],[NATION],[NATIONCODE],[IOFID],[RANKING],[GROUPNAME],[GROUPCLUB],[FOREIGNKEY],[REFPERS],[REFHEAT],[REFGRP],[REFEXT],[CARDHASDATA],[CARDNUM],[CARDNUMORIG],[RFID],[STARTNUM],[CLASSSTA],[COMBINATION],[DATEH0],[TIMEPREC],[STARTTIMELIST],[STARTTIMEGATE],[STARTTIMELATE],[STARTFULLPREC],[FINISHFULLPREC],[STARTPRECADJ],[FINISHPRECADJ],[RUNTIMEEFF],[RUNTIMENET],[RANKNET],[BEHINDNET],[PENALTY],[CREDIT],[NEUTRAL],[POINTS],[TIMEUSERMOD],[CARDUSERMOD],[RESPERSIDX],[RESCARDIDX],[IOFRESSTATTEXT],[INFOALL],[INFOMAND],[NOTCLASSTEXT],[RANKTEXT],[RESULTTEXT],[BEHINDTEXT],[PENCRENEUTTEXT],[SCHEDULED],[STARTED],[FINISHED],[SLIADDTEXT],[RESADDTEXT],[RENMERGINFO],[LIVEOFFSET],[LIVEINVALID1],[LIVEINVALID2],[LIVEINVALID3],[LEGMASSSTART],[LEGMAXTIMELIMIT],[LEGMAXTIMENCLA],[RELAYSTARTTIME],[RELCUMRUNTIMEEFF],[RELCUMRUNTIMENET],[RELCUMRANKNET],[RELCUMBEHINDNET],[RELCUMRANKTEXT],[RELCUMRESULTTEXT],[RELCUMBEHINDTEXT],[RELCUMPERSRESIDX],[RELCUMIOFSTATTEXT],[RELCUMINFOALL],[RELCUMINFOMAND],[RELCUMNOTCLATEXT],[RELCUMMASTAFLAG],[RELCUMSTARTED],[RELCUMFINISHED],[RELCUMORDERRES],[RELCUMSPARE2],[RELCUMSPARE3],[EXCLUDED],[NEGRUNTIME],[CLASSOKNOTREADY],[RESULTINVALID],[DOPSTATOK],[SLIORDER],[SORTORDERRES],[SUBSECRUNTIMENET],[STARTTIMEEXT],[FINISHTIMEEXT],[RUNTIMENETFULLPREC],[IMPORTGROUPID],[IMPORTUSER],[HIDETIME],[PAID],[RESERVE8],[RESERVE7],[RESERVE6],[RESERVE5],[RESERVE4],[LASTUPDATE],[MISSLISTCODE],[EXTRALISTCODE],[EXTRALISTTIME],[RADIOLISTCODE],[NOFSPLITS],[NOFSPLITPARAMS],[SPLITTYPE],[SPLITSTATUS],[TERM]\n";
|
|
93
|
-
// FIXME: implement serialization of runners
|
|
94
|
-
return result;
|
|
101
|
+
throw new Error("format does not implement serialization");
|
|
95
102
|
};
|
|
96
103
|
PicoeventsFormat.prototype.check = function (text) {
|
|
97
104
|
return text.startsWith("BasicData,");
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as formats from './formats';
|
|
2
2
|
import * as ranking from './utils/ranking';
|
|
3
|
+
import * as relay from './utils/relay';
|
|
3
4
|
import * as model from './model';
|
|
4
5
|
import { Format } from './format';
|
|
5
6
|
import { formatTime, parseTime } from './time';
|
|
6
|
-
export { formats, ranking, model, Format, formatTime, parseTime };
|
|
7
|
+
export { formats, ranking, relay, model, Format, formatTime, parseTime };
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTime = exports.formatTime = exports.model = exports.ranking = exports.formats = void 0;
|
|
3
|
+
exports.parseTime = exports.formatTime = exports.model = exports.relay = exports.ranking = exports.formats = void 0;
|
|
4
4
|
var formats = require("./formats");
|
|
5
5
|
exports.formats = formats;
|
|
6
6
|
var ranking = require("./utils/ranking");
|
|
7
7
|
exports.ranking = ranking;
|
|
8
|
+
var relay = require("./utils/relay");
|
|
9
|
+
exports.relay = relay;
|
|
8
10
|
var model = require("./model");
|
|
9
11
|
exports.model = model;
|
|
10
12
|
var time_1 = require("./time");
|
package/lib/model/runner.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Runner } from "../model";
|
|
2
|
+
import { Ranking } from "./ranking";
|
|
3
|
+
export interface Team {
|
|
4
|
+
name: string;
|
|
5
|
+
startNumber: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Extract all unique teams from the given runners.
|
|
9
|
+
*
|
|
10
|
+
* @param runners the runners to extract teams from
|
|
11
|
+
* @returns a list of unique teams with their name and start number
|
|
12
|
+
*/
|
|
13
|
+
export declare function getTeams(runners: Runner[]): Team[];
|
|
14
|
+
/**
|
|
15
|
+
* Create a ranking for a relay event from the given runners. The runners must
|
|
16
|
+
* belong to the same base category.
|
|
17
|
+
*
|
|
18
|
+
* @param runners the runners to create a ranking from
|
|
19
|
+
* @returns a ranking for the relay event
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseRelayRanking(runners: Runner[]): Ranking;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// I need functions to process relay data
|
|
3
|
+
// in case of relay the event returns Runners with startNumber, runOrLeg, baseCategory, team
|
|
4
|
+
// runners of the same team have the same baseCategory and same startNumber
|
|
5
|
+
// runOrLeg indicates which leg of the relay the runner is running
|
|
6
|
+
// e.g. for a 3-leg relay, there will be runners with runOrLeg 1, 2 and 3
|
|
7
|
+
// all runners with runOrLeg 1 belong to the first leg of their team, etc.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getTeams = getTeams;
|
|
10
|
+
exports.parseRelayRanking = parseRelayRanking;
|
|
11
|
+
var ranking_1 = require("./ranking");
|
|
12
|
+
var time_1 = require("../time");
|
|
13
|
+
/**
|
|
14
|
+
* Extract all unique teams from the given runners.
|
|
15
|
+
*
|
|
16
|
+
* @param runners the runners to extract teams from
|
|
17
|
+
* @returns a list of unique teams with their name and start number
|
|
18
|
+
*/
|
|
19
|
+
function getTeams(runners) {
|
|
20
|
+
var teams = new Set();
|
|
21
|
+
runners.forEach(function (runner) {
|
|
22
|
+
if (runner.team && runner.team.trim().length > 0) {
|
|
23
|
+
teams.add({
|
|
24
|
+
name: runner.team,
|
|
25
|
+
startNumber: runner.startNumber ? parseInt(runner.startNumber) : 0
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return Array.from(teams);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a ranking for a relay event from the given runners. The runners must
|
|
33
|
+
* belong to the same base category.
|
|
34
|
+
*
|
|
35
|
+
* @param runners the runners to create a ranking from
|
|
36
|
+
* @returns a ranking for the relay event
|
|
37
|
+
*/
|
|
38
|
+
function parseRelayRanking(runners) {
|
|
39
|
+
// Group runners by team (startNumber)
|
|
40
|
+
var teamMap = new Map();
|
|
41
|
+
runners.forEach(function (runner) {
|
|
42
|
+
var team = runner.startNumber || '';
|
|
43
|
+
if (!teamMap.has(team)) {
|
|
44
|
+
teamMap.set(team, []);
|
|
45
|
+
}
|
|
46
|
+
teamMap.get(team).push(runner);
|
|
47
|
+
});
|
|
48
|
+
// Create combined runners for each team
|
|
49
|
+
var combinedRunners = [];
|
|
50
|
+
teamMap.forEach(function (teamRunners, startNumber) {
|
|
51
|
+
// Sort runners by runOrLeg to ensure correct order
|
|
52
|
+
teamRunners.sort(function (a, b) { return (a.runOrLeg || 0) - (b.runOrLeg || 0); });
|
|
53
|
+
// Start with the first leg runner as the base
|
|
54
|
+
var firstRunner = teamRunners[0];
|
|
55
|
+
var combinedRunner = {
|
|
56
|
+
id: firstRunner.id,
|
|
57
|
+
category: firstRunner.category,
|
|
58
|
+
fullName: teamRunners.map(function (r) { return r.fullName; }).join(' / '),
|
|
59
|
+
startTime: firstRunner.startTime,
|
|
60
|
+
startNumber: startNumber,
|
|
61
|
+
team: firstRunner.team,
|
|
62
|
+
splits: []
|
|
63
|
+
};
|
|
64
|
+
// Combine splits from all legs
|
|
65
|
+
var accumulatedTime = 0;
|
|
66
|
+
teamRunners.forEach(function (runner) {
|
|
67
|
+
runner.splits.forEach(function (split) {
|
|
68
|
+
var splitTime = (0, time_1.parseTime)(split.time);
|
|
69
|
+
if (splitTime !== undefined && splitTime > 0) {
|
|
70
|
+
// Accumulate time from previous legs
|
|
71
|
+
var adjustedTime = splitTime + accumulatedTime;
|
|
72
|
+
// Add the adjusted split
|
|
73
|
+
combinedRunner.splits.push({
|
|
74
|
+
code: split.code,
|
|
75
|
+
time: (0, time_1.formatTime)(adjustedTime)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
// Accumulate the total time of this leg for the next leg
|
|
80
|
+
if (runner.time) {
|
|
81
|
+
var runnerTotalTime = (0, time_1.parseTime)(runner.time);
|
|
82
|
+
if (runnerTotalTime !== undefined && runnerTotalTime > 0) {
|
|
83
|
+
accumulatedTime += runnerTotalTime;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
// Set the final combined time
|
|
88
|
+
combinedRunner.time = (0, time_1.formatTime)(accumulatedTime);
|
|
89
|
+
combinedRunners.push(combinedRunner);
|
|
90
|
+
});
|
|
91
|
+
// Parse the ranking as usual
|
|
92
|
+
return (0, ranking_1.parseRanking)(combinedRunners);
|
|
93
|
+
}
|