ts-watches 0.1.0
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/LICENSE.md +21 -0
- package/README.md +358 -0
- package/dist/analysis/index.d.ts +5 -0
- package/dist/analysis/personal-records.d.ts +58 -0
- package/dist/analysis/race-predictor.d.ts +53 -0
- package/dist/analysis/running-dynamics.d.ts +66 -0
- package/dist/analysis/training-load.d.ts +40 -0
- package/dist/analysis/zones.d.ts +69 -0
- package/dist/bin/cli.js +52 -0
- package/dist/chunk-gsgt8r0z.js +2 -0
- package/dist/cloud/garmin-activity-api.d.ts +129 -0
- package/dist/cloud/garmin-connect.d.ts +67 -0
- package/dist/cloud/index.d.ts +4 -0
- package/dist/cloud/strava.d.ts +88 -0
- package/dist/cloud/trainingpeaks.d.ts +48 -0
- package/dist/config.d.ts +4 -0
- package/dist/drivers/apple.d.ts +17 -0
- package/dist/drivers/coros.d.ts +13 -0
- package/dist/drivers/garmin.d.ts +12 -0
- package/dist/drivers/index.d.ts +6 -0
- package/dist/drivers/polar.d.ts +14 -0
- package/dist/drivers/suunto.d.ts +13 -0
- package/dist/drivers/wahoo.d.ts +13 -0
- package/dist/export/csv.d.ts +15 -0
- package/dist/export/geojson.d.ts +23 -0
- package/dist/export/gpx.d.ts +10 -0
- package/dist/export/index.d.ts +4 -0
- package/dist/export/tcx.d.ts +10 -0
- package/dist/fit/constants.d.ts +606 -0
- package/dist/fit/decoder.d.ts +16 -0
- package/dist/fit/index.d.ts +3 -0
- package/dist/fit/parser.d.ts +21 -0
- package/dist/index.d.ts +40 -0
- package/dist/realtime/ant-plus.d.ts +201 -0
- package/dist/realtime/bluetooth.d.ts +153 -0
- package/dist/realtime/index.d.ts +3 -0
- package/dist/realtime/live-tracking.d.ts +70 -0
- package/dist/src/index.js +324 -0
- package/dist/types.d.ts +307 -0
- package/dist/workouts/builder.d.ts +184 -0
- package/dist/workouts/course.d.ts +74 -0
- package/dist/workouts/index.d.ts +3 -0
- package/dist/workouts/training-plan.d.ts +77 -0
- package/package.json +92 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
<p align="center"><img src=".github/art/cover.jpg" alt="Social Card of this repo"></p>
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/ts-watches)
|
|
4
|
+
[](https://github.com/stacksjs/ts-watches/actions?query=workflow%3Aci)
|
|
5
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
6
|
+
<!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] -->
|
|
7
|
+
<!-- [![Codecov][codecov-src]][codecov-href] -->
|
|
8
|
+
|
|
9
|
+
# ts-watches
|
|
10
|
+
|
|
11
|
+
A comprehensive TypeScript library for downloading, parsing, and analyzing data from smartwatches and fitness devices. Supports Garmin, Polar, Suunto, Coros, Wahoo, and Apple Watch with full FIT file parsing, cloud integrations, training analysis, and real-time data streaming.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
### Device Support
|
|
16
|
+
|
|
17
|
+
- **Garmin** - Full FIT file parsing for activities, monitoring, sleep, stress, HRV
|
|
18
|
+
- **Polar** - HRM and JSON file format support
|
|
19
|
+
- **Suunto** - SML (XML) format parsing
|
|
20
|
+
- **Coros** - FIT file support with device detection
|
|
21
|
+
- **Wahoo** - FIT file support for ELEMNT devices
|
|
22
|
+
- **Apple Watch** - Health XML export parsing
|
|
23
|
+
|
|
24
|
+
### Data Parsing
|
|
25
|
+
|
|
26
|
+
- **FIT Protocol** - Complete binary parser for Garmin's FIT format
|
|
27
|
+
- **Activity Data** - Runs, rides, swims, hikes with full GPS and metrics
|
|
28
|
+
- **Health Monitoring** - Heart rate, sleep, stress, SpO2, HRV, respiration
|
|
29
|
+
- **Training Metrics** - TSS, IF, NP, training load calculations
|
|
30
|
+
|
|
31
|
+
### Data Export
|
|
32
|
+
|
|
33
|
+
- **GPX 1.1** - With Garmin TrackPoint extensions for heart rate, cadence, power
|
|
34
|
+
- **TCX** - Training Center XML format for Strava and other platforms
|
|
35
|
+
- **CSV** - Flexible export for activities and monitoring data
|
|
36
|
+
- **GeoJSON** - For mapping applications with Douglas-Peucker simplification
|
|
37
|
+
|
|
38
|
+
### Cloud Integrations
|
|
39
|
+
|
|
40
|
+
- **Garmin Activity API** - Official OAuth 2.0 PKCE integration with webhook push notifications, backfill and deregistration
|
|
41
|
+
- **Garmin Connect** - Download activities, daily summaries, sleep, stress, body battery (unofficial, password-based)
|
|
42
|
+
- **Strava** - OAuth authentication, activity upload, stream data retrieval
|
|
43
|
+
|
|
44
|
+
### Training Analysis
|
|
45
|
+
|
|
46
|
+
- **Training Load** - TSS, ATL, CTL, TSB calculations with recommendations
|
|
47
|
+
- **Personal Records** - Track PRs for various distances and metrics
|
|
48
|
+
- **Heart Rate Zones** - Percentage, Karvonen (reserve), LTHR-based calculations
|
|
49
|
+
- **Power Zones** - FTP-based zone calculations
|
|
50
|
+
- **Race Predictor** - Riegel formula predictions, VO2max estimation, training paces
|
|
51
|
+
- **Running Dynamics** - Form analysis, ground contact time, vertical oscillation
|
|
52
|
+
|
|
53
|
+
### Workout Tools
|
|
54
|
+
|
|
55
|
+
- **Workout Builder** - Fluent API for creating structured workouts
|
|
56
|
+
- **Course Builder** - Create GPS courses with waypoints
|
|
57
|
+
- **Training Plans** - Generate marathon and 5K training plans
|
|
58
|
+
- **iCal Export** - Export training plans to calendar format
|
|
59
|
+
|
|
60
|
+
### Real-time Data
|
|
61
|
+
|
|
62
|
+
- **ANT+** - Heart rate, power, speed/cadence sensor protocols
|
|
63
|
+
- **Bluetooth LE** - BLE GATT services for fitness devices
|
|
64
|
+
- **Live Tracking** - Real-time position and metrics sharing
|
|
65
|
+
|
|
66
|
+
### Developer Experience
|
|
67
|
+
|
|
68
|
+
- **CLI Tool** - Download, parse, and analyze from command line
|
|
69
|
+
- **TypeScript** - Fully typed APIs with comprehensive type exports
|
|
70
|
+
- **Zero Dependencies** - Core FIT parser has no external dependencies
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bun install ts-watches
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createGarminDriver } from 'ts-watches'
|
|
82
|
+
|
|
83
|
+
const driver = createGarminDriver()
|
|
84
|
+
|
|
85
|
+
// Detect connected devices
|
|
86
|
+
const devices = await driver.detectDevices()
|
|
87
|
+
console.log('Found devices:', devices)
|
|
88
|
+
|
|
89
|
+
// Download data from a device
|
|
90
|
+
if (devices.length > 0) {
|
|
91
|
+
const result = await driver.downloadData(devices[0], {
|
|
92
|
+
outputDir: './my-watch-data',
|
|
93
|
+
includeActivities: true,
|
|
94
|
+
includeMonitoring: true,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
console.log(`Downloaded ${result.activities.length} activities`)
|
|
98
|
+
console.log(`Downloaded ${result.monitoring.size} days of monitoring data`)
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Usage Examples
|
|
103
|
+
|
|
104
|
+
### Parse FIT Files
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { createGarminDriver } from 'ts-watches'
|
|
108
|
+
|
|
109
|
+
const driver = createGarminDriver()
|
|
110
|
+
const activity = await driver.parseActivityFile('/path/to/activity.fit')
|
|
111
|
+
|
|
112
|
+
console.log(`${activity.sport}: ${(activity.totalDistance / 1000).toFixed(2)}km`)
|
|
113
|
+
console.log(`Duration: ${Math.floor(activity.totalTime / 60)} minutes`)
|
|
114
|
+
console.log(`Avg HR: ${activity.avgHeartRate} bpm`)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Export to GPX
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { activityToGpx, activityToTcx, activityToCsv } from 'ts-watches'
|
|
121
|
+
|
|
122
|
+
// Export activity to GPX
|
|
123
|
+
const gpx = activityToGpx(activity)
|
|
124
|
+
await Bun.write('activity.gpx', gpx)
|
|
125
|
+
|
|
126
|
+
// Export to TCX for Strava upload
|
|
127
|
+
const tcx = activityToTcx(activity)
|
|
128
|
+
await Bun.write('activity.tcx', tcx)
|
|
129
|
+
|
|
130
|
+
// Export to CSV for analysis
|
|
131
|
+
const csv = activityToCsv(activity)
|
|
132
|
+
await Bun.write('activity.csv', csv)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Training Analysis
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { calculateTSS, ZoneCalculator, RacePredictor } from 'ts-watches'
|
|
139
|
+
|
|
140
|
+
// Calculate Training Stress Score
|
|
141
|
+
const tss = calculateTSS(activity, { ftp: 250 })
|
|
142
|
+
|
|
143
|
+
// Analyze zones
|
|
144
|
+
const zones = new ZoneCalculator({ maxHR: 185, restingHR: 50, ftp: 250 })
|
|
145
|
+
const zoneAnalysis = zones.analyzeActivity(activity)
|
|
146
|
+
|
|
147
|
+
// Predict race times
|
|
148
|
+
const predictor = new RacePredictor()
|
|
149
|
+
const predictions = predictor.predictFromPerformance(5000, 20 * 60) // 5K in 20min
|
|
150
|
+
console.log(`Predicted marathon: ${predictions.marathon}`)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Cloud Integration
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { GarminActivityApiClient, GarminConnectClient, StravaClient } from 'ts-watches'
|
|
157
|
+
|
|
158
|
+
// Garmin Activity API (official, OAuth 2.0 PKCE, push notifications).
|
|
159
|
+
// The athlete approves on Garmin's own site and can revoke at any time.
|
|
160
|
+
const garmin = new GarminActivityApiClient({
|
|
161
|
+
clientId: process.env.GARMIN_CLIENT_ID!,
|
|
162
|
+
clientSecret: process.env.GARMIN_CLIENT_SECRET!,
|
|
163
|
+
redirectUri: 'https://example.com/garmin/callback',
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const { verifier, challenge } = createPkcePair()
|
|
167
|
+
const url = garmin.buildAuthorizationUrl({ state, challenge }) // send the athlete here
|
|
168
|
+
const tokens = await garmin.exchangeCode(code, verifier) // on the callback
|
|
169
|
+
const userId = await garmin.getUserId(tokens.accessToken) // the key push notifications carry
|
|
170
|
+
|
|
171
|
+
// Garmin Connect (unofficial; needs the athlete's password, breaks under 2FA)
|
|
172
|
+
const legacy = new GarminConnectClient()
|
|
173
|
+
await legacy.login('email@example.com', 'password')
|
|
174
|
+
const activities = await legacy.getActivities(new Date('2024-01-01'))
|
|
175
|
+
|
|
176
|
+
// Strava
|
|
177
|
+
const strava = new StravaClient({
|
|
178
|
+
clientId: 'your-client-id',
|
|
179
|
+
clientSecret: 'your-client-secret',
|
|
180
|
+
})
|
|
181
|
+
const authUrl = strava.getAuthorizationUrl('http://localhost:3000/callback')
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Build Workouts
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { WorkoutBuilder, workoutTemplates } from 'ts-watches'
|
|
188
|
+
|
|
189
|
+
// Use a template
|
|
190
|
+
const intervals = workoutTemplates.vo2maxIntervals({ ftp: 250 })
|
|
191
|
+
|
|
192
|
+
// Or build custom workout
|
|
193
|
+
const workout = new WorkoutBuilder('Custom Threshold')
|
|
194
|
+
.warmup({ duration: 600, targetPower: { min: 100, max: 150 } })
|
|
195
|
+
.interval({ duration: 1200, targetPower: { min: 240, max: 260 } })
|
|
196
|
+
.recovery({ duration: 300, targetPower: { min: 100, max: 130 } })
|
|
197
|
+
.repeat(4)
|
|
198
|
+
.cooldown({ duration: 600, targetPower: { min: 100, max: 130 } })
|
|
199
|
+
.build()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Real-time Data
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
import { createLiveTracking, createBleScanner } from 'ts-watches'
|
|
206
|
+
|
|
207
|
+
// Live tracking
|
|
208
|
+
const tracker = createLiveTracking({
|
|
209
|
+
updateInterval: 5000,
|
|
210
|
+
onUpdate: (session) => console.log(`Distance: ${session.totalDistance}m`),
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
tracker.start('Morning Run')
|
|
214
|
+
tracker.updatePosition({ lat: 37.7749, lng: -122.4194, altitude: 10 })
|
|
215
|
+
|
|
216
|
+
// BLE sensors
|
|
217
|
+
const ble = createBleScanner()
|
|
218
|
+
await ble.startScanning()
|
|
219
|
+
ble.on('data', (device, data) => {
|
|
220
|
+
if (data.type === 'heart_rate') {
|
|
221
|
+
console.log(`HR: ${data.data.heartRate} bpm`)
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## CLI
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Detect connected watches
|
|
230
|
+
watch detect
|
|
231
|
+
|
|
232
|
+
# Download all data from connected watch
|
|
233
|
+
watch download
|
|
234
|
+
|
|
235
|
+
# Download to specific directory
|
|
236
|
+
watch download --output ./my-data
|
|
237
|
+
|
|
238
|
+
# Download only activities from the last week
|
|
239
|
+
watch download --activities --since 2024-01-01
|
|
240
|
+
|
|
241
|
+
# Parse a single FIT file
|
|
242
|
+
watch parse /path/to/activity.fit
|
|
243
|
+
|
|
244
|
+
# Parse and output as JSON
|
|
245
|
+
watch parse /path/to/activity.fit --format json
|
|
246
|
+
|
|
247
|
+
# Watch for device connection and auto-download
|
|
248
|
+
watch watch
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Supported Data Types
|
|
252
|
+
|
|
253
|
+
### Activities
|
|
254
|
+
|
|
255
|
+
- Running (treadmill, trail, track)
|
|
256
|
+
- Cycling (road, mountain, gravel, indoor)
|
|
257
|
+
- Swimming (pool, open water)
|
|
258
|
+
- Hiking, Walking
|
|
259
|
+
- Strength training, Cardio, HIIT
|
|
260
|
+
- Multisport (triathlon)
|
|
261
|
+
- And 50+ more sport types
|
|
262
|
+
|
|
263
|
+
### Health Metrics
|
|
264
|
+
|
|
265
|
+
| Metric | Description |
|
|
266
|
+
|--------|-------------|
|
|
267
|
+
| Heart Rate | Continuous monitoring, resting HR, zones |
|
|
268
|
+
| Sleep | Duration, stages (light, deep, REM), score |
|
|
269
|
+
| Stress | Stress levels throughout the day |
|
|
270
|
+
| Body Battery | Energy levels based on HRV |
|
|
271
|
+
| SpO2 | Blood oxygen saturation |
|
|
272
|
+
| Respiration | Breathing rate |
|
|
273
|
+
| HRV | Heart rate variability (RMSSD, SDRR) |
|
|
274
|
+
| Steps | Daily count, goals, intensity minutes |
|
|
275
|
+
|
|
276
|
+
### Training Metrics
|
|
277
|
+
|
|
278
|
+
| Metric | Description |
|
|
279
|
+
|--------|-------------|
|
|
280
|
+
| TSS | Training Stress Score |
|
|
281
|
+
| IF | Intensity Factor |
|
|
282
|
+
| NP | Normalized Power |
|
|
283
|
+
| ATL | Acute Training Load |
|
|
284
|
+
| CTL | Chronic Training Load (Fitness) |
|
|
285
|
+
| TSB | Training Stress Balance (Form) |
|
|
286
|
+
| TRIMP | Training Impulse |
|
|
287
|
+
|
|
288
|
+
## Device Setup
|
|
289
|
+
|
|
290
|
+
### Garmin
|
|
291
|
+
|
|
292
|
+
1. Connect your watch via USB
|
|
293
|
+
2. On the watch: **Settings > System > USB Mode > Mass Storage**
|
|
294
|
+
3. Close Garmin Express (it locks the device)
|
|
295
|
+
4. The watch appears as `/Volumes/GARMIN` on macOS
|
|
296
|
+
|
|
297
|
+
### Polar
|
|
298
|
+
|
|
299
|
+
1. Export data from Polar Flow web interface
|
|
300
|
+
2. Or use Polar's data export feature on the device
|
|
301
|
+
|
|
302
|
+
### Apple Watch
|
|
303
|
+
|
|
304
|
+
1. Open Health app on iPhone
|
|
305
|
+
2. Tap profile > Export All Health Data
|
|
306
|
+
3. Extract the ZIP file
|
|
307
|
+
|
|
308
|
+
## API Reference
|
|
309
|
+
|
|
310
|
+
See the [full API documentation](./docs/api.md) for detailed type definitions and method signatures.
|
|
311
|
+
|
|
312
|
+
## Testing
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
bun test
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Changelog
|
|
319
|
+
|
|
320
|
+
Please see our [releases](https://github.com/stacksjs/ts-watches/releases) page for more information on what has changed recently.
|
|
321
|
+
|
|
322
|
+
## Contributing
|
|
323
|
+
|
|
324
|
+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
|
|
325
|
+
|
|
326
|
+
## Community
|
|
327
|
+
|
|
328
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
329
|
+
|
|
330
|
+
[Discussions on GitHub](https://github.com/stacksjs/ts-watches/discussions)
|
|
331
|
+
|
|
332
|
+
For casual chit-chat with others using this package:
|
|
333
|
+
|
|
334
|
+
[Join the Stacks Discord Server](https://stacksjs.com/discord)
|
|
335
|
+
|
|
336
|
+
## Postcardware
|
|
337
|
+
|
|
338
|
+
"Software that is free, but hopes for a postcard." We love receiving postcards from around the world showing where Stacks is being used! We showcase them on our website too.
|
|
339
|
+
|
|
340
|
+
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States
|
|
341
|
+
|
|
342
|
+
## Sponsors
|
|
343
|
+
|
|
344
|
+
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
|
|
345
|
+
|
|
346
|
+
- [JetBrains](https://www.jetbrains.com/)
|
|
347
|
+
- [The Solana Foundation](https://solana.com/)
|
|
348
|
+
|
|
349
|
+
## License
|
|
350
|
+
|
|
351
|
+
The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.
|
|
352
|
+
|
|
353
|
+
Made with 💙
|
|
354
|
+
|
|
355
|
+
<!-- Badges -->
|
|
356
|
+
|
|
357
|
+
<!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/ts-watches/main?style=flat-square
|
|
358
|
+
[codecov-href]: https://codecov.io/gh/stacksjs/ts-watches -->
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Activity, ActivityRecord } from '../types';
|
|
2
|
+
export declare function createPersonalRecordsTracker(existingRecords?: PersonalRecord[]): PersonalRecordsTracker;
|
|
3
|
+
export declare interface PersonalRecord {
|
|
4
|
+
type: RecordType
|
|
5
|
+
value: number
|
|
6
|
+
unit: string
|
|
7
|
+
activityId: string
|
|
8
|
+
activityName?: string
|
|
9
|
+
date: Date
|
|
10
|
+
sport: string
|
|
11
|
+
previousRecord?: {
|
|
12
|
+
value: number
|
|
13
|
+
date: Date
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare interface RecordDefinition {
|
|
17
|
+
type: RecordType
|
|
18
|
+
label: string
|
|
19
|
+
unit: string
|
|
20
|
+
sports: string[]
|
|
21
|
+
extractor: (activity: Activity, records?: ActivityRecord[]) => number | null
|
|
22
|
+
comparator: 'higher' | 'lower'
|
|
23
|
+
distanceMeters?: number
|
|
24
|
+
}
|
|
25
|
+
export type RecordType = | 'longest_distance'
|
|
26
|
+
| 'longest_duration'
|
|
27
|
+
| 'fastest_1k'
|
|
28
|
+
| 'fastest_5k'
|
|
29
|
+
| 'fastest_10k'
|
|
30
|
+
| 'fastest_half_marathon'
|
|
31
|
+
| 'fastest_marathon'
|
|
32
|
+
| 'fastest_100m'
|
|
33
|
+
| 'fastest_400m'
|
|
34
|
+
| 'fastest_1_mile'
|
|
35
|
+
| 'highest_avg_power'
|
|
36
|
+
| 'highest_max_power'
|
|
37
|
+
| 'highest_normalized_power'
|
|
38
|
+
| 'highest_elevation_gain'
|
|
39
|
+
| 'most_calories'
|
|
40
|
+
| 'fastest_avg_pace'
|
|
41
|
+
| 'highest_avg_hr'
|
|
42
|
+
| 'highest_max_hr'
|
|
43
|
+
| 'longest_moving_time'
|
|
44
|
+
| 'best_20min_power'
|
|
45
|
+
| 'best_1hr_power'
|
|
46
|
+
| 'best_5min_power'
|
|
47
|
+
| 'max_speed';
|
|
48
|
+
export declare class PersonalRecordsTracker {
|
|
49
|
+
constructor(existingRecords?: PersonalRecord[]);
|
|
50
|
+
processActivity(activity: Activity): PersonalRecord[];
|
|
51
|
+
processActivities(activities: Activity[]): PersonalRecord[];
|
|
52
|
+
getAllRecords(): PersonalRecord[];
|
|
53
|
+
getRecordsForSport(sport: string): PersonalRecord[];
|
|
54
|
+
getRecord(sport: string, type: RecordType): PersonalRecord | undefined;
|
|
55
|
+
formatRecordValue(record: PersonalRecord): string;
|
|
56
|
+
toJSON(): PersonalRecord[];
|
|
57
|
+
static fromJSON(data: PersonalRecord[]): PersonalRecordsTracker;
|
|
58
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Activity } from '../types';
|
|
2
|
+
export declare function createRacePredictor(): RacePredictor;
|
|
3
|
+
// Standard race distances in meters
|
|
4
|
+
export declare const RACE_DISTANCES: {
|
|
5
|
+
'1K': 1000;
|
|
6
|
+
'1 Mile': 1609.34;
|
|
7
|
+
'5K': 5000;
|
|
8
|
+
'10K': 10000;
|
|
9
|
+
'15K': 15000;
|
|
10
|
+
'Half Marathon': 21097.5;
|
|
11
|
+
'Marathon': 42195;
|
|
12
|
+
'50K': 50000;
|
|
13
|
+
'100K': 100000
|
|
14
|
+
};
|
|
15
|
+
export declare interface RacePrediction {
|
|
16
|
+
distance: number
|
|
17
|
+
distanceName: string
|
|
18
|
+
predictedTime: number
|
|
19
|
+
predictedPace: number
|
|
20
|
+
confidence: 'high' | 'medium' | 'low'
|
|
21
|
+
}
|
|
22
|
+
export declare interface PredictorInput {
|
|
23
|
+
recentActivities: Activity[]
|
|
24
|
+
personalRecords?: Map<number, number>
|
|
25
|
+
vo2max?: number
|
|
26
|
+
age?: number
|
|
27
|
+
gender?: 'male' | 'female'
|
|
28
|
+
}
|
|
29
|
+
export declare interface FitnessEstimate {
|
|
30
|
+
vo2max: number
|
|
31
|
+
vdot: number
|
|
32
|
+
equivalentMarathon: number
|
|
33
|
+
fitnessAge: number
|
|
34
|
+
}
|
|
35
|
+
export declare class RacePredictor {
|
|
36
|
+
predictFromPerformance(distance: number): RacePrediction[];
|
|
37
|
+
predictFromActivities(activities: Activity[], targetDistances?: number[]): RacePrediction[];
|
|
38
|
+
estimateVO2max(distance: number, time: number): number;
|
|
39
|
+
estimateVDOT(distance: number, time: number): number;
|
|
40
|
+
estimateFitness(activities: Activity[], age?: number): FitnessEstimate;
|
|
41
|
+
getTrainingPaces(vdot: number): {
|
|
42
|
+
easy: {
|
|
43
|
+
min: number
|
|
44
|
+
max: number
|
|
45
|
+
}
|
|
46
|
+
marathon: number
|
|
47
|
+
threshold: number
|
|
48
|
+
interval: number
|
|
49
|
+
repetition: number
|
|
50
|
+
};
|
|
51
|
+
formatTime(seconds: number): string;
|
|
52
|
+
formatPace(secondsPerKm: number): string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Activity, ActivityRecord } from '../types';
|
|
2
|
+
export declare function createRunningDynamicsAnalyzer(): RunningDynamicsAnalyzer;
|
|
3
|
+
export declare interface RunningDynamicsMetrics {
|
|
4
|
+
groundContactTime?: {
|
|
5
|
+
avg: number
|
|
6
|
+
min: number
|
|
7
|
+
max: number
|
|
8
|
+
}
|
|
9
|
+
groundContactBalance?: {
|
|
10
|
+
avg: number
|
|
11
|
+
left: number
|
|
12
|
+
right: number
|
|
13
|
+
}
|
|
14
|
+
strideLength?: {
|
|
15
|
+
avg: number
|
|
16
|
+
min: number
|
|
17
|
+
max: number
|
|
18
|
+
}
|
|
19
|
+
verticalOscillation?: {
|
|
20
|
+
avg: number
|
|
21
|
+
min: number
|
|
22
|
+
max: number
|
|
23
|
+
}
|
|
24
|
+
verticalRatio?: {
|
|
25
|
+
avg: number
|
|
26
|
+
min: number
|
|
27
|
+
max: number
|
|
28
|
+
}
|
|
29
|
+
cadence?: {
|
|
30
|
+
avg: number
|
|
31
|
+
min: number
|
|
32
|
+
max: number
|
|
33
|
+
}
|
|
34
|
+
stanceTimeBalance?: number
|
|
35
|
+
runningPowerEstimate?: number
|
|
36
|
+
}
|
|
37
|
+
export declare interface RunningFormAnalysis {
|
|
38
|
+
metrics: RunningDynamicsMetrics
|
|
39
|
+
formScore: number
|
|
40
|
+
insights: FormInsight[]
|
|
41
|
+
recommendations: string[]
|
|
42
|
+
}
|
|
43
|
+
export declare interface FormInsight {
|
|
44
|
+
metric: string
|
|
45
|
+
status: 'good' | 'warning' | 'needs_attention'
|
|
46
|
+
message: string
|
|
47
|
+
value: number
|
|
48
|
+
optimalRange: {
|
|
49
|
+
min: number
|
|
50
|
+
max: number
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export declare interface ExtendedActivityRecord extends ActivityRecord {
|
|
54
|
+
groundContactTime?: number
|
|
55
|
+
groundContactBalance?: number
|
|
56
|
+
strideLength?: number
|
|
57
|
+
verticalOscillation?: number
|
|
58
|
+
verticalRatio?: number
|
|
59
|
+
stanceTimePercent?: number
|
|
60
|
+
stanceTime?: number
|
|
61
|
+
}
|
|
62
|
+
export declare class RunningDynamicsAnalyzer {
|
|
63
|
+
calculateMetrics(records: ExtendedActivityRecord[]): RunningDynamicsMetrics;
|
|
64
|
+
analyzeForm(activity: Activity, athleteLevel?: 'elite' | 'recreational'): RunningFormAnalysis;
|
|
65
|
+
calculateEfficiency(activity: Activity): number | null;
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Activity } from '../types';
|
|
2
|
+
export declare function createTrainingLoadCalculator(config?: TrainingLoadConfig): TrainingLoadCalculator;
|
|
3
|
+
export declare interface TrainingLoadMetrics {
|
|
4
|
+
tss: number
|
|
5
|
+
atl: number
|
|
6
|
+
ctl: number
|
|
7
|
+
tsb: number
|
|
8
|
+
ifactor: number
|
|
9
|
+
rampRate: number
|
|
10
|
+
}
|
|
11
|
+
export declare interface DailyTrainingLoad {
|
|
12
|
+
date: Date
|
|
13
|
+
tss: number
|
|
14
|
+
atl: number
|
|
15
|
+
ctl: number
|
|
16
|
+
tsb: number
|
|
17
|
+
}
|
|
18
|
+
export declare interface TrainingLoadConfig {
|
|
19
|
+
ftp?: number
|
|
20
|
+
lthr?: number
|
|
21
|
+
maxHr?: number
|
|
22
|
+
restingHr?: number
|
|
23
|
+
atlDecay?: number
|
|
24
|
+
ctlDecay?: number
|
|
25
|
+
}
|
|
26
|
+
export declare class TrainingLoadCalculator {
|
|
27
|
+
constructor(config?: TrainingLoadConfig);
|
|
28
|
+
calculateTSS(activity: Activity): number;
|
|
29
|
+
calculateIntensityFactor(activity: Activity): number;
|
|
30
|
+
calculateTrainingLoad(activities: Activity[], startDate?: Date, endDate?: Date): DailyTrainingLoad[];
|
|
31
|
+
getCurrentMetrics(activities: Activity[]): TrainingLoadMetrics;
|
|
32
|
+
getTrainingRecommendation(metrics: TrainingLoadMetrics): {
|
|
33
|
+
status: 'fresh' | 'optimal' | 'tired' | 'overtrained'
|
|
34
|
+
recommendation: string
|
|
35
|
+
suggestedTSS: {
|
|
36
|
+
min: number
|
|
37
|
+
max: number
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Activity } from '../types';
|
|
2
|
+
export declare function createZoneCalculator(config: ZoneConfig): ZoneCalculator;
|
|
3
|
+
/**
|
|
4
|
+
* Estimate max heart rate by age
|
|
5
|
+
*/
|
|
6
|
+
export declare function estimateMaxHrByAge(age: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Estimate LTHR from max HR
|
|
9
|
+
*/
|
|
10
|
+
export declare function estimateLthrFromMaxHr(maxHr: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate heart rate reserve
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculateHrReserve(maxHr: number, restingHr: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Calculate target HR using Karvonen formula
|
|
17
|
+
*/
|
|
18
|
+
export declare function calculateTargetHr(maxHr: number, restingHr: number, intensity: number): number;
|
|
19
|
+
export declare interface Zone {
|
|
20
|
+
name: string
|
|
21
|
+
min: number
|
|
22
|
+
max: number
|
|
23
|
+
color?: string
|
|
24
|
+
}
|
|
25
|
+
export declare interface ZoneConfig {
|
|
26
|
+
heartRate?: {
|
|
27
|
+
maxHr: number
|
|
28
|
+
restingHr?: number
|
|
29
|
+
method: 'percentage' | 'reserve' | 'lthr'
|
|
30
|
+
lthr?: number
|
|
31
|
+
zones?: Zone[]
|
|
32
|
+
}
|
|
33
|
+
power?: {
|
|
34
|
+
ftp: number
|
|
35
|
+
zones?: Zone[]
|
|
36
|
+
}
|
|
37
|
+
pace?: {
|
|
38
|
+
thresholdPace: number
|
|
39
|
+
zones?: Zone[]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export declare interface ZoneDistribution {
|
|
43
|
+
zone: Zone
|
|
44
|
+
seconds: number
|
|
45
|
+
percentage: number
|
|
46
|
+
}
|
|
47
|
+
export declare interface ZoneAnalysis {
|
|
48
|
+
heartRate?: ZoneDistribution[]
|
|
49
|
+
power?: ZoneDistribution[]
|
|
50
|
+
pace?: ZoneDistribution[]
|
|
51
|
+
summary: {
|
|
52
|
+
timeInZ1: number
|
|
53
|
+
timeInZ2: number
|
|
54
|
+
timeInZ3: number
|
|
55
|
+
timeInZ4: number
|
|
56
|
+
timeInZ5: number
|
|
57
|
+
polarizedIndex?: number
|
|
58
|
+
intensityDistribution: 'polarized' | 'pyramidal' | 'threshold' | 'unknown'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export declare class ZoneCalculator {
|
|
62
|
+
constructor(config: ZoneConfig);
|
|
63
|
+
getHeartRateZones(): Zone[];
|
|
64
|
+
getPowerZones(): Zone[];
|
|
65
|
+
getPaceZones(): Zone[];
|
|
66
|
+
analyzeActivity(activity: Activity): ZoneAnalysis;
|
|
67
|
+
getZoneForValue(value: number, type: 'heartRate' | 'power' | 'pace'): Zone | null;
|
|
68
|
+
formatTime(seconds: number): string;
|
|
69
|
+
}
|