Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new changes - Adroit JSON to JST #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Ethan-beca
Copy link

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

Copy link
Contributor

@abonstu abonstu left a comment

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.

*/
export class AdroitVWJsonConverter extends Converter {
convert(input: Buffer): JtsDocument {
const series1 = new TimeSeries({ name: 'frequency' });
Copy link
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

//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
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)

*/
export class AdroitVWJsonConverter extends Converter {
convert(input: Buffer): JtsDocument {
const series1 = new TimeSeries({ name: 'frequency' });
Copy link
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
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
Copy link
Contributor

abonstu commented Nov 12, 2024

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