incyclist-services 1.3.18 → 1.3.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/lib/activities/base/model/index.d.ts +4 -0
- package/lib/activities/base/repo/db.d.ts +1 -0
- package/lib/activities/base/repo/db.js +14 -4
- package/lib/activities/base/repo/types.d.ts +3 -0
- package/lib/activities/base/utils/index.js +2 -2
- package/lib/activities/list/service.d.ts +2 -3
- package/lib/activities/list/service.js +27 -5
- package/lib/activities/ride/service.d.ts +1 -1
- package/lib/activities/ride/service.js +29 -8
- package/package.json +1 -1
|
@@ -60,6 +60,8 @@ export type ActivitySummary = {
|
|
|
60
60
|
rideTime: number;
|
|
61
61
|
distance: number;
|
|
62
62
|
startPos: number;
|
|
63
|
+
endPos?: number;
|
|
64
|
+
segment?: string;
|
|
63
65
|
realityFactor: number;
|
|
64
66
|
uploadStatus: Array<UploadInfo>;
|
|
65
67
|
isCompleted?: boolean;
|
|
@@ -133,6 +135,8 @@ export interface ActivityDetails {
|
|
|
133
135
|
timePause: number;
|
|
134
136
|
distance: number;
|
|
135
137
|
startPos: number;
|
|
138
|
+
endPos?: number;
|
|
139
|
+
segment?: string;
|
|
136
140
|
startpos?: number;
|
|
137
141
|
endpos?: number;
|
|
138
142
|
totalElevation: number;
|
|
@@ -4,6 +4,7 @@ import { Observer, PromiseObserver } from "../../../base/types/observer";
|
|
|
4
4
|
import { ActivityDetails, ActivityInfo } from "../model";
|
|
5
5
|
import { ActivitySearchCriteria } from "./types";
|
|
6
6
|
export declare const DB_VERSION = "1";
|
|
7
|
+
export declare const DB_NAME = "db";
|
|
7
8
|
export declare class ActivitiesRepository {
|
|
8
9
|
protected repo: JsonRepository;
|
|
9
10
|
protected loadObserver: Observer;
|
|
@@ -47,7 +47,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
|
|
|
47
47
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.ActivitiesRepository = exports.DB_VERSION = void 0;
|
|
50
|
+
exports.ActivitiesRepository = exports.DB_NAME = exports.DB_VERSION = void 0;
|
|
51
51
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
52
52
|
const api_1 = require("../../../api");
|
|
53
53
|
const types_1 = require("../../../base/types");
|
|
@@ -55,6 +55,7 @@ const observer_1 = require("../../../base/types/observer");
|
|
|
55
55
|
const utils_1 = require("../../../utils");
|
|
56
56
|
const utils_2 = require("../utils");
|
|
57
57
|
exports.DB_VERSION = '1';
|
|
58
|
+
exports.DB_NAME = 'db';
|
|
58
59
|
let ActivitiesRepository = (() => {
|
|
59
60
|
let _classDecorators = [types_1.Singleton];
|
|
60
61
|
let _classDescriptor;
|
|
@@ -154,6 +155,9 @@ let ActivitiesRepository = (() => {
|
|
|
154
155
|
if ((result === null || result === void 0 ? void 0 : result.length) > 0 && (criteria === null || criteria === void 0 ? void 0 : criteria.startPos) !== undefined) {
|
|
155
156
|
result = result.filter(ai => ai.summary.startPos === criteria.startPos);
|
|
156
157
|
}
|
|
158
|
+
if ((result === null || result === void 0 ? void 0 : result.length) > 0 && (criteria === null || criteria === void 0 ? void 0 : criteria.endPos) !== undefined) {
|
|
159
|
+
result = result.filter(ai => ai.summary.endPos === criteria.endPos);
|
|
160
|
+
}
|
|
157
161
|
if ((result === null || result === void 0 ? void 0 : result.length) > 0 && (criteria === null || criteria === void 0 ? void 0 : criteria.realityFactor) !== undefined) {
|
|
158
162
|
result = result.filter(ai => { var _a; return ((_a = ai.summary.realityFactor) !== null && _a !== void 0 ? _a : 100) === criteria.realityFactor; });
|
|
159
163
|
}
|
|
@@ -180,6 +184,12 @@ let ActivitiesRepository = (() => {
|
|
|
180
184
|
});
|
|
181
185
|
}
|
|
182
186
|
}
|
|
187
|
+
if ((result === null || result === void 0 ? void 0 : result.length) > 0 && (criteria === null || criteria === void 0 ? void 0 : criteria.minTime) !== undefined) {
|
|
188
|
+
result = result.filter(ai => ai.summary.rideTime >= criteria.minTime);
|
|
189
|
+
}
|
|
190
|
+
if ((result === null || result === void 0 ? void 0 : result.length) > 0 && (criteria === null || criteria === void 0 ? void 0 : criteria.minDistance) !== undefined) {
|
|
191
|
+
result = result.filter(ai => ai.summary.distance >= criteria.minDistance);
|
|
192
|
+
}
|
|
183
193
|
return result;
|
|
184
194
|
}
|
|
185
195
|
writeRepo() {
|
|
@@ -194,7 +204,7 @@ let ActivitiesRepository = (() => {
|
|
|
194
204
|
isComplete,
|
|
195
205
|
activities: this.activities.map(ai => ai.summary)
|
|
196
206
|
};
|
|
197
|
-
yield this.getRepo().write(
|
|
207
|
+
yield this.getRepo().write(exports.DB_NAME, dbData);
|
|
198
208
|
}
|
|
199
209
|
catch (err) {
|
|
200
210
|
this.logger.logEvent({ message: 'could not safe repo', error: err.message });
|
|
@@ -235,7 +245,7 @@ let ActivitiesRepository = (() => {
|
|
|
235
245
|
}
|
|
236
246
|
loadSummaries() {
|
|
237
247
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
-
const dbData = yield this.getRepo().read(
|
|
248
|
+
const dbData = yield this.getRepo().read(exports.DB_NAME);
|
|
239
249
|
if (dbData) {
|
|
240
250
|
const { activities = [] } = dbData;
|
|
241
251
|
this.activities = activities.map(summary => ({ summary }));
|
|
@@ -267,7 +277,7 @@ let ActivitiesRepository = (() => {
|
|
|
267
277
|
}
|
|
268
278
|
listActivities() {
|
|
269
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
return this.getRepo().list([
|
|
280
|
+
return this.getRepo().list([exports.DB_NAME]);
|
|
271
281
|
});
|
|
272
282
|
}
|
|
273
283
|
fixMissingHash() {
|
|
@@ -3,7 +3,10 @@ export interface ActivitySearchCriteria {
|
|
|
3
3
|
routeId?: string;
|
|
4
4
|
routeHash?: string;
|
|
5
5
|
startPos?: number;
|
|
6
|
+
endPos?: number;
|
|
6
7
|
realityFactor?: number;
|
|
7
8
|
uploadStatus?: UploadInfo | Array<UploadInfo>;
|
|
8
9
|
isSaved?: boolean;
|
|
10
|
+
minTime?: number;
|
|
11
|
+
minDistance?: number;
|
|
9
12
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildSummary = void 0;
|
|
4
4
|
const buildSummary = (activity, proposedName) => {
|
|
5
5
|
var _a;
|
|
6
|
-
const { id, title, route, screenshots, startTime: startTimeUTC, time: rideTime, distance, startPos, realityFactor = 100, links, laps } = activity;
|
|
6
|
+
const { id, title, route, screenshots, startTime: startTimeUTC, time: rideTime, distance, startPos, endPos, segment, realityFactor = 100, links, laps } = activity;
|
|
7
7
|
const name = proposedName !== null && proposedName !== void 0 ? proposedName : activity.name;
|
|
8
8
|
const routeId = route === null || route === void 0 ? void 0 : route.id;
|
|
9
9
|
const routeHash = route === null || route === void 0 ? void 0 : route.hash;
|
|
@@ -18,7 +18,7 @@ const buildSummary = (activity, proposedName) => {
|
|
|
18
18
|
uploadStatus.push({ service: 'strava', status: 'success' });
|
|
19
19
|
}
|
|
20
20
|
return {
|
|
21
|
-
id, title, name, routeId, routeHash, previewImage, startTime, rideTime, distance, startPos, realityFactor, uploadStatus, laps
|
|
21
|
+
id, title, name, routeId, routeHash, previewImage, startTime, rideTime, distance, startPos, endPos, realityFactor, uploadStatus, laps
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
exports.buildSummary = buildSummary;
|
|
@@ -9,9 +9,8 @@ export declare class ActivityListService extends IncyclistService {
|
|
|
9
9
|
protected observer: Observer;
|
|
10
10
|
constructor();
|
|
11
11
|
preload(): PromiseObserver<void>;
|
|
12
|
-
getPastActivities(filter: ActivitySearchCriteria
|
|
13
|
-
|
|
14
|
-
}): Array<ActivityInfo>;
|
|
12
|
+
getPastActivities(filter: ActivitySearchCriteria): Array<ActivityInfo>;
|
|
13
|
+
getPastActivitiesWithDetails(filter: ActivitySearchCriteria): Promise<Array<ActivityInfo>>;
|
|
15
14
|
protected loadActivities(): Promise<void>;
|
|
16
15
|
protected getRepo(): ActivitiesRepository;
|
|
17
16
|
protected get activities(): Array<ActivityInfo>;
|
|
@@ -92,13 +92,35 @@ let ActivityListService = (() => {
|
|
|
92
92
|
}
|
|
93
93
|
return this.preloadObserver;
|
|
94
94
|
}
|
|
95
|
-
getPastActivities(filter
|
|
95
|
+
getPastActivities(filter) {
|
|
96
96
|
var _a;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
activities
|
|
97
|
+
try {
|
|
98
|
+
const activities = (_a = this.getRepo().search(filter)) !== null && _a !== void 0 ? _a : [];
|
|
99
|
+
return activities;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.logError(err, 'getPastActivities');
|
|
103
|
+
return [];
|
|
100
104
|
}
|
|
101
|
-
|
|
105
|
+
}
|
|
106
|
+
getPastActivitiesWithDetails(filter) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
var _a;
|
|
109
|
+
try {
|
|
110
|
+
const activities = (_a = this.getRepo().search(filter)) !== null && _a !== void 0 ? _a : [];
|
|
111
|
+
const promises = [];
|
|
112
|
+
activities.forEach(ai => {
|
|
113
|
+
promises.push(this.getRepo().getWithDetails(ai.summary.id));
|
|
114
|
+
});
|
|
115
|
+
yield Promise.allSettled(promises);
|
|
116
|
+
const res = activities.filter(a => a.details !== undefined && a.details !== null);
|
|
117
|
+
return res;
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
this.logError(err, 'getPastActivitiesWithDetails');
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
102
124
|
}
|
|
103
125
|
loadActivities() {
|
|
104
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -68,7 +68,7 @@ export declare class ActivityRideService extends IncyclistService {
|
|
|
68
68
|
getObserver(): Observer;
|
|
69
69
|
addSceenshot(screenshot: ScreenShotInfo): void;
|
|
70
70
|
onRouteUpdate(points: Array<RoutePoint>): void;
|
|
71
|
-
getPrevRideStats(
|
|
71
|
+
getPrevRideStats(current: ActivityLogRecord): PastActivityInfo;
|
|
72
72
|
getPrevRidesListDisplay(maxEntries?: number): Array<PrevRidesListDisplayProps>;
|
|
73
73
|
protected getPrevActivityLog(ai: ActivityInfo, current: ActivityLogRecord): PastActivityLogEntry | null;
|
|
74
74
|
protected getCurrentActivityLog(ai: ActivityInfo, current: ActivityLogRecord): PastActivityLogEntry | null;
|
|
@@ -137,9 +137,15 @@ let ActivityRideService = (() => {
|
|
|
137
137
|
this.emit('started');
|
|
138
138
|
}
|
|
139
139
|
stop() {
|
|
140
|
+
var _a;
|
|
140
141
|
this.stopWorker();
|
|
141
142
|
if (!this.observer)
|
|
142
143
|
return;
|
|
144
|
+
if (this.state === 'paused') {
|
|
145
|
+
const pauseDuration = (Date.now() - this.tsPauseStart) / 1000;
|
|
146
|
+
this.activity.timePause = ((_a = this.activity.timePause) !== null && _a !== void 0 ? _a : 0) + pauseDuration;
|
|
147
|
+
this.current.tsUpdate = Date.now();
|
|
148
|
+
}
|
|
143
149
|
(0, devices_1.useDeviceRide)().off('data', this.deviceDataHandler);
|
|
144
150
|
this.state = 'completed';
|
|
145
151
|
this.updateActivityTime();
|
|
@@ -351,8 +357,9 @@ let ActivityRideService = (() => {
|
|
|
351
357
|
this.current.route.details.distance = points[points.length - 1].routeDistance;
|
|
352
358
|
(0, route_1.addDetails)(this.current.route, this.current.route.details);
|
|
353
359
|
}
|
|
354
|
-
getPrevRideStats(
|
|
360
|
+
getPrevRideStats(current) {
|
|
355
361
|
var _a;
|
|
362
|
+
const activities = this.current.prevRides;
|
|
356
363
|
if (!(activities === null || activities === void 0 ? void 0 : activities.length))
|
|
357
364
|
return [];
|
|
358
365
|
const logs = (_a = activities.map(ai => { return this.getPrevActivityLog(ai, current); })) === null || _a === void 0 ? void 0 : _a.filter(a => a !== null);
|
|
@@ -361,7 +368,6 @@ let ActivityRideService = (() => {
|
|
|
361
368
|
logs.push(this.getCurrentActivityLog(activities[0], current));
|
|
362
369
|
const sorted = logs.sort((a, b) => b.distance - a.distance);
|
|
363
370
|
this.current.prevRidesLogs = sorted;
|
|
364
|
-
console.log('~~~ PREV RIDES', activities.map(a => `${a.summary.name}:${a.summary.startTime}`), sorted);
|
|
365
371
|
return sorted;
|
|
366
372
|
}
|
|
367
373
|
getPrevRidesListDisplay(maxEntries = 12) {
|
|
@@ -406,6 +412,14 @@ let ActivityRideService = (() => {
|
|
|
406
412
|
props.splice(currentIdx - 1, 1);
|
|
407
413
|
}
|
|
408
414
|
}
|
|
415
|
+
let logInfo = '';
|
|
416
|
+
try {
|
|
417
|
+
logInfo = `(${props.length}/${prevRides.length})`
|
|
418
|
+
+ props.map(pr => { var _a, _b; return `${pr.position}:${(_a = pr.avatar) === null || _a === void 0 ? void 0 : _a.shirt}-${(_b = pr.avatar) === null || _b === void 0 ? void 0 : _b.helmet}:${pr.title}:${pr.timeGap}:${pr.distanceGap}`; })
|
|
419
|
+
.join(',');
|
|
420
|
+
}
|
|
421
|
+
catch (_a) { }
|
|
422
|
+
this.logEvent({ message: 'PrevRides', prevRides: logInfo });
|
|
409
423
|
return props;
|
|
410
424
|
}
|
|
411
425
|
getPrevActivityLog(ai, current) {
|
|
@@ -534,13 +548,17 @@ let ActivityRideService = (() => {
|
|
|
534
548
|
if (!this.current || !((_a = this.activity) === null || _a === void 0 ? void 0 : _a.route))
|
|
535
549
|
return;
|
|
536
550
|
this.current.showPrev = settings.showPrev;
|
|
551
|
+
this.current.prevRides = undefined;
|
|
537
552
|
const { startPos, realityFactor } = settings;
|
|
538
553
|
const routeId = this.activity.route.id;
|
|
539
554
|
const routeHash = this.activity.route.hash;
|
|
540
|
-
const filter = { routeId, routeHash, startPos, realityFactor };
|
|
541
|
-
|
|
542
|
-
.filter
|
|
543
|
-
|
|
555
|
+
const filter = { routeId, routeHash, startPos, realityFactor, minTime: 60, minDistance: 500 };
|
|
556
|
+
(0, list_1.useActivityList)()
|
|
557
|
+
.getPastActivitiesWithDetails(filter)
|
|
558
|
+
.then(prevRides => {
|
|
559
|
+
this.current.prevRides = prevRides;
|
|
560
|
+
this.observer.emit('list.init', prevRides);
|
|
561
|
+
});
|
|
544
562
|
}
|
|
545
563
|
catch (err) {
|
|
546
564
|
this.logError(err, 'initPrevActivities');
|
|
@@ -683,6 +701,7 @@ let ActivityRideService = (() => {
|
|
|
683
701
|
const startTime = new Date(this.tsStart).toUTCString();
|
|
684
702
|
this.current = { deviceData: {}, dataState: {} };
|
|
685
703
|
let startPos = 0;
|
|
704
|
+
let endPos, segment;
|
|
686
705
|
let realityFactor;
|
|
687
706
|
let routeName;
|
|
688
707
|
let routeId;
|
|
@@ -705,6 +724,8 @@ let ActivityRideService = (() => {
|
|
|
705
724
|
(0, route_1.validateRoute)(selectedRoute);
|
|
706
725
|
const s = startSettings;
|
|
707
726
|
startPos = s.startPos;
|
|
727
|
+
endPos = s.endPos;
|
|
728
|
+
segment = s.segment;
|
|
708
729
|
this.current.endPos = s.endPos;
|
|
709
730
|
realityFactor = s.realityFactor;
|
|
710
731
|
routeId = selectedRoute.description.id;
|
|
@@ -741,7 +762,7 @@ let ActivityRideService = (() => {
|
|
|
741
762
|
distance: 0,
|
|
742
763
|
totalElevation: 0,
|
|
743
764
|
logs: [],
|
|
744
|
-
startPos, realityFactor,
|
|
765
|
+
startPos, endPos, segment, realityFactor,
|
|
745
766
|
fileName
|
|
746
767
|
};
|
|
747
768
|
return activity;
|
|
@@ -844,7 +865,7 @@ let ActivityRideService = (() => {
|
|
|
844
865
|
this.activity.totalElevation = this.current.elevationGain;
|
|
845
866
|
let list;
|
|
846
867
|
if (this.current.showPrev) {
|
|
847
|
-
list = this.getPrevRideStats(
|
|
868
|
+
list = this.getPrevRideStats(logRecord);
|
|
848
869
|
this.emit('prevRides', list);
|
|
849
870
|
}
|
|
850
871
|
this.emit('data', data, list);
|