incyclist-services 1.3.8 → 1.3.10
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.
|
@@ -6,6 +6,7 @@ type RemainingTimeProps = {
|
|
|
6
6
|
routePos: number;
|
|
7
7
|
power?: number;
|
|
8
8
|
speed?: number;
|
|
9
|
+
endPos?: number;
|
|
9
10
|
};
|
|
10
11
|
type RemainingTimeCache = {
|
|
11
12
|
remaining: RemainingInfo;
|
|
@@ -24,6 +25,6 @@ export declare class ActivityDuration {
|
|
|
24
25
|
protected cache: RemainingTimeCache;
|
|
25
26
|
constructor(activity: ActivityDetails);
|
|
26
27
|
getRemainingTime(props: RemainingTimeProps): number;
|
|
27
|
-
protected calculateRemainingTime(route: Route, routePos: number, power: number, m: number, v?: number, realityFactor?: number): Array<RemainingInfo>;
|
|
28
|
+
protected calculateRemainingTime(route: Route, routePos: number, power: number, m: number, v?: number, realityFactor?: number, endPos?: number): Array<RemainingInfo>;
|
|
28
29
|
}
|
|
29
30
|
export {};
|
|
@@ -24,7 +24,7 @@ class ActivityDuration {
|
|
|
24
24
|
getRemainingTime(props) {
|
|
25
25
|
var _a, _b;
|
|
26
26
|
try {
|
|
27
|
-
const { route, routePos, power, speed = 0 } = props || {};
|
|
27
|
+
const { route, routePos, power, speed = 0, endPos } = props || {};
|
|
28
28
|
const { stats, time = 0, user } = this.activity;
|
|
29
29
|
const calcPower = ((_a = stats === null || stats === void 0 ? void 0 : stats.power) === null || _a === void 0 ? void 0 : _a.avg) || power;
|
|
30
30
|
const m = (user.weight || 75) + 10;
|
|
@@ -43,7 +43,7 @@ class ActivityDuration {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
const tsStart = Date.now();
|
|
46
|
-
const res = this.calculateRemainingTime(route, routePos, calcPower, m, v, realityFactor);
|
|
46
|
+
const res = this.calculateRemainingTime(route, routePos, calcPower, m, v, realityFactor, endPos);
|
|
47
47
|
if (!res || !Array.isArray(res) || res.length === 0) {
|
|
48
48
|
return undefined;
|
|
49
49
|
}
|
|
@@ -56,13 +56,13 @@ class ActivityDuration {
|
|
|
56
56
|
return undefined;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
calculateRemainingTime(route, routePos, power, m, v = 0, realityFactor = 1) {
|
|
59
|
+
calculateRemainingTime(route, routePos, power, m, v = 0, realityFactor = 1, endPos) {
|
|
60
60
|
if (!route)
|
|
61
61
|
return;
|
|
62
62
|
const gpxData = route.points;
|
|
63
63
|
const isLap = (0, route_1.checkIsLoop)(route);
|
|
64
64
|
const lapDistance = isLap ? routePos % route.distance : routePos;
|
|
65
|
-
const totalDistance = route.distance;
|
|
65
|
+
const totalDistance = endPos !== undefined ? endPos : route.distance;
|
|
66
66
|
const fromStart = [];
|
|
67
67
|
let vPrev = v;
|
|
68
68
|
let timeSinceStart = 0;
|
|
@@ -95,6 +95,8 @@ class ActivityDuration {
|
|
|
95
95
|
try {
|
|
96
96
|
if (p.routeDistance < startDistance && (i === gpxData.length - 1 || gpxData[i + 1].routeDistance < startDistance))
|
|
97
97
|
return;
|
|
98
|
+
if (endPos !== undefined && p.routeDistance > endPos)
|
|
99
|
+
return;
|
|
98
100
|
const segmentEnd = i === gpxData.length - 1 ? totalDistance : gpxData[i + 1].routeDistance;
|
|
99
101
|
const segmentLength = segmentEnd - segmentStart;
|
|
100
102
|
const slope = (p.slope || 0) * (realityFactor || 0);
|
|
@@ -36,6 +36,7 @@ export declare class ActivityRideService extends IncyclistService {
|
|
|
36
36
|
route?: Route;
|
|
37
37
|
position?: RoutePoint;
|
|
38
38
|
deviceData: DeviceData;
|
|
39
|
+
endPos?: number;
|
|
39
40
|
tsDeviceData?: number;
|
|
40
41
|
tsUpdate?: number;
|
|
41
42
|
routeDistance?: number;
|
|
@@ -52,6 +53,7 @@ export declare class ActivityRideService extends IncyclistService {
|
|
|
52
53
|
stop(): void;
|
|
53
54
|
pause(autoResume?: boolean): void;
|
|
54
55
|
resume(requester?: 'user' | 'system'): void;
|
|
56
|
+
ignoreEndPos(): void;
|
|
55
57
|
getDashboardDisplayProperties(): any[];
|
|
56
58
|
getActivitySummaryDisplayProperties(): {};
|
|
57
59
|
getActivity(): ActivityDetails;
|
|
@@ -162,6 +162,9 @@ let ActivityRideService = (() => {
|
|
|
162
162
|
this._save();
|
|
163
163
|
this.isSaveDone = false;
|
|
164
164
|
}
|
|
165
|
+
ignoreEndPos() {
|
|
166
|
+
delete this.current.endPos;
|
|
167
|
+
}
|
|
165
168
|
getDashboardDisplayProperties() {
|
|
166
169
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
167
170
|
try {
|
|
@@ -178,7 +181,7 @@ let ActivityRideService = (() => {
|
|
|
178
181
|
distanceRemaining = undefined;
|
|
179
182
|
if (distanceRemaining < 0)
|
|
180
183
|
distanceRemaining = 0;
|
|
181
|
-
const timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData.speed, routePos: this.activity.distance + ((_j = this.activity.startPos) !== null && _j !== void 0 ? _j : 0) });
|
|
184
|
+
const timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData.speed, routePos: this.activity.distance + ((_j = this.activity.startPos) !== null && _j !== void 0 ? _j : 0), endPos: this.current.endPos });
|
|
182
185
|
let speedDetails, powerDetails, elevationGain, heartrateDetails, cadenceDetails;
|
|
183
186
|
const stats = (_k = this.activity) === null || _k === void 0 ? void 0 : _k.stats;
|
|
184
187
|
if (display === 0) {
|
|
@@ -267,14 +270,12 @@ let ActivityRideService = (() => {
|
|
|
267
270
|
});
|
|
268
271
|
}
|
|
269
272
|
save() {
|
|
270
|
-
console.log('~~~ ActivityRide.save', this.saveObserver !== undefined, this.isSaveDone);
|
|
271
273
|
if (this.saveObserver) {
|
|
272
274
|
return this.saveObserver;
|
|
273
275
|
}
|
|
274
276
|
const emit = (event, ...args) => {
|
|
275
277
|
if (this.saveObserver)
|
|
276
278
|
this.saveObserver.emit(event, ...args);
|
|
277
|
-
console.log('~~~ ActivityRide.emit', event, args, this.saveObserver !== undefined, this.isSaveDone);
|
|
278
279
|
};
|
|
279
280
|
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
280
281
|
let success = false;
|
|
@@ -309,7 +310,6 @@ let ActivityRideService = (() => {
|
|
|
309
310
|
return success;
|
|
310
311
|
});
|
|
311
312
|
this.saveObserver = new observer_1.PromiseObserver(run());
|
|
312
|
-
console.log('~~~ ActivityRide.save returns', this.saveObserver !== undefined, this.isSaveDone);
|
|
313
313
|
return this.saveObserver;
|
|
314
314
|
}
|
|
315
315
|
getObserver() {
|
|
@@ -529,6 +529,7 @@ let ActivityRideService = (() => {
|
|
|
529
529
|
(0, route_1.validateRoute)(selectedRoute);
|
|
530
530
|
const s = startSettings;
|
|
531
531
|
startPos = s.startPos;
|
|
532
|
+
this.current.endPos = s.endPos;
|
|
532
533
|
realityFactor = s.realityFactor;
|
|
533
534
|
routeId = selectedRoute.description.id;
|
|
534
535
|
routeHash = selectedRoute.description.routeHash;
|
|
@@ -611,8 +612,8 @@ let ActivityRideService = (() => {
|
|
|
611
612
|
const route = this.current.route;
|
|
612
613
|
if (!route)
|
|
613
614
|
return 0;
|
|
614
|
-
const totalRouteDistance = (_a = route.points[route.points.length - 1]) === null || _a === void 0 ? void 0 : _a.routeDistance;
|
|
615
615
|
const isLoop = (0, route_1.checkIsLoop)(route);
|
|
616
|
+
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;
|
|
616
617
|
if (isLoop) {
|
|
617
618
|
const currentLap = Math.floor(((_b = this.current.routeDistance) !== null && _b !== void 0 ? _b : 0) / totalRouteDistance);
|
|
618
619
|
return totalRouteDistance - ((_c = this.activity.startPos) !== null && _c !== void 0 ? _c : 0) + currentLap * totalRouteDistance;
|
|
@@ -626,10 +627,16 @@ let ActivityRideService = (() => {
|
|
|
626
627
|
const route = this.current.route;
|
|
627
628
|
if (!route)
|
|
628
629
|
return 0;
|
|
629
|
-
const totalElevation = (_a = route.points[route.points.length - 1]) === null || _a === void 0 ? void 0 : _a.elevationGain;
|
|
630
|
-
const totalRouteDistance = (_b = route.points[route.points.length - 1]) === null || _b === void 0 ? void 0 : _b.routeDistance;
|
|
631
|
-
const gainAtStart = (0, route_1.getElevationGainAt)(route, (_c = this.activity.startPos) !== null && _c !== void 0 ? _c : 0);
|
|
632
630
|
const isLoop = (0, route_1.checkIsLoop)(route);
|
|
631
|
+
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;
|
|
632
|
+
let totalElevation = (_b = route.points[route.points.length - 1]) === null || _b === void 0 ? void 0 : _b.elevationGain;
|
|
633
|
+
if (this.current.endPos !== undefined && !isLoop) {
|
|
634
|
+
const endPosPoint = route.points.find(p => p.routeDistance >= this.current.endPos);
|
|
635
|
+
if (endPosPoint) {
|
|
636
|
+
totalElevation = endPosPoint.elevationGain;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
const gainAtStart = (0, route_1.getElevationGainAt)(route, (_c = this.activity.startPos) !== null && _c !== void 0 ? _c : 0);
|
|
633
640
|
if (isLoop) {
|
|
634
641
|
const currentLap = Math.floor(((_d = this.current.routeDistance) !== null && _d !== void 0 ? _d : 0) / totalRouteDistance);
|
|
635
642
|
return totalElevation - gainAtStart + currentLap * totalElevation;
|
|
@@ -210,7 +210,7 @@ let StravaUpload = (() => {
|
|
|
210
210
|
}
|
|
211
211
|
this.getUserSettings().set('user.auth.strava', {
|
|
212
212
|
accesstoken: this.config.accessToken,
|
|
213
|
-
|
|
213
|
+
refreshtoken: this.config.refreshToken,
|
|
214
214
|
expiration: this.config.expiration.toISOString()
|
|
215
215
|
});
|
|
216
216
|
}
|