@time2win/t2w 1.4.19 → 1.4.21

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 CHANGED
@@ -5,6 +5,14 @@ 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.21 - 2025-03-13
9
+ ### Modified
10
+ ```paceBrutto``` ```paceNetto``` ```speedBrutto``` ```speedNetto``` properties to support laps
11
+
12
+ ## 1.4.20 - 2025-03-13
13
+ ### Added
14
+ ```paceBrutto``` ```paceNetto``` ```speedBrutto``` ```speedNetto``` properties for individual result
15
+
8
16
  ## 1.4.19 - 2025-02-25
9
17
  ### Added
10
18
  ```age``` property for participant info
package/index.d.ts CHANGED
@@ -17,4 +17,5 @@ export default class Time2WinAPI {
17
17
  private calculateAge;
18
18
  private formatDate;
19
19
  private getNumericBib;
20
+ private calculateSpeed;
20
21
  }
package/index.js CHANGED
@@ -206,30 +206,34 @@ 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
- return __generator(this, function (_e) {
213
- switch (_e.label) {
212
+ var _e;
213
+ return __generator(this, function (_f) {
214
+ switch (_f.label) {
214
215
  case 0: return [4 /*yield*/, response.json()];
215
216
  case 1:
216
- body = _e.sent();
217
+ body = _f.sent();
217
218
  if (response.status === 403) {
218
219
  reject(body);
219
220
  return [2 /*return*/];
220
221
  }
221
- if (!(body.page < body.page_total)) return [3 /*break*/, 3];
222
+ return [4 /*yield*/, this.getEventData(eventId, ['splits'])];
223
+ case 2:
224
+ event = _f.sent();
225
+ if (!(body.page < body.page_total)) return [3 /*break*/, 4];
222
226
  _b = (_a = (_d = body.list).push).apply;
223
227
  _c = [_d];
224
228
  return [4 /*yield*/, this.getIndividualResults(eventId, raceId, dataExtra, gender, body.page + 1)];
225
- case 2:
226
- _b.apply(_a, _c.concat([(_e.sent()).list]));
229
+ case 3:
230
+ _b.apply(_a, _c.concat([(_f.sent()).list]));
227
231
  body.page = Math.ceil(body.list.length / body.page_size);
228
232
  resolve(body);
229
- _e.label = 3;
230
- case 3:
231
- 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) });
233
+ _f.label = 4;
234
+ case 4:
235
+ body.list = (_e = body.list) === null || _e === void 0 ? void 0 : _e.map(function (p) {
236
+ 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
237
  });
234
238
  resolve(body);
235
239
  return [2 /*return*/];
@@ -385,6 +389,31 @@ var Time2WinAPI = /** @class */ (function () {
385
389
  }
386
390
  return Number((bib.match(/[0-9]/g) || []).join(''));
387
391
  };
392
+ Time2WinAPI.prototype.calculateSpeed = function (p, event, returnType, timeType) {
393
+ var race = event.races.find(function (race) { return race.race_id === p.race_id; });
394
+ var time = timeType === 'netto' ? p.finishtime_fromchip_ms : p.finishtime_fromgun_ms;
395
+ if (!race || !time)
396
+ return '-';
397
+ var distance = race.distance * (p.laps_count || 1);
398
+ // calculate speed in km/h
399
+ if (returnType === 'speed') {
400
+ // Convert time from milliseconds to hours
401
+ var timeHours = time / (1000 * 60 * 60);
402
+ // Convert distance from meters to kilometers
403
+ var distanceKm = distance / 1000;
404
+ // Calculate speed in km/h
405
+ return (distanceKm / timeHours).toFixed(2).replace('.00', '').replace('.', ',');
406
+ }
407
+ if (returnType === 'pace') {
408
+ // Calculate pace in seconds per km
409
+ var paceSecondsPerKm = (time / 1000) / (distance / 1000);
410
+ var paceMinutes = Math.floor(paceSecondsPerKm / 60);
411
+ var paceSeconds = Math.round(paceSecondsPerKm % 60);
412
+ // Format pace as mm:ss/km
413
+ return "".concat(String(paceMinutes).padStart(2, '0'), ":").concat(String(paceSeconds).padStart(2, '0'));
414
+ }
415
+ return '-';
416
+ };
388
417
  return Time2WinAPI;
389
418
  }());
390
419
  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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@time2win/t2w",
3
- "version": "1.4.19",
3
+ "version": "1.4.21",
4
4
  "description": "providing latest-state models and advanced methods to interact with the T2W API",
5
5
  "keywords": [
6
6
  "time2win",
package/test.js CHANGED
@@ -5,8 +5,6 @@ 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.getEventData(550, ['prices', 'splits', 'categories', 'attributes']).then(function (res) {
9
- // console.log('SUCCESS', res);
10
- }).catch(function (err) {
11
- console.log('ERROR', err);
8
+ api.getIndividualResults(38, 161).then(function (res) {
9
+ console.log(res.list[0]);
12
10
  });