Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/AdroitVW/adroitvw-converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { JtsDocument, TimeSeries } from '@eagle-io/timeseries';
import { Converter } from '../../converter';
import moment from 'moment-timezone';

/**
* Convert the JSON data from Adroit VW Logger
* example: https://adroitplatform.com/api/points/34404/feeds/54553
*/
export class AdroitVWJsonConverter extends Converter {
convert(input: Buffer): JtsDocument {
// 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] });
}
}

18 changes: 18 additions & 0 deletions lib/AdroitVW/test/adroitvw-converter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as fs from 'fs'
import { AdroitVWJsonConverter } from '../AdroitVW-converter'

describe('Unit test for AdroitVWJson', function () {
it('converts sample file', async () => {
const converter = new AdroitVWJsonConverter()
const buff = fs.readFileSync('lib/AdroitVW/test/input.dat')
const result = converter.convert(buff)

// Corrected quotes and numeric timestamp for lastUpdate
expect(result.series[0].first.timestamp).toEqual(new Date('2024-09-16T08:00:00Z'))
expect(result.series[0].values).toEqual([2928.3])

})
})



44 changes: 44 additions & 0 deletions lib/AdroitVW/test/input.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"id": 54553,
"name": "VWS1 Frequency",
"point": 34404,
"creationDate": 1724640746000,
"lastUpdate": 1726430400000,
"value": "2928.3",
"sourceStatus": "ACTIVE",
"path": "Site/dvwt-01-st12429/VWS1 Frequency",
"pathId": "17597/34404/54553/",
"alarmState": "NORMAL",
"alarmMessage": "STATE_NORMAL",
"sourceType": "DEVICE_SENSOR",
"sourceId": 56680,
"contextId": 9138,
"unit": {
"id": 28,
"name": "HERTZ",
"symbol": "Hz",
"readingTypeId": 40,
"system": "SI",
"precision": 1,
"context": null,
"guid": "7c805b6e-a879-11e9-83cd-0a0027000005",
"readingTypeName": "FREQUENCY",
"inUse": true
},
"minimum": null,
"maximum": null,
"trend": "STEADY",
"validity": 30,
"thresholdsEnabled": false,
"originType": "FEED",
"readingType": {
"id": 40,
"name": "FREQUENCY",
"dataType": "NUMERIC",
"size": 1,
"labels": null,
"iconName": null
},
"originId": 54553,
"message": "STATE_NORMAL"
}