Skip to content

Commit bfed37d

Browse files
committed
Add timeFidelity to getTimelinePrediction()
1 parent 50135e3 commit bfed37d

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const timeline = getTimelinePrediction({
5555
lat: 26.7,
5656
lon: -80.05,
5757
start: new Date('2025-12-19T00:00:00-05:00'),
58-
end: new Date('2025-12-19T01:00:00-05:00')
58+
end: new Date('2025-12-19T01:00:00-05:00'),
59+
timeFidelity: 5 * 60 // seconds, defaults to `10 * 60`
5960
})
6061

6162
console.log(timeline)
@@ -67,13 +68,11 @@ console.log(timeline)
6768
// // ...
6869
// },
6970
// timeline: [
70-
// { time: 2025-12-19T05:00:00.000Z, hour: 0, level: 0.07269280868130157 },
71-
// { time: 2025-12-19T05:10:00.000Z, hour: 0.16666666666666666, level: 0.054517202710722634 },
72-
// { time: 2025-12-19T05:20:00.000Z, hour: 0.3333333333333333, level: 0.0387568479105333 },
73-
// { time: 2025-12-19T05:30:00.000Z, hour: 0.5, level: 0.025594147655661648 },
74-
// { time: 2025-12-19T05:40:00.000Z, hour: 0.6666666666666666, level: 0.015185512178782279 },
75-
// { time: 2025-12-19T05:50:00.000Z, hour: 0.8333333333333334, level: 0.00765764296563648 },
76-
// { time: 2025-12-19T06:00:00.000Z, hour: 1, level: 0.0031046829237997287 }
71+
// { time: 2025-12-19T05:00:00.000Z, hour: 0, level: 0.7232836255650095 },
72+
// { time: 2025-12-19T05:06:00.000Z, hour: 0.1, level: 0.7231644154595303 },
73+
// { time: 2025-12-19T05:12:00.000Z, hour: 0.2, level: 0.7221097788490487 },
74+
// { time: 2025-12-19T05:18:00.000Z, hour: 0.3, level: 0.7201242512580206 },
75+
// // ...
7776
// ]
7877
// }
7978
```

packages/tide-predictor/src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface TidePredictionOptions {
1515
export interface TimeSpan {
1616
start: Date
1717
end: Date
18+
timeFidelity?: number
1819
}
1920

2021
export interface ExtremesInput extends TimeSpan {
@@ -23,7 +24,6 @@ export interface ExtremesInput extends TimeSpan {
2324
low?: string
2425
}
2526
offsets?: ExtremeOffsets
26-
timeFidelity?: number
2727
}
2828

2929
export interface TidePrediction {
@@ -44,10 +44,14 @@ const tidePredictionFactory = (
4444
}
4545

4646
const tidePrediction: TidePrediction = {
47-
getTimelinePrediction: ({ start, end }: TimeSpan): TimelinePoint[] => {
47+
getTimelinePrediction: ({
48+
start,
49+
end,
50+
timeFidelity
51+
}: TimeSpan): TimelinePoint[] => {
4852
return harmonics(harmonicsOptions)
4953
.setTimeSpan(start, end)
50-
.prediction()
54+
.prediction({ timeFidelity })
5155
.getTimelinePrediction()
5256
},
5357

packages/tide-predictor/test/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ describe('Tidal station', () => {
4444
start: startDate,
4545
end: endDate
4646
})
47+
expect(results.length).toBe(37)
48+
expect(results[0].level).toBeCloseTo(-1.34712509, 3)
49+
const lastResult = results.pop()
50+
expect(lastResult?.level).toBeCloseTo(2.85263589, 3)
51+
})
52+
53+
it('it predicts the tides in a timeline with time fidelity', () => {
54+
const results = tidePrediction(mockConstituents).getTimelinePrediction({
55+
start: startDate,
56+
end: endDate,
57+
timeFidelity: 60
58+
})
59+
expect(results.length).toBe(361)
4760
expect(results[0].level).toBeCloseTo(-1.34712509, 3)
4861
const lastResult = results.pop()
4962
expect(lastResult?.level).toBeCloseTo(2.85263589, 3)

0 commit comments

Comments
 (0)