incyclist-services 1.3.40 → 1.3.42

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.
@@ -74,10 +74,14 @@ let AvatarService = (() => {
74
74
  }
75
75
  deleteAll() {
76
76
  const currentAvatar = this.registered.current;
77
- this.options.forEach(o => { o.usageCnt = 0; });
77
+ this.options.forEach(o => {
78
+ if (o)
79
+ o.usageCnt = 0;
80
+ });
78
81
  this.currentBucket = 0;
79
82
  const currentOption = this.find(currentAvatar);
80
- currentOption.usageCnt = 1;
83
+ if (currentOption)
84
+ currentOption.usageCnt = 1;
81
85
  this.registered = { current: currentAvatar };
82
86
  }
83
87
  buildOptions() {
@@ -93,17 +97,20 @@ let AvatarService = (() => {
93
97
  });
94
98
  }
95
99
  getNextAvailable() {
96
- let available = this.options.find(a => a.usageCnt === this.currentBucket);
100
+ let available = this.options.find(a => (a === null || a === void 0 ? void 0 : a.usageCnt) === this.currentBucket);
97
101
  if (!available) {
98
102
  this.currentBucket++;
99
103
  const currentOption = this.find('current');
100
- currentOption.usageCnt++;
101
- available = this.options.find(a => a.usageCnt === this.currentBucket);
104
+ if (currentOption)
105
+ currentOption.usageCnt++;
106
+ available = this.options.find(a => (a === null || a === void 0 ? void 0 : a.usageCnt) === this.currentBucket);
102
107
  }
103
- available.usageCnt++;
108
+ if (available)
109
+ available.usageCnt++;
104
110
  return available === null || available === void 0 ? void 0 : available.avatar;
105
111
  }
106
112
  cleanup(id, isCurrent = false) {
113
+ var _a;
107
114
  if (this.registered[id]) {
108
115
  const prev = this.find(this.registered[id]);
109
116
  if (prev) {
@@ -115,8 +122,8 @@ let AvatarService = (() => {
115
122
  delete this.registered[id];
116
123
  }
117
124
  const currentAvatar = this.registered.current;
118
- const inUse = this.options.filter(a => !currentAvatar || (a.avatar.helmet !== currentAvatar.helmet && a.avatar.shirt !== currentAvatar.shirt)).sort((a, b) => b.usageCnt - a.usageCnt);
119
- this.currentBucket = inUse[0].usageCnt;
125
+ const inUse = this.options.filter(a => !currentAvatar || (a.avatar.helmet !== currentAvatar.helmet && a.avatar.shirt !== currentAvatar.shirt)).sort((a, b) => (b === null || b === void 0 ? void 0 : b.usageCnt) - (a === null || a === void 0 ? void 0 : a.usageCnt));
126
+ this.currentBucket = (_a = inUse[0]) === null || _a === void 0 ? void 0 : _a.usageCnt;
120
127
  }
121
128
  find(avatar) {
122
129
  return this.options.find(a => a.avatar.helmet === avatar.helmet && a.avatar.shirt === avatar.shirt);
@@ -3,7 +3,8 @@ import { RouteApiDetail } from "../api/types";
3
3
  import { Route } from "../model/route";
4
4
  import { RoutePoint, RouteSegment } from "../types";
5
5
  export declare const checkIsLoop: (_route: Route | Array<RoutePoint>) => boolean;
6
- export declare const updateSlopes: (points: Array<RoutePoint>) => void;
6
+ export declare const validateSlopes: (points: Array<RoutePoint>) => void;
7
+ export declare const updateSlopes: (points: Array<RoutePoint>, validateOnly?: boolean) => void;
7
8
  export declare const getSegments: (route: Route) => Array<RouteSegment>;
8
9
  export declare const addDetails: (route: Route, details: RouteApiDetail) => void;
9
10
  export declare const validateRoute: (route: Route | RouteApiDetail) => void;
@@ -33,5 +34,5 @@ export declare const getPosition: (route: Route, props: GetPositionProps) => Rou
33
34
  interface LegacyRouteApiDetail extends RouteApiDetail {
34
35
  decoded?: Array<RoutePoint>;
35
36
  }
36
- export declare const createFromJson: (data: LegacyRouteApiDetail) => Route;
37
+ export declare const createFromJson: (r: LegacyRouteApiDetail) => Route;
37
38
  export {};
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createFromJson = exports.getPosition = exports.getNextPosition = exports.getRouteHash = exports.getTotalDistance = exports.updateElevationGain = exports.getElevationGainAt = exports.getTotalElevation = exports.validateDistance = exports.validateRoute = exports.addDetails = exports.getSegments = exports.updateSlopes = exports.checkIsLoop = void 0;
6
+ exports.createFromJson = exports.getPosition = exports.getNextPosition = exports.getRouteHash = exports.getTotalDistance = exports.updateElevationGain = exports.getElevationGainAt = exports.getTotalElevation = exports.validateDistance = exports.validateRoute = exports.addDetails = exports.getSegments = exports.updateSlopes = exports.validateSlopes = exports.checkIsLoop = void 0;
7
7
  const utils_1 = require("../../../utils");
8
+ const clone_1 = __importDefault(require("../../../utils/clone"));
8
9
  const geo_1 = require("../../../utils/geo");
9
10
  const valid_1 = require("../../../utils/valid");
10
11
  const route_1 = require("../model/route");
@@ -41,10 +42,37 @@ const checkIsLoop = (_route) => {
41
42
  return (dist <= maxDistance);
42
43
  };
43
44
  exports.checkIsLoop = checkIsLoop;
44
- const updateSlopes = (points) => {
45
+ const validateSlopes = (points) => {
46
+ (0, exports.updateSlopes)(points, true);
47
+ };
48
+ exports.validateSlopes = validateSlopes;
49
+ const updateSlopes = (points, validateOnly = false) => {
45
50
  let prevPoint = null;
51
+ if (!validateOnly) {
52
+ const lapMode = (0, exports.checkIsLoop)(points);
53
+ if (lapMode) {
54
+ const distance = utils_1.geo.distanceBetween(points[0], points[points.length - 1]);
55
+ let elevationShift;
56
+ if (distance === 0) {
57
+ elevationShift = points[0].elevation - points[points.length - 1].elevation;
58
+ }
59
+ else {
60
+ const distanceLast = utils_1.geo.distanceBetween(points[points.length - 2], points[points.length - 1]);
61
+ const slopeLast = (points[points.length - 1].elevation - points[points.length - 2].elevation) / distanceLast * 100;
62
+ const elevationLast = points[0].elevation - slopeLast * distance / 100;
63
+ elevationShift = points[0].elevation - elevationLast;
64
+ }
65
+ (0, exports.validateDistance)(points);
66
+ const totalDistance = points[points.length - 1].routeDistance;
67
+ points.forEach((point) => {
68
+ point.elevation += elevationShift * (point.routeDistance / totalDistance);
69
+ });
70
+ }
71
+ }
46
72
  points.forEach((point) => {
47
73
  const i = point.cnt;
74
+ if (validateOnly && point.slope !== undefined)
75
+ return;
48
76
  if (i > 0) {
49
77
  updateSlopePrevPoint(point, prevPoint, points);
50
78
  }
@@ -156,7 +184,7 @@ const validateRoute = (route) => {
156
184
  if (!((_a = route === null || route === void 0 ? void 0 : route.points) === null || _a === void 0 ? void 0 : _a.length))
157
185
  return;
158
186
  (0, exports.validateDistance)(route.points);
159
- (0, exports.updateSlopes)(route.points);
187
+ (0, exports.validateSlopes)(route.points);
160
188
  (0, exports.updateElevationGain)(route.points);
161
189
  route.distance = route.points[route.points.length - 1].routeDistance;
162
190
  };
@@ -453,7 +481,8 @@ const buildRouteInfo = (descr) => {
453
481
  }
454
482
  return data;
455
483
  };
456
- const createFromJson = (data) => {
484
+ const createFromJson = (r) => {
485
+ const data = (0, clone_1.default)(r);
457
486
  if (data.decoded) {
458
487
  data.points = data.decoded;
459
488
  delete data.decoded;
@@ -213,6 +213,7 @@ class RouteCard extends base_1.BaseCard {
213
213
  const markers = [];
214
214
  try {
215
215
  const startSettings = settings || this.getSettings();
216
+ this.adjustStartPosAvi(startSettings);
216
217
  const startDistance = startSettings.startPos || 0;
217
218
  const startPos = (0, route_1.getPosition)(this.route, { distance: startDistance, nearest: true });
218
219
  markers.push(startPos);
@@ -263,7 +263,7 @@ let RoutesDbLoader = (() => {
263
263
  details.localizedTitle = { en: details.localizedTitle };
264
264
  }
265
265
  (0, route_1.validateDistance)(details.points);
266
- (0, route_1.updateSlopes)(details.points);
266
+ (0, route_1.validateSlopes)(details.points);
267
267
  }
268
268
  validateDescription(description, details) {
269
269
  if (!description.elevation) {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.3.40",
3
+ "version": "1.3.42",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },
7
7
  "devDependencies": {
8
8
  "@types/jest": "^29.5.14",
9
9
  "@types/node": "^22.9.0",
10
- "@typescript-eslint/eslint-plugin": "^8.13.0",
11
- "@typescript-eslint/parser": "^8.13.0",
10
+ "@typescript-eslint/eslint-plugin": "^8.14.0",
11
+ "@typescript-eslint/parser": "^8.15.0",
12
12
  "dotenv": "^16.4.5",
13
- "eslint": "^9.14.0",
13
+ "eslint": "^9.15.0",
14
14
  "formdata-node": "^6.0.3",
15
15
  "jest": "^29.7.0",
16
16
  "jsdoc": "^4.0.4",