-
Notifications
You must be signed in to change notification settings - Fork 2
/
getData.ts
38 lines (33 loc) · 1.14 KB
/
getData.ts
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
import axios from 'axios';
import { Coordinates, OpenSenseMapID, RFC3339Date } from '../globalTypes';
/**
* @see https://docs.opensensemap.org/#api-Measurements-getData
*/
export async function getData(senseBoxId: OpenSenseMapID, sensorId: OpenSenseMapID, options?: GetDataOptions): Promise<GetDataResult> {
if (options?.['from-date'] && options['from-date'] instanceof Date) {
options['from-date'] = options['from-date'].toISOString();
}
if (options?.['to-date'] && options['to-date'] instanceof Date) {
options['to-date'] = options['to-date'].toISOString();
}
return (
await axios.get(`https://api.opensensemap.org/boxes/${senseBoxId}/data/${sensorId}`, {
params: options
})
).data;
}
export type GetDataOptions = {
'from-date'?: RFC3339Date | Date;
'to-date'?: RFC3339Date | Date;
outliers?: 'replace' | 'mark';
'outlier-window'?: number;
};
/**
* @linkcode https://github.com/sensebox/openSenseMap-API/blob/2e645bdc4c80e668720b5eaaf384a35d2909569e/packages/models/src/measurement/measurement.js#L154C4-L154C4
*/
export type GetDataResult = {
value: string;
location: Coordinates;
createdAt: RFC3339Date;
isOutlier?: boolean;
}[];