@time2win/t2w 1.4.18 → 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 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.20 - 2025-03-13
9
+ ### Added
10
+ ```paceBrutto``` ```paceNetto``` ```speedBrutto``` ```speedNetto``` properties for individual result
11
+
12
+ ## 1.4.19 - 2025-02-25
13
+ ### Added
14
+ ```age``` property for participant info
15
+
8
16
  ## 1.4.18 - 2025-02-14
9
17
  ### Added
10
18
  ```agecategories``` and ```attributes``` properties to ```T2WEvent```
package/index.d.ts CHANGED
@@ -9,9 +9,13 @@ export default class Time2WinAPI {
9
9
  getTeamsWithMembers(eventId: number, raceId?: number, dataExtra?: ('teammembers' | 'attributes')[], page?: number): Promise<T2WTeamResponse>;
10
10
  getIndividualResults(eventId: number, raceId: number, dataExtra?: ('splits' | 'laps' | 'positions' | 'attributes')[], gender?: 'M' | 'F' | 'U', page?: number): Promise<T2WIndividualResultResponse>;
11
11
  getParticipantInfos(eventId: number, raceId?: number, dataExtra?: ('order' | 'attributes' | 'categories' | 'uci_id' | 'chip_code' | 'externalticket' | 'contactinfo')[], gender?: 'M' | 'F' | 'U', page?: number): Promise<T2WParticipantResponse>;
12
+ /**
13
+ * if no params are given, the events in the next seven days are returned
14
+ * */
12
15
  getUpcomingEvents(from?: Date, to?: Date, page?: number): Promise<T2WEventResponse>;
13
16
  private getUrl;
14
17
  private calculateAge;
15
18
  private formatDate;
16
19
  private getNumericBib;
20
+ private calculateSpeed;
17
21
  }
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
- if (!(body.page < body.page_total)) return [3 /*break*/, 3];
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 2:
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 = 3;
230
- case 3:
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*/];
@@ -246,60 +249,67 @@ var Time2WinAPI = /** @class */ (function () {
246
249
  return __awaiter(this, void 0, void 0, function () {
247
250
  var _this = this;
248
251
  return __generator(this, function (_a) {
249
- return [2 /*return*/, new Promise(function (resolve, reject) {
250
- var queryParams = {
251
- 'race_id': raceId || '',
252
- 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
253
- gender: gender || '',
254
- page: page,
255
- 'page_size': _this.pageSize
256
- };
257
- fetch(_this.getUrl("/participants/".concat(eventId, "/individuals"), queryParams))
258
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
259
- var body, _a, _b, _c;
260
- var _d;
261
- var _this = this;
262
- return __generator(this, function (_e) {
263
- switch (_e.label) {
264
- case 0: return [4 /*yield*/, response.json()];
265
- case 1:
266
- body = _e.sent();
267
- if (response.status === 403) {
268
- reject(body);
269
- return [2 /*return*/];
270
- }
271
- if (!raceId) {
272
- // const race = (await this.getEventData(eventId)).races.find(r => r.race_id === raceId);
273
- }
274
- if (!body.page_more) return [3 /*break*/, 3];
275
- _b = (_a = (_d = body.list).push).apply;
276
- _c = [_d];
277
- return [4 /*yield*/, this.getParticipantInfos(eventId, raceId, dataExtra, gender, body.page + 1)];
278
- case 2:
279
- _b.apply(_a, _c.concat([(_e.sent()).list]));
280
- body.page_more = false;
281
- body.page = Math.ceil(body.list.length / body.page_size);
282
- resolve(body);
283
- _e.label = 3;
284
- case 3:
285
- body.list = body.list.map(function (p) {
286
- return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null,
287
- // age: p.birthdate && race ? this.calculateAge(new Date(p.birthdate), race.starttime) : null,
288
- year: p.birthdate ? new Date(p.birthdate).getFullYear() : null, order_date: p.order_date ? new Date(p.order_date) : null, racenumNumeric: _this.getNumericBib(p.racenum) });
252
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
253
+ var queryParams, races;
254
+ var _this = this;
255
+ return __generator(this, function (_a) {
256
+ switch (_a.label) {
257
+ case 0:
258
+ queryParams = {
259
+ 'race_id': raceId || '',
260
+ 'data_extra': (dataExtra === null || dataExtra === void 0 ? void 0 : dataExtra.join(',')) || '',
261
+ gender: gender || '',
262
+ page: page,
263
+ 'page_size': this.pageSize
264
+ };
265
+ return [4 /*yield*/, this.getEventData(eventId)];
266
+ case 1:
267
+ races = (_a.sent()).races;
268
+ fetch(this.getUrl("/participants/".concat(eventId, "/individuals"), queryParams))
269
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
270
+ var body, _a, _b, _c;
271
+ var _d;
272
+ var _this = this;
273
+ return __generator(this, function (_e) {
274
+ switch (_e.label) {
275
+ case 0: return [4 /*yield*/, response.json()];
276
+ case 1:
277
+ body = _e.sent();
278
+ if (response.status === 403) {
279
+ reject(body);
280
+ return [2 /*return*/];
281
+ }
282
+ if (!body.page_more) return [3 /*break*/, 3];
283
+ _b = (_a = (_d = body.list).push).apply;
284
+ _c = [_d];
285
+ return [4 /*yield*/, this.getParticipantInfos(eventId, raceId, dataExtra, gender, body.page + 1)];
286
+ case 2:
287
+ _b.apply(_a, _c.concat([(_e.sent()).list]));
288
+ body.page_more = false;
289
+ body.page = Math.ceil(body.list.length / body.page_size);
290
+ resolve(body);
291
+ _e.label = 3;
292
+ case 3:
293
+ body.list = body.list.map(function (p) {
294
+ var race = races.find(function (r) { return r.race_id === p.race_id; });
295
+ return __assign(__assign({}, p), { birthdate: p.birthdate ? new Date(p.birthdate) : null, age: p.birthdate && race ? _this.calculateAge(new Date(p.birthdate), race.starttime) : null, year: p.birthdate ? new Date(p.birthdate).getFullYear() : null, order_date: p.order_date ? new Date(p.order_date) : null, racenumNumeric: _this.getNumericBib(p.racenum) });
296
+ });
297
+ resolve(body);
298
+ return [2 /*return*/];
299
+ }
289
300
  });
290
- resolve(body);
291
- return [2 /*return*/];
292
- }
293
- });
294
- }); })
295
- .catch(function (reason) { return reject(reason); });
296
- })];
301
+ }); })
302
+ .catch(function (reason) { return reject(reason); });
303
+ return [2 /*return*/];
304
+ }
305
+ });
306
+ }); })];
297
307
  });
298
308
  });
299
309
  };
300
- /*
301
- * if no params are given, the events in the next seven days are returned
302
- * */
310
+ /**
311
+ * if no params are given, the events in the next seven days are returned
312
+ * */
303
313
  Time2WinAPI.prototype.getUpcomingEvents = function (from, to, page) {
304
314
  if (from === void 0) { from = new Date(); }
305
315
  if (page === void 0) { page = 1; }
@@ -378,6 +388,30 @@ var Time2WinAPI = /** @class */ (function () {
378
388
  }
379
389
  return Number((bib.match(/[0-9]/g) || []).join(''));
380
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
+ };
381
415
  return Time2WinAPI;
382
416
  }());
383
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@time2win/t2w",
3
- "version": "1.4.18",
3
+ "version": "1.4.20",
4
4
  "description": "providing latest-state models and advanced methods to interact with the T2W API",
5
5
  "keywords": [
6
6
  "time2win",
@@ -18,11 +18,9 @@
18
18
  },
19
19
  "author": "Jonas Dorfinger",
20
20
  "license": "MIT",
21
- "dependencies": {
22
- },
23
21
  "devDependencies": {
24
22
  "@types/node": "^16.10.1",
25
- "nodemon": "^2.0.22",
23
+ "nodemon": "^3.1.9",
26
24
  "ts-node": "^10.2.1",
27
25
  "typescript": "^4.4.3"
28
26
  }
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.getEventData(550, ['prices', 'splits', 'categories', 'attributes']).then(function (res) {
9
- // console.log('SUCCESS', res);
10
- }).catch(function (err) {
11
- console.log('ERROR', err);
12
- });
8
+ api.getIndividualResults(38, 161).then(console.log);