-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
45 lines (38 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import harmonics from './harmonics/index.js'
const tidePredictionFactory = (constituents, options) => {
const harmonicsOptions = {
harmonicConstituents: constituents,
phaseKey: 'phase_GMT',
offset: false
}
if (typeof options !== 'undefined') {
Object.keys(harmonicsOptions).forEach((key) => {
if (typeof options[key] !== 'undefined') {
harmonicsOptions[key] = options[key]
}
})
}
const tidePrediction = {
getTimelinePrediction: ({ start, end }) => {
return harmonics(harmonicsOptions)
.setTimeSpan(start, end)
.prediction()
.getTimelinePrediction()
},
getExtremesPrediction: ({ start, end, labels, offsets, timeFidelity }) => {
return harmonics(harmonicsOptions)
.setTimeSpan(start, end)
.prediction({ timeFidelity })
.getExtremesPrediction(labels, offsets)
},
getWaterLevelAtTime: ({ time }) => {
const endDate = new Date(time.getTime() + 10 * 60 * 1000)
return harmonics(harmonicsOptions)
.setTimeSpan(time, endDate)
.prediction()
.getTimelinePrediction()[0]
}
}
return tidePrediction
}
export default tidePredictionFactory