incyclist-services 1.4.23 → 1.4.24

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.
@@ -847,37 +847,37 @@ let ActivityRideService = (() => {
847
847
  this.current.tsUpdate = tsNow;
848
848
  }
849
849
  getTotalDistance() {
850
- var _a, _b, _c, _d;
850
+ var _a, _b, _c, _d, _e, _f;
851
851
  const route = this.current.route;
852
852
  if (!route)
853
853
  return 0;
854
854
  const isLoop = (0, route_1.checkIsLoop)(route);
855
- const totalRouteDistance = this.current.endPos !== undefined && !isLoop ? this.current.endPos : (_a = route.points[route.points.length - 1]) === null || _a === void 0 ? void 0 : _a.routeDistance;
855
+ const totalRouteDistance = (_b = (_a = this.current) === null || _a === void 0 ? void 0 : _a.endPos) !== null && _b !== void 0 ? _b : (_c = route.points[route.points.length - 1]) === null || _c === void 0 ? void 0 : _c.routeDistance;
856
856
  if (isLoop) {
857
- const currentLap = Math.floor(((_b = this.current.routeDistance) !== null && _b !== void 0 ? _b : 0) / totalRouteDistance);
858
- return totalRouteDistance - ((_c = this.activity.startPos) !== null && _c !== void 0 ? _c : 0) + currentLap * totalRouteDistance;
857
+ const currentLap = Math.floor(((_d = this.current.routeDistance) !== null && _d !== void 0 ? _d : 0) / totalRouteDistance);
858
+ return totalRouteDistance - ((_e = this.activity.startPos) !== null && _e !== void 0 ? _e : 0) + currentLap * totalRouteDistance;
859
859
  }
860
860
  else {
861
- return totalRouteDistance - ((_d = this.activity.startPos) !== null && _d !== void 0 ? _d : 0);
861
+ return totalRouteDistance - ((_f = this.activity.startPos) !== null && _f !== void 0 ? _f : 0);
862
862
  }
863
863
  }
864
864
  getTotalElevation() {
865
- var _a, _b, _c, _d;
865
+ var _a, _b, _c, _d, _e, _f, _g;
866
866
  const route = this.current.route;
867
867
  if (!route)
868
868
  return 0;
869
869
  const isLoop = (0, route_1.checkIsLoop)(route);
870
- const totalRouteDistance = this.current.endPos !== undefined && !isLoop ? this.current.endPos : (_a = route.points[route.points.length - 1]) === null || _a === void 0 ? void 0 : _a.routeDistance;
871
- let totalElevation = (_b = route.points[route.points.length - 1]) === null || _b === void 0 ? void 0 : _b.elevationGain;
872
- if (this.current.endPos !== undefined && !isLoop) {
870
+ const totalRouteDistance = (_b = (_a = this.current) === null || _a === void 0 ? void 0 : _a.endPos) !== null && _b !== void 0 ? _b : (_c = route.points[route.points.length - 1]) === null || _c === void 0 ? void 0 : _c.routeDistance;
871
+ let totalElevation = (_d = route.points[route.points.length - 1]) === null || _d === void 0 ? void 0 : _d.elevationGain;
872
+ if (((_e = this.current) === null || _e === void 0 ? void 0 : _e.endPos) !== undefined) {
873
873
  const endPosPoint = route.points.find(p => p.routeDistance >= this.current.endPos);
874
874
  if (endPosPoint) {
875
875
  totalElevation = endPosPoint.elevationGain;
876
876
  }
877
877
  }
878
- const gainAtStart = (0, route_1.getElevationGainAt)(route, (_c = this.activity.startPos) !== null && _c !== void 0 ? _c : 0);
878
+ const gainAtStart = (0, route_1.getElevationGainAt)(route, (_f = this.activity.startPos) !== null && _f !== void 0 ? _f : 0);
879
879
  if (isLoop) {
880
- const currentLap = Math.floor(((_d = this.current.routeDistance) !== null && _d !== void 0 ? _d : 0) / totalRouteDistance);
880
+ const currentLap = Math.floor(((_g = this.current.routeDistance) !== null && _g !== void 0 ? _g : 0) / totalRouteDistance);
881
881
  return totalElevation - gainAtStart + currentLap * totalElevation;
882
882
  }
883
883
  else {
@@ -96,8 +96,9 @@ const getReferencedFileInfo = (info, referenced, scheme = 'file') => {
96
96
  };
97
97
  exports.getReferencedFileInfo = getReferencedFileInfo;
98
98
  const buildFromFile = (info, referenced, scheme = 'file') => {
99
+ var _a;
99
100
  if (referenced.file) {
100
- const fileName = info.filename.replace(info.name, referenced.file);
101
+ const fileName = (_a = info.filename) === null || _a === void 0 ? void 0 : _a.replace(info.name, referenced.file);
101
102
  return `file:///${fileName}`;
102
103
  }
103
104
  return referenced.url;
@@ -247,6 +247,8 @@ class XMLParser {
247
247
  prevTime = 0;
248
248
  }
249
249
  else {
250
+ if (mapping.frame == prev.frame || mapping.distance === prev.distance)
251
+ return;
250
252
  const time = addMapping(mapping, prev, idx, startFrame, prevTime);
251
253
  prevTime = time;
252
254
  }
@@ -275,6 +277,11 @@ class XMLParser {
275
277
  routeDistance: Number(a.distance),
276
278
  elevation: Number(a.height),
277
279
  }));
280
+ route.points = route.points.filter((p, idx) => {
281
+ if (idx === 0)
282
+ return true;
283
+ return (p.routeDistance !== route.points[idx - 1].routeDistance);
284
+ });
278
285
  const points = route.points;
279
286
  if ((points === null || points === void 0 ? void 0 : points.length) > 0) {
280
287
  route.distance = points[points.length - 1].routeDistance;
@@ -294,6 +301,13 @@ class XMLParser {
294
301
  route.elevation = 0;
295
302
  const points = [];
296
303
  positions.forEach((pos, i) => {
304
+ if (i > 0) {
305
+ const prev = positions[i - 1];
306
+ if (prev.distance === pos.distance) {
307
+ console.log('# found duplicate position');
308
+ return;
309
+ }
310
+ }
297
311
  const altitude = getAltitude(altitudes, positions, i, prevAltitude);
298
312
  const elevationGain = altitude - prevAltitude;
299
313
  const pi = createPoint(pos, altitude, prevDistance);
@@ -1050,7 +1050,9 @@ let RouteListService = (() => {
1050
1050
  }
1051
1051
  }
1052
1052
  resetCards() {
1053
- this.getLists().forEach(list => {
1053
+ var _a;
1054
+ const lists = (_a = this.getLists()) !== null && _a !== void 0 ? _a : [];
1055
+ lists.forEach(list => {
1054
1056
  list.getCards().forEach((card) => {
1055
1057
  card.reset(true);
1056
1058
  });
@@ -403,9 +403,9 @@ let WorkoutRide = (() => {
403
403
  const ftp = this.settings.ftp;
404
404
  const wo = this.workout;
405
405
  const limits = wo.getLimits(time, true);
406
- this.currentStep = limits.step;
407
- const request = { time: 0, duration: 0, remaining: 0 };
408
406
  if (limits !== undefined) {
407
+ this.currentStep = limits.step;
408
+ const request = { time: 0, duration: 0, remaining: 0 };
409
409
  request.time = Math.round(time);
410
410
  request.minPower = this.getPowerVal(limits.power, 'min');
411
411
  request.maxPower = this.getPowerVal(limits.power, 'max');
@@ -415,7 +415,7 @@ let WorkoutRide = (() => {
415
415
  request.maxHrm = ((_d = limits.hrm) === null || _d === void 0 ? void 0 : _d.max) ? Math.round(limits.hrm.max) : undefined;
416
416
  this.currentLimits = Object.assign(Object.assign({}, request), { duration: limits.duration, remaining: limits.remaining });
417
417
  }
418
- this.isFreeRide = limits.power === undefined || limits.power === null;
418
+ this.isFreeRide = (limits === null || limits === void 0 ? void 0 : limits.power) === undefined || (limits === null || limits === void 0 ? void 0 : limits.power) === null;
419
419
  this.logger.logEvent(Object.assign(Object.assign({ message: 'workout requests' }, this.currentLimits), { ftp }));
420
420
  this.emit('request-update', this.currentLimits);
421
421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.4.23",
3
+ "version": "1.4.24",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },