incyclist-services 1.1.85 → 1.1.87
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/routes/base/types/index.d.ts +3 -0
- package/lib/routes/list/cards/ActiveImportCard.d.ts +2 -1
- package/lib/routes/list/cards/FreeRideCard.d.ts +6 -1
- package/lib/routes/list/cards/FreeRideCard.js +47 -17
- package/lib/routes/list/cards/RouteCard.d.ts +13 -3
- package/lib/routes/list/cards/RouteCard.js +53 -17
- package/lib/routes/list/cards/RouteImportCard.d.ts +2 -1
- package/lib/routes/list/cards/types.d.ts +0 -3
- package/lib/routes/list/service.d.ts +1 -1
- package/lib/routes/list/service.js +3 -1
- package/lib/workouts/base/model/Segment.d.ts +18 -0
- package/lib/workouts/base/model/Segment.js +139 -0
- package/lib/workouts/base/model/Step.d.ts +35 -0
- package/lib/workouts/base/model/Step.js +158 -0
- package/lib/workouts/base/model/Workout.d.ts +10 -0
- package/lib/workouts/base/model/Workout.js +42 -0
- package/lib/workouts/base/model/types.d.ts +44 -0
- package/lib/workouts/base/model/types.js +2 -0
- package/lib/workouts/base/parsers/Json.d.ts +12 -0
- package/lib/workouts/base/parsers/Json.js +73 -0
- package/lib/workouts/base/parsers/factory.d.ts +11 -0
- package/lib/workouts/base/parsers/factory.js +92 -0
- package/lib/workouts/base/parsers/index.d.ts +5 -0
- package/lib/workouts/base/parsers/index.js +51 -0
- package/lib/workouts/base/parsers/types.d.ts +8 -0
- package/lib/workouts/base/parsers/types.js +2 -0
- package/lib/workouts/base/parsers/zwo.d.ts +32 -0
- package/lib/workouts/base/parsers/zwo.js +249 -0
- package/lib/workouts/list/cards/WorkoutCard.d.ts +0 -0
- package/lib/workouts/list/cards/WorkoutCard.js +0 -0
- package/lib/workouts/list/cards/WorkoutImportCard.d.ts +19 -0
- package/lib/workouts/list/cards/WorkoutImportCard.js +40 -0
- package/lib/workouts/list/cards/base.d.ts +20 -0
- package/lib/workouts/list/cards/base.js +54 -0
- package/lib/workouts/list/cards/types.d.ts +19 -0
- package/lib/workouts/list/cards/types.js +8 -0
- package/lib/workouts/list/service.d.ts +4 -0
- package/lib/workouts/list/service.js +66 -0
- package/package.json +1 -1
|
@@ -4,7 +4,8 @@ import { ImportFilter } from "../../../base/cardlist/types";
|
|
|
4
4
|
import { PromiseObserver } from "../../../base/types/observer";
|
|
5
5
|
import { Route } from "../../base/model/route";
|
|
6
6
|
import { BaseCard } from "./base";
|
|
7
|
-
import {
|
|
7
|
+
import { RouteCardType, ActiveImportProps } from "./types";
|
|
8
|
+
import { AppStatus } from "../../base/types";
|
|
8
9
|
export declare class ActiveImportCard extends BaseCard implements Card<Route> {
|
|
9
10
|
protected file: FileInfo;
|
|
10
11
|
protected error: Error;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { EventLogger } from "gd-eventlog";
|
|
1
2
|
import { Card } from "../../../base/cardlist";
|
|
2
3
|
import { PromiseObserver } from "../../../base/types/observer";
|
|
3
4
|
import { LatLng } from "../../../utils/geo";
|
|
4
5
|
import { Route } from "../../base/model/route";
|
|
5
6
|
import { FreeRideOption } from "../types";
|
|
6
7
|
import { BaseCard } from "./base";
|
|
7
|
-
import {
|
|
8
|
+
import { RouteCardType } from "./types";
|
|
9
|
+
import { AppStatus } from "../../base/types";
|
|
8
10
|
export type FreeRideSettings = {
|
|
9
11
|
position?: LatLng;
|
|
10
12
|
options?: any;
|
|
@@ -15,6 +17,8 @@ export interface FreeRideDisplayProps extends LatLng {
|
|
|
15
17
|
export declare class FreeRideCard extends BaseCard implements Card<Route> {
|
|
16
18
|
protected position: LatLng;
|
|
17
19
|
protected options: [];
|
|
20
|
+
protected logger: EventLogger;
|
|
21
|
+
constructor();
|
|
18
22
|
delete(): PromiseObserver<boolean>;
|
|
19
23
|
canStart(status: AppStatus): boolean;
|
|
20
24
|
setVisible(): void;
|
|
@@ -34,4 +38,5 @@ export declare class FreeRideCard extends BaseCard implements Card<Route> {
|
|
|
34
38
|
cancel(): void;
|
|
35
39
|
protected loadSettings(): void;
|
|
36
40
|
protected saveSettings(): void;
|
|
41
|
+
protected logError(err: Error, fn: string): void;
|
|
37
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FreeRideCard = void 0;
|
|
4
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
4
5
|
const observer_1 = require("../../../base/types/observer");
|
|
5
6
|
const settings_1 = require("../../../settings");
|
|
6
7
|
const utils_1 = require("../../../utils");
|
|
@@ -9,6 +10,10 @@ const route_1 = require("../../base/model/route");
|
|
|
9
10
|
const service_1 = require("../service");
|
|
10
11
|
const base_1 = require("./base");
|
|
11
12
|
class FreeRideCard extends base_1.BaseCard {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.logger = new gd_eventlog_1.EventLogger('FreeRideCard');
|
|
16
|
+
}
|
|
12
17
|
delete() {
|
|
13
18
|
return observer_1.PromiseObserver.alwaysReturning(false);
|
|
14
19
|
}
|
|
@@ -29,7 +34,12 @@ class FreeRideCard extends base_1.BaseCard {
|
|
|
29
34
|
return 'Free-Ride';
|
|
30
35
|
}
|
|
31
36
|
getDisplayProperties() {
|
|
32
|
-
|
|
37
|
+
try {
|
|
38
|
+
return Object.assign(Object.assign({}, this.position), { visible: true });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
this.logError(err, 'getDisplayProperties');
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
44
|
getPosition() {
|
|
35
45
|
return this.position;
|
|
@@ -46,29 +56,46 @@ class FreeRideCard extends base_1.BaseCard {
|
|
|
46
56
|
setData(_data) {
|
|
47
57
|
}
|
|
48
58
|
openSettings() {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
try {
|
|
60
|
+
(0, service_1.getRouteList)().unselect();
|
|
61
|
+
if (!this.position)
|
|
62
|
+
this.loadSettings();
|
|
63
|
+
const position = this.position;
|
|
64
|
+
return { position };
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
this.logError(err, 'openSettings');
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
54
70
|
}
|
|
55
71
|
changeSettings(props) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
try {
|
|
73
|
+
const { position: pos } = props;
|
|
74
|
+
this.position = utils_1.geo.getLatLng(pos);
|
|
75
|
+
this.saveSettings();
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
this.logError(err, 'changeSettings');
|
|
79
|
+
}
|
|
59
80
|
}
|
|
60
81
|
accept(option) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
try {
|
|
83
|
+
option.path = option.path.map(p => ({ lat: p.lat, lng: p.lng, ways: p.ways, tag: p.tag }));
|
|
84
|
+
const settings = {
|
|
85
|
+
type: this.getCardType(),
|
|
86
|
+
position: this.position,
|
|
87
|
+
option
|
|
88
|
+
};
|
|
89
|
+
(0, service_1.getRouteList)().setStartSettings(settings);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
this.logError(err, 'accept');
|
|
93
|
+
}
|
|
68
94
|
}
|
|
69
95
|
cancel() {
|
|
70
96
|
}
|
|
71
97
|
loadSettings() {
|
|
98
|
+
var _a, _b;
|
|
72
99
|
const prevSetting = this.getUserSetting(`routeSelection.freeRide`, null);
|
|
73
100
|
if (prevSetting) {
|
|
74
101
|
this.position = prevSetting.position;
|
|
@@ -76,7 +103,7 @@ class FreeRideCard extends base_1.BaseCard {
|
|
|
76
103
|
else {
|
|
77
104
|
this.position = this.getUserSetting(`position`, null);
|
|
78
105
|
}
|
|
79
|
-
if (!(0, valid_1.valid)(this.position.lat) || !(0, valid_1.valid)(this.position.lng))
|
|
106
|
+
if (!(0, valid_1.valid)((_a = this.position) === null || _a === void 0 ? void 0 : _a.lat) || !(0, valid_1.valid)((_b = this.position) === null || _b === void 0 ? void 0 : _b.lng))
|
|
80
107
|
this.position = undefined;
|
|
81
108
|
}
|
|
82
109
|
saveSettings() {
|
|
@@ -85,5 +112,8 @@ class FreeRideCard extends base_1.BaseCard {
|
|
|
85
112
|
const userSettings = (0, settings_1.useUserSettings)();
|
|
86
113
|
userSettings.set('routeSelection.freeRide', { position: this.position });
|
|
87
114
|
}
|
|
115
|
+
logError(err, fn) {
|
|
116
|
+
this.logger.logEvent({ message: 'error', error: err.message, fn, stack: err.stack });
|
|
117
|
+
}
|
|
88
118
|
}
|
|
89
119
|
exports.FreeRideCard = FreeRideCard;
|
|
@@ -2,9 +2,10 @@ import { Card, CardList } from "../../../base/cardlist";
|
|
|
2
2
|
import { Observer, PromiseObserver } from "../../../base/types/observer";
|
|
3
3
|
import { RouteApiDetail } from "../../base/api/types";
|
|
4
4
|
import { Route } from "../../base/model/route";
|
|
5
|
-
import { RouteInfo } from "../../base/types";
|
|
5
|
+
import { RouteInfo, RoutePoint } from "../../base/types";
|
|
6
6
|
import { BaseCard } from "./base";
|
|
7
|
-
import {
|
|
7
|
+
import { RouteCardType } from "./types";
|
|
8
|
+
import { AppStatus } from "../../base/types";
|
|
8
9
|
import { RouteStartSettings } from "../types";
|
|
9
10
|
import { RoutesDbLoader } from "../loaders/db";
|
|
10
11
|
import { DownloadObserver } from "../../download/types";
|
|
@@ -28,8 +29,15 @@ export interface StartSettings {
|
|
|
28
29
|
realityFactor: number;
|
|
29
30
|
downloadProgress?: number;
|
|
30
31
|
convertProgress?: number;
|
|
32
|
+
loopOverwrite?: boolean;
|
|
33
|
+
nextOverwrite?: boolean;
|
|
31
34
|
}
|
|
32
35
|
export type RouteSettings = StartSettings & RouteStartSettings;
|
|
36
|
+
export type RouteCardProps = {
|
|
37
|
+
settings: RouteSettings;
|
|
38
|
+
showLoopOverwrite: boolean;
|
|
39
|
+
showNextOverwrite: boolean;
|
|
40
|
+
};
|
|
33
41
|
declare class ConvertObserver extends Observer {
|
|
34
42
|
protected conversion: Observer;
|
|
35
43
|
constructor();
|
|
@@ -65,10 +73,11 @@ export declare class RouteCard extends BaseCard implements Card<Route> {
|
|
|
65
73
|
getCardType(): RouteCardType;
|
|
66
74
|
getTitle(): string;
|
|
67
75
|
getDisplayProperties(): SummaryCardDisplayProps;
|
|
76
|
+
getMarkers(settings?: RouteSettings): Array<RoutePoint>;
|
|
68
77
|
getId(): string;
|
|
69
78
|
enableDelete(enabled?: boolean): void;
|
|
70
79
|
canDelete(): boolean;
|
|
71
|
-
openSettings():
|
|
80
|
+
openSettings(): RouteCardProps;
|
|
72
81
|
changeSettings(props: RouteSettings): void;
|
|
73
82
|
save(): Promise<void>;
|
|
74
83
|
delete(): PromiseObserver<boolean>;
|
|
@@ -102,5 +111,6 @@ export declare class RouteCard extends BaseCard implements Card<Route> {
|
|
|
102
111
|
protected resetDownload(): Promise<void>;
|
|
103
112
|
protected deleteRoute(): Promise<void>;
|
|
104
113
|
protected logError(err: Error, fn: string): void;
|
|
114
|
+
protected getSettings(): RouteSettings;
|
|
105
115
|
}
|
|
106
116
|
export {};
|
|
@@ -22,6 +22,7 @@ const utils_1 = require("../../../utils");
|
|
|
22
22
|
const service_2 = require("../../download/service");
|
|
23
23
|
const localization_1 = require("../../base/utils/localization");
|
|
24
24
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
25
|
+
const route_1 = require("../../base/utils/route");
|
|
25
26
|
class ConvertObserver extends observer_1.Observer {
|
|
26
27
|
constructor() {
|
|
27
28
|
super();
|
|
@@ -162,6 +163,19 @@ class RouteCard extends base_1.BaseCard {
|
|
|
162
163
|
this.logError(err, 'getDisplayProperties');
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
getMarkers(settings) {
|
|
167
|
+
const markers = [];
|
|
168
|
+
try {
|
|
169
|
+
const startSettings = settings || this.getSettings();
|
|
170
|
+
const startDistance = startSettings.startPos || 0;
|
|
171
|
+
const startPos = (0, route_1.getPosition)(this.route, { distance: startDistance, nearest: true });
|
|
172
|
+
markers.push(startPos);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
this.logError(err, 'getMarkers');
|
|
176
|
+
}
|
|
177
|
+
return markers;
|
|
178
|
+
}
|
|
165
179
|
getId() {
|
|
166
180
|
var _a, _b;
|
|
167
181
|
return (_b = (_a = this.route) === null || _a === void 0 ? void 0 : _a.description) === null || _b === void 0 ? void 0 : _b.id;
|
|
@@ -173,32 +187,29 @@ class RouteCard extends base_1.BaseCard {
|
|
|
173
187
|
return this.deleteable;
|
|
174
188
|
}
|
|
175
189
|
openSettings() {
|
|
176
|
-
|
|
190
|
+
var _a, _b, _c, _d, _e, _f;
|
|
191
|
+
const settings = this.getSettings();
|
|
192
|
+
let showLoopOverwrite, showNextOverwrite;
|
|
177
193
|
try {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (startSettings) {
|
|
188
|
-
this.startSettings = startSettings;
|
|
189
|
-
}
|
|
190
|
-
if (migrate) {
|
|
191
|
-
(0, settings_1.useUserSettings)().set(key, this.startSettings);
|
|
194
|
+
showLoopOverwrite = (_b = (_a = this.route) === null || _a === void 0 ? void 0 : _a.description) === null || _b === void 0 ? void 0 : _b.isLoop;
|
|
195
|
+
showNextOverwrite = (0, valid_1.valid)((_d = (_c = this.route) === null || _c === void 0 ? void 0 : _c.description) === null || _d === void 0 ? void 0 : _d.next);
|
|
196
|
+
if (showNextOverwrite) {
|
|
197
|
+
const card = (0, service_1.getRouteList)().getCard((_f = (_e = this.route) === null || _e === void 0 ? void 0 : _e.description) === null || _f === void 0 ? void 0 : _f.next);
|
|
198
|
+
const route = card === null || card === void 0 ? void 0 : card.getData();
|
|
199
|
+
if (!route || (route.description.requiresDownload && !route.description.isDownloaded)) {
|
|
200
|
+
showNextOverwrite = false;
|
|
201
|
+
}
|
|
202
|
+
console.log('~~~ NEXT', route);
|
|
192
203
|
}
|
|
193
204
|
}
|
|
194
205
|
catch (err) {
|
|
195
206
|
this.logError(err, 'openSettings');
|
|
196
207
|
}
|
|
197
|
-
return
|
|
208
|
+
return { settings, showLoopOverwrite, showNextOverwrite };
|
|
198
209
|
}
|
|
199
210
|
changeSettings(props) {
|
|
200
211
|
try {
|
|
201
|
-
this.startSettings = props;
|
|
212
|
+
this.startSettings = Object.assign({}, props);
|
|
202
213
|
const userSettings = (0, settings_1.useUserSettings)();
|
|
203
214
|
const key = this.buildSettingsKey();
|
|
204
215
|
userSettings.set(key, props, true);
|
|
@@ -275,6 +286,7 @@ class RouteCard extends base_1.BaseCard {
|
|
|
275
286
|
start() {
|
|
276
287
|
try {
|
|
277
288
|
const service = (0, service_1.getRouteList)();
|
|
289
|
+
console.log('~~~ start', this.startSettings);
|
|
278
290
|
service.select(this.route);
|
|
279
291
|
service.setStartSettings(Object.assign({ type: this.getCardType() }, this.startSettings));
|
|
280
292
|
this.route.description.tsLastStart = Date.now();
|
|
@@ -519,5 +531,29 @@ class RouteCard extends base_1.BaseCard {
|
|
|
519
531
|
logError(err, fn) {
|
|
520
532
|
this.logger.logEvent({ message: 'error', error: err.message, fn, stack: err.stack });
|
|
521
533
|
}
|
|
534
|
+
getSettings() {
|
|
535
|
+
this.startSettings = { startPos: 0, realityFactor: 100, type: this.getCardType() };
|
|
536
|
+
try {
|
|
537
|
+
let migrate = false;
|
|
538
|
+
const legacy = this.buildSettingsKey(true);
|
|
539
|
+
const legacySettings = (0, settings_1.useUserSettings)().get(legacy, null);
|
|
540
|
+
if (legacySettings) {
|
|
541
|
+
this.startSettings = legacySettings;
|
|
542
|
+
migrate = true;
|
|
543
|
+
}
|
|
544
|
+
const key = this.buildSettingsKey();
|
|
545
|
+
const startSettings = (0, settings_1.useUserSettings)().get(key, null);
|
|
546
|
+
if (startSettings) {
|
|
547
|
+
this.startSettings = startSettings;
|
|
548
|
+
}
|
|
549
|
+
if (migrate) {
|
|
550
|
+
(0, settings_1.useUserSettings)().set(key, this.startSettings);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
catch (err) {
|
|
554
|
+
this.logError(err, 'getSettings');
|
|
555
|
+
}
|
|
556
|
+
return this.startSettings;
|
|
557
|
+
}
|
|
522
558
|
}
|
|
523
559
|
exports.RouteCard = RouteCard;
|
|
@@ -3,7 +3,8 @@ import { ImportFilter } from "../../../base/cardlist/types";
|
|
|
3
3
|
import { PromiseObserver } from "../../../base/types/observer";
|
|
4
4
|
import { Route } from "../../base/model/route";
|
|
5
5
|
import { BaseCard } from "./base";
|
|
6
|
-
import {
|
|
6
|
+
import { RouteCardType, RouteImportProps } from "./types";
|
|
7
|
+
import { AppStatus } from "../../base/types";
|
|
7
8
|
export declare class RouteImportCard extends BaseCard implements Card<Route> {
|
|
8
9
|
setVisible(): void;
|
|
9
10
|
canStart(status: AppStatus): boolean;
|
|
@@ -61,7 +61,7 @@ export declare class RouteListService extends IncyclistService {
|
|
|
61
61
|
onCarouselUpdated(list: any, item: any, itemsInSlide: any): void;
|
|
62
62
|
preload(): PromiseObserver<void>;
|
|
63
63
|
getLists(forUi?: boolean): Array<CardList<Route>>;
|
|
64
|
-
getRouteDetails(id: string): Promise<RouteApiDetail>;
|
|
64
|
+
getRouteDetails(id: string, expectLocal?: boolean): Promise<RouteApiDetail>;
|
|
65
65
|
getSelectedRouteDetails(): Promise<RouteApiDetail>;
|
|
66
66
|
unselect(): void;
|
|
67
67
|
select(route: Route): void;
|
|
@@ -300,11 +300,13 @@ let RouteListService = (() => {
|
|
|
300
300
|
return [this.myRoutes];
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
|
-
getRouteDetails(id) {
|
|
303
|
+
getRouteDetails(id, expectLocal = false) {
|
|
304
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
305
|
try {
|
|
306
306
|
const route = this.routes.find(r => r.description.id === id);
|
|
307
307
|
if (route) {
|
|
308
|
+
if (expectLocal && route.description.requiresDownload && !route.description.isDownloaded)
|
|
309
|
+
return;
|
|
308
310
|
if (route.details)
|
|
309
311
|
return route.details;
|
|
310
312
|
route.details = yield this.db.getDetails(id);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Step from './Step';
|
|
2
|
+
import { CurrentStep, SegmentDefinition, StepDefinition } from './types';
|
|
3
|
+
export default class Segment extends Step implements SegmentDefinition {
|
|
4
|
+
steps: Array<Step>;
|
|
5
|
+
repeat: number;
|
|
6
|
+
constructor(opts?: SegmentDefinition, ignoreValidate?: boolean);
|
|
7
|
+
protected init(opts: SegmentDefinition, ignoreValidate: boolean): void;
|
|
8
|
+
validate(): void;
|
|
9
|
+
validateTiming(): boolean;
|
|
10
|
+
prepareNext(json: StepDefinition | SegmentDefinition): void;
|
|
11
|
+
push(s: any): void;
|
|
12
|
+
getDuration(): number;
|
|
13
|
+
getSingleDuration(): number;
|
|
14
|
+
getStart(): number;
|
|
15
|
+
getEnd(): number;
|
|
16
|
+
getStep(ts: number): Step;
|
|
17
|
+
getLimits(ts: any, includeStepInfo?: boolean): CurrentStep;
|
|
18
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const valid_1 = require("../../../utils/valid");
|
|
7
|
+
const Step_1 = __importDefault(require("./Step"));
|
|
8
|
+
class Segment extends Step_1.default {
|
|
9
|
+
constructor(opts = null, ignoreValidate) {
|
|
10
|
+
super(opts, true);
|
|
11
|
+
this.steps = [];
|
|
12
|
+
this.repeat = 1;
|
|
13
|
+
this.type = 'segment';
|
|
14
|
+
if ((0, valid_1.valid)(opts)) {
|
|
15
|
+
this.init(opts, ignoreValidate);
|
|
16
|
+
if (ignoreValidate === undefined || ignoreValidate === false)
|
|
17
|
+
this.validate();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
init(opts, ignoreValidate) {
|
|
21
|
+
const start = opts.start || 0;
|
|
22
|
+
this.start = start;
|
|
23
|
+
let stepStart = start;
|
|
24
|
+
if (opts instanceof Step_1.default) {
|
|
25
|
+
this.steps = [new Step_1.default(opts)];
|
|
26
|
+
}
|
|
27
|
+
else if (opts.steps !== undefined) {
|
|
28
|
+
if (Array.isArray(opts.steps)) {
|
|
29
|
+
opts.steps.forEach(step => {
|
|
30
|
+
if (step.start === undefined) {
|
|
31
|
+
step.start = stepStart;
|
|
32
|
+
}
|
|
33
|
+
const s = new Step_1.default(step);
|
|
34
|
+
stepStart = s.end;
|
|
35
|
+
this.steps.push(s);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (ignoreValidate !== true)
|
|
40
|
+
throw new Error(`Invalid Segment description, no steps defined`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
if (ignoreValidate === undefined || ignoreValidate === false)
|
|
45
|
+
throw new Error(`Invalid Segment description, no steps defined`);
|
|
46
|
+
}
|
|
47
|
+
if (opts.repeat !== undefined)
|
|
48
|
+
this.repeat = opts.repeat;
|
|
49
|
+
this.duration = this.getDuration();
|
|
50
|
+
this.end = this.start + this.duration;
|
|
51
|
+
}
|
|
52
|
+
validate() {
|
|
53
|
+
this.validateTiming();
|
|
54
|
+
}
|
|
55
|
+
validateTiming() {
|
|
56
|
+
let prev;
|
|
57
|
+
this.steps.forEach(s => {
|
|
58
|
+
s.validateTiming();
|
|
59
|
+
if (prev !== undefined) {
|
|
60
|
+
const delta1 = Math.abs(prev.end - s.start);
|
|
61
|
+
if (delta1 > 0)
|
|
62
|
+
throw new Error(`Invalid Segment description, start & prev end not matching`);
|
|
63
|
+
}
|
|
64
|
+
prev = s;
|
|
65
|
+
});
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
prepareNext(json) {
|
|
69
|
+
if (json === undefined)
|
|
70
|
+
return;
|
|
71
|
+
const empty = this.steps.length === 0;
|
|
72
|
+
if (json.start === undefined && json.end === undefined) {
|
|
73
|
+
json.start = !empty ? this.steps[this.steps.length - 1].end : 0;
|
|
74
|
+
}
|
|
75
|
+
if (empty) {
|
|
76
|
+
this.start = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
push(s) {
|
|
80
|
+
if (s === undefined)
|
|
81
|
+
return;
|
|
82
|
+
this.prepareNext(s);
|
|
83
|
+
let step;
|
|
84
|
+
if (s instanceof Step_1.default || s instanceof Segment)
|
|
85
|
+
step = s;
|
|
86
|
+
else
|
|
87
|
+
step = new Step_1.default(s);
|
|
88
|
+
this.steps.push(step);
|
|
89
|
+
this.duration += step.getDuration();
|
|
90
|
+
this.end = this.start + this.duration;
|
|
91
|
+
this.validate();
|
|
92
|
+
}
|
|
93
|
+
getDuration() {
|
|
94
|
+
return this.getSingleDuration() * this.repeat;
|
|
95
|
+
}
|
|
96
|
+
getSingleDuration() {
|
|
97
|
+
if (this.steps.length === 0)
|
|
98
|
+
return 0;
|
|
99
|
+
return this.steps.map(s => s.duration).reduce((a, b) => a + b);
|
|
100
|
+
}
|
|
101
|
+
getStart() {
|
|
102
|
+
if (this.start !== undefined)
|
|
103
|
+
return this.start;
|
|
104
|
+
else {
|
|
105
|
+
if (this.steps.length > 0)
|
|
106
|
+
return this.steps[0].start;
|
|
107
|
+
else
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
getEnd() {
|
|
112
|
+
return this.getStart() + this.getDuration();
|
|
113
|
+
}
|
|
114
|
+
getStep(ts) {
|
|
115
|
+
if (ts >= this.getStart() && ts <= this.getEnd()) {
|
|
116
|
+
const segTime = ts - this.getStart();
|
|
117
|
+
let part = (segTime % this.getSingleDuration());
|
|
118
|
+
part += this.getStart();
|
|
119
|
+
if (part === this.getStart() && segTime > 0)
|
|
120
|
+
part += this.getSingleDuration();
|
|
121
|
+
const found = this.steps.find(s => {
|
|
122
|
+
return (part >= s.start && part <= s.end);
|
|
123
|
+
});
|
|
124
|
+
return found;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
getLimits(ts, includeStepInfo = false) {
|
|
128
|
+
const step = this.getStep(ts);
|
|
129
|
+
if (step === undefined)
|
|
130
|
+
return undefined;
|
|
131
|
+
const segTime = ts - this.getStart();
|
|
132
|
+
let part = (segTime % this.getSingleDuration());
|
|
133
|
+
part += this.getStart();
|
|
134
|
+
if (part === this.getStart() && segTime > 0)
|
|
135
|
+
part += this.getSingleDuration();
|
|
136
|
+
return step.getLimits(part, includeStepInfo);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.default = Segment;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CurrentStep, Limit, PowerLimit, StepDefinition } from "./types";
|
|
2
|
+
export declare const STEP_TYPE: {
|
|
3
|
+
STEP: string;
|
|
4
|
+
SEGMENT: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const POWER_TYPE: {
|
|
7
|
+
WATT: string;
|
|
8
|
+
PCT: string;
|
|
9
|
+
};
|
|
10
|
+
export default class Step implements StepDefinition {
|
|
11
|
+
type: 'step' | 'segment';
|
|
12
|
+
start?: number;
|
|
13
|
+
end?: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
power?: PowerLimit;
|
|
16
|
+
cadence?: Limit;
|
|
17
|
+
hrm?: Limit;
|
|
18
|
+
text: string;
|
|
19
|
+
work: boolean;
|
|
20
|
+
steady: boolean;
|
|
21
|
+
cooldown: boolean;
|
|
22
|
+
constructor(opts?: any, ignoreValidate?: boolean);
|
|
23
|
+
validate(): void;
|
|
24
|
+
getDuration(): number;
|
|
25
|
+
getStart(): number;
|
|
26
|
+
getEnd(): number;
|
|
27
|
+
validateTiming(): boolean;
|
|
28
|
+
validateLimit(p: Limit, name: string): boolean;
|
|
29
|
+
validatePower(): boolean;
|
|
30
|
+
validateCadence(): boolean;
|
|
31
|
+
validateHrm(): boolean;
|
|
32
|
+
getLimits(ts: number, includeStepInfo?: boolean): CurrentStep;
|
|
33
|
+
getRemainder(limits: CurrentStep, includeStepInfo?: boolean): CurrentStep;
|
|
34
|
+
calc(ts: any, limit: any, includeStepInfo: boolean, isPower?: boolean): {};
|
|
35
|
+
}
|