Skip to content

new changes - Adroit JSON to JST#17

Open
Ethan-beca wants to merge 4 commits into
eagle-io:masterfrom
Ethan-beca:master
Open

new changes - Adroit JSON to JST#17
Ethan-beca wants to merge 4 commits into
eagle-io:masterfrom
Ethan-beca:master

Conversation

@Ethan-beca

Copy link
Copy Markdown

this converts the data file from Adroit VW logger from JSON format to eagle JST format.

@abonstu abonstu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers for contributing a converter ethan :)

we encourage converters to be as flexible as possible, i.e. rather than being constrained to a single frequency sensor with a single sample, its useful to have one converter that handles all permutations of a payload format.

Comment thread lib/AdroitVW/adroitvw-converter.ts Outdated
*/
export class AdroitVWJsonConverter extends Converter {
convert(input: Buffer): JtsDocument {
const series1 = new TimeSeries({ name: 'frequency' });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using the 'name' json field to define the timeseries name

Comment thread lib/AdroitVW/adroitvw-converter.ts Outdated
//const timestamp = new Date(record.lastUpdate); // using 'lastUpdate' as timestamp
//const timestamp = new Date(record.lastUpdate * 1000).toLocaleString("en-NZ", { timeZone: "Pacific/Auckland" });
const timestamp_ep = new Date(record.lastUpdate);
const timestamp = new Date(timestamp_ep.getTime() + (12 * 60 * 60 * 1000));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take a look at the sample-with-zone converter (this includes the timezone configured by the user)

Comment thread lib/AdroitVW/adroitvw-converter.ts Outdated
*/
export class AdroitVWJsonConverter extends Converter {
convert(input: Buffer): JtsDocument {
const series1 = new TimeSeries({ name: 'frequency' });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using the 'unit.symbol' json field to define the timeseries units

@Ethan-beca

Copy link
Copy Markdown
Author

Hi Jarrah, thanks for your comments, code has been modified as below:

import { JtsDocument, TimeSeries } from '@eagle-io/timeseries';
import { Converter } from '../../converter';
import moment from 'moment-timezone';

/**

// Parse the input buffer to JSON object
const record = JSON.parse(input.toString());

// Convert the epoch time to a moment object

let timestamp = moment.utc(record.lastUpdate).tz('Pacific/Auckland').toDate();

 // Create a TimeSeries object
const series1 = new TimeSeries({ name: record.name });


// Convert the value to a number
const value = Number(record.value);  

// Insert the time series data
series1.insert({ timestamp, value });

// Return the JTS document
return new JtsDocument({ series: [series1] });

}
}

@abonstu

abonstu commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

please update this pull request with your changes for review.

note: take a look at line 17 of lib/sample-with-zone/sample-with-zone-converter.ts, this demonstrates using the timezone configured on the data source to convert data to UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants