@time2win/t2w 1.4.19 → 1.4.20
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/CHANGELOG.md +4 -0
- package/index.d.ts +1 -0
- package/index.js +33 -6
- package/models.d.ts +4 -0
- package/package.json +1 -1
- package/test.js +1 -5
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 1.4.20 - 2025-03-13
|
|
9
|
+
### Added
|
|
10
|
+
```paceBrutto``` ```paceNetto``` ```speedBrutto``` ```speedNetto``` properties for individual result
|
|
11
|
+
|
|
8
12
|
## 1.4.19 - 2025-02-25
|
|
9
13
|
### Added
|
|
10
14
|
```age``` property for participant info
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -206,7 +206,7 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
206
206
|
};
|
|
207
207
|
fetch(_this.getUrl("results/".concat(eventId, "/individuals"), queryParams))
|
|
208
208
|
.then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
209
|
-
var body, _a, _b, _c;
|
|
209
|
+
var body, event, _a, _b, _c;
|
|
210
210
|
var _d;
|
|
211
211
|
var _this = this;
|
|
212
212
|
return __generator(this, function (_e) {
|
|
@@ -218,18 +218,21 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
218
218
|
reject(body);
|
|
219
219
|
return [2 /*return*/];
|
|
220
220
|
}
|
|
221
|
-
|
|
221
|
+
return [4 /*yield*/, this.getEventData(eventId, ['splits'])];
|
|
222
|
+
case 2:
|
|
223
|
+
event = _e.sent();
|
|
224
|
+
if (!(body.page < body.page_total)) return [3 /*break*/, 4];
|
|
222
225
|
_b = (_a = (_d = body.list).push).apply;
|
|
223
226
|
_c = [_d];
|
|
224
227
|
return [4 /*yield*/, this.getIndividualResults(eventId, raceId, dataExtra, gender, body.page + 1)];
|
|
225
|
-
case
|
|
228
|
+
case 3:
|
|
226
229
|
_b.apply(_a, _c.concat([(_e.sent()).list]));
|
|
227
230
|
body.page = Math.ceil(body.list.length / body.page_size);
|
|
228
231
|
resolve(body);
|
|
229
|
-
_e.label =
|
|
230
|
-
case
|
|
232
|
+
_e.label = 4;
|
|
233
|
+
case 4:
|
|
231
234
|
body.list = body.list.map(function (p) {
|
|
232
|
-
return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, racenumNumeric: _this.getNumericBib(p.racenum) });
|
|
235
|
+
return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, racenumNumeric: _this.getNumericBib(p.racenum), speedNetto: _this.calculateSpeed(p, event, 'speed', 'netto') + ' km/h', speedBrutto: _this.calculateSpeed(p, event, 'speed', 'brutto') + ' km/h', paceNetto: _this.calculateSpeed(p, event, 'pace', 'netto') + ' min/km', paceBrutto: _this.calculateSpeed(p, event, 'pace', 'brutto') + ' min/km' });
|
|
233
236
|
});
|
|
234
237
|
resolve(body);
|
|
235
238
|
return [2 /*return*/];
|
|
@@ -385,6 +388,30 @@ var Time2WinAPI = /** @class */ (function () {
|
|
|
385
388
|
}
|
|
386
389
|
return Number((bib.match(/[0-9]/g) || []).join(''));
|
|
387
390
|
};
|
|
391
|
+
Time2WinAPI.prototype.calculateSpeed = function (p, event, returnType, timeType) {
|
|
392
|
+
var race = event.races.find(function (race) { return race.race_id === p.race_id; });
|
|
393
|
+
var time = timeType === 'netto' ? p.finishtime_fromchip_ms : p.finishtime_fromgun_ms;
|
|
394
|
+
if (!race || !time)
|
|
395
|
+
return '-';
|
|
396
|
+
// calculate speed in km/h
|
|
397
|
+
if (returnType === 'speed') {
|
|
398
|
+
// Convert time from milliseconds to hours
|
|
399
|
+
var timeHours = time / (1000 * 60 * 60);
|
|
400
|
+
// Convert distance from meters to kilometers
|
|
401
|
+
var distanceKm = race.distance / 1000;
|
|
402
|
+
// Calculate speed in km/h
|
|
403
|
+
return (distanceKm / timeHours).toFixed(2).replace('.00', '').replace('.', ',');
|
|
404
|
+
}
|
|
405
|
+
if (returnType === 'pace') {
|
|
406
|
+
// Calculate pace in seconds per km
|
|
407
|
+
var paceSecondsPerKm = (time / 1000) / (race.distance / 1000);
|
|
408
|
+
var paceMinutes = Math.floor(paceSecondsPerKm / 60);
|
|
409
|
+
var paceSeconds = Math.round(paceSecondsPerKm % 60);
|
|
410
|
+
// Format pace as mm:ss/km
|
|
411
|
+
return "".concat(String(paceMinutes).padStart(2, '0'), ":").concat(String(paceSeconds).padStart(2, '0'));
|
|
412
|
+
}
|
|
413
|
+
return '-';
|
|
414
|
+
};
|
|
388
415
|
return Time2WinAPI;
|
|
389
416
|
}());
|
|
390
417
|
exports.default = Time2WinAPI;
|
package/models.d.ts
CHANGED
|
@@ -170,6 +170,10 @@ export interface T2WIndividualResult extends T2WParticipantBasic {
|
|
|
170
170
|
finishtime_fromchip: string | null;
|
|
171
171
|
finishtime_fromchip_ms: number | null;
|
|
172
172
|
laps_count: number;
|
|
173
|
+
paceNetto: string;
|
|
174
|
+
paceBrutto: string;
|
|
175
|
+
speedNetto: string;
|
|
176
|
+
speedBrutto: string;
|
|
173
177
|
}
|
|
174
178
|
export interface T2WIndividualResultSplit {
|
|
175
179
|
distance: number;
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -5,8 +5,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var index_1 = __importDefault(require("./index"));
|
|
7
7
|
var api = new index_1.default('09f006ca-23ee-44da-bec5-4372580f4113');
|
|
8
|
-
api.
|
|
9
|
-
// console.log('SUCCESS', res);
|
|
10
|
-
}).catch(function (err) {
|
|
11
|
-
console.log('ERROR', err);
|
|
12
|
-
});
|
|
8
|
+
api.getIndividualResults(38, 161).then(console.log);
|