Skip to content

Commit e4b6420

Browse files
committed
Update to latest @neaps/tide-database
1 parent d26c05a commit e4b6420

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

benchmarks/noaa.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mkdir, readFile, writeFile } from 'fs/promises'
33
import { createWriteStream } from 'fs'
44
import { join } from 'path'
55
import { findStation } from 'neaps'
6-
import db from '@neaps/tide-database'
6+
import { stations as db } from '@neaps/tide-database'
77
import createFetch from 'make-fetch-happen'
88

99
process.env.TZ = 'UTC'
@@ -16,7 +16,7 @@ const fetch = createFetch.defaults({
1616
})
1717

1818
const stations = db
19-
.filter((station) => station.source.source_url.includes('noaa.gov'))
19+
.filter((station) => station.source.url.includes('noaa.gov'))
2020
.map((station) => station.source.id)
2121

2222
// Create a directory for test cache
@@ -36,6 +36,7 @@ interface Stat {
3636
p95_abs_dt_min: number
3737
mean_dt_min: number
3838
mae_dh_m: number
39+
mean_dh_m: number
3940
rmse_dh_m: number
4041
bias_dh_m: number
4142
p95_abs_dh_m: number
@@ -163,6 +164,7 @@ for (const id of stations) {
163164
// Height metrics (meters) at matched events
164165
const absDh = dhMeters.map((v) => Math.abs(v))
165166
const mae_dh_m = mean(absDh)
167+
const mean_dh_m = mean(dhMeters)
166168
const rmse_dh_m = Math.sqrt(
167169
dhMeters.reduce((a, b) => a + b * b, 0) / dhMeters.length
168170
)
@@ -183,6 +185,7 @@ for (const id of stations) {
183185
p95_abs_dt_min,
184186
mean_dt_min,
185187
mae_dh_m,
188+
mean_dh_m,
186189
rmse_dh_m,
187190
bias_dh_m,
188191
p95_abs_dh_m
@@ -193,7 +196,7 @@ for (const id of stations) {
193196
// Write stats to file for later analysis
194197
const summary = createWriteStream(join(__dirname, 'noaa.csv'))
195198
summary.write(
196-
'station,type,start_utc,end_utc,events_noaa,events_model,matched,missed,extra,med_abs_dt_min,p95_abs_dt_min,mean_dt_min,mae_dh_m,rmse_dh_m,bias_dh_m,p95_abs_dh_m\n'
199+
'station,type,start_utc,end_utc,events_noaa,events_model,matched,missed,extra,med_abs_dt_min,p95_abs_dt_min,mean_dt_min,mae_dh_m,mean_dh_m,rmse_dh_m,bias_dh_m,p95_abs_dh_m\n'
197200
)
198201

199202
stats.forEach((s) => {
@@ -212,6 +215,7 @@ stats.forEach((s) => {
212215
s.p95_abs_dt_min.toFixed(2),
213216
s.mean_dt_min.toFixed(2),
214217
s.mae_dh_m.toFixed(4),
218+
s.mean_dh_m.toFixed(4),
215219
s.rmse_dh_m.toFixed(4),
216220
s.bias_dh_m.toFixed(4),
217221
s.p95_abs_dh_m.toFixed(4)

packages/neaps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"dependencies": {
3737
"@neaps/tide-predictor": "^0.2.0",
38-
"@neaps/tide-database": "^0.0",
38+
"@neaps/tide-database": "0.1",
3939
"geolib": "^3.3.4"
4040
}
4141
}

packages/neaps/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getDistance } from 'geolib'
2-
import stations, { type Station } from '@neaps/tide-database'
2+
import { stations, type Station } from '@neaps/tide-database'
33
import tidePredictor, {
44
type TimeSpan,
55
type ExtremesInput

packages/neaps/test/index.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import stations from '@neaps/tide-database'
1+
import { stations } from '@neaps/tide-database'
22
import {
33
getExtremesPrediction,
44
nearestStation,
@@ -24,7 +24,7 @@ describe('getExtremesPrediction', () => {
2424
datum: 'MLLW'
2525
})
2626

27-
expect(prediction.station.id).toEqual('us-fl-port-of-palm-beach')
27+
expect(prediction.station.id).toEqual('us/fl/port-of-palm-beach')
2828
expect(prediction.datum).toBe('MLLW')
2929

3030
const { extremes } = prediction
@@ -46,7 +46,7 @@ describe('getTimelinePrediction', () => {
4646
end: new Date('2025-12-19T01:00:00-05:00')
4747
})
4848

49-
expect(timeline.station.id).toEqual('us-fl-port-of-palm-beach')
49+
expect(timeline.station.id).toEqual('us/fl/port-of-palm-beach')
5050
expect(timeline.datum).toBe('MLLW')
5151
expect(timeline.timeline.length).toBe(7) // Every 10 minutes for 1 hour = 7 points
5252
})
@@ -61,7 +61,7 @@ describe('getWaterLevelAtTime', () => {
6161
datum: 'MSL'
6262
})
6363

64-
expect(prediction.station.id).toEqual('us-fl-port-of-palm-beach')
64+
expect(prediction.station.id).toEqual('us/fl/port-of-palm-beach')
6565
expect(prediction.datum).toBe('MSL')
6666
expect(prediction.time).toEqual(new Date('2025-12-19T05:30:00.000Z'))
6767
expect(typeof prediction.level).toBe('number')
@@ -213,16 +213,16 @@ describe('findStation', () => {
213213
})
214214

215215
test('finds station by id', () => {
216-
const station = findStation('us-ma-boston')
216+
const station = findStation('us/ma/boston')
217217
expect(station).toBeDefined()
218-
expect(station.id).toBe('us-ma-boston')
218+
expect(station.id).toBe('us/ma/boston')
219219
expect(station.getExtremesPrediction).toBeDefined()
220220
})
221221

222222
test('finds station by source id', () => {
223223
const station = findStation('8443970')
224224
expect(station).toBeDefined()
225-
expect(station.id).toBe('us-ma-boston')
225+
expect(station.id).toBe('us/ma/boston')
226226
expect(station.getExtremesPrediction).toBeDefined()
227227
})
228228
})
@@ -248,7 +248,7 @@ describe('datum', () => {
248248
})
249249

250250
test('throws error for unavailable datum', () => {
251-
const station = findStation('us-ma-boston')
251+
const station = findStation('us/ma/boston')
252252
expect(() => {
253253
station.getExtremesPrediction({
254254
start: new Date('2025-12-17T00:00:00Z'),

0 commit comments

Comments
 (0)