Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Updating Synthetic Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
harshita-adsk committed Mar 29, 2021
1 parent e9c1439 commit f8d0bfb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client/data/Hyperion.Data.Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DataView extends EventSource {
/**
*
* Constructs an instance of DataView object. This method should not be used
* directly. A DataView object should be created through {@link Autodesk.DataVisualization.Data.DataStore#createView} method of DataStore.
* directly. A DataView object should be created through {@link DataStore#createView} method of DataStore.
* @param {DataStore} dataStore The owning DataStore object
*/
constructor(dataStore) {
Expand Down Expand Up @@ -503,7 +503,7 @@ class DataStore extends EventSource {

/**
* Gets a map of all uninque properties from all the deviceModels in the datastore.
* @returns {Map.<string,DeviceProperty>} Map of all the properties across all devicesModels in a {@link Autodesk.DataVisualization.Data.DataStore} object.
* @returns {Map.<string,DeviceProperty>} Map of all the properties across all devicesModels in a {@link DataStore} object.
*/
getPropertiesFromDataStore() {
const deviceModels = Object.values(this._deviceModels);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forge-dataviz-iot-data-modules",
"version": "0.1.2",
"version": "0.1.3",
"description": "IoT data modules used by https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app",
"author": "Autodesk Inc",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions server/gateways/Hyperion.Server.CsvGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const { loadJSONFile } = require("./FileUtility.js")
class CsvDataGateway extends DataGateway {
/**
*
* @param {string} deviceModelFile JSON file, please refer ./synthetic-data/device-models.json
* @param {string} deviceFile JSON file, please refer ./synthetic-data/devices.json
* @param {string} deviceModelFile JSON file, please refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/device-models.json
* @param {string} deviceFile JSON file, please refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/devices.json
* @param {string} dataFile
*/
constructor(
Expand Down
32 changes: 24 additions & 8 deletions server/gateways/Hyperion.Server.SyntheticGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//
const DataGateway = require("./Hyperion.Server.DataGateway");
const tweenFunctions = require("tween-functions");
const config = require("./synthetic-data/config");
const { loadJSONFile } = require("./FileUtility.js");

const STARTDATE = new Date("2020-01-01");

Expand All @@ -33,7 +33,13 @@ function weekNum(time) {
}

class Synthetic {
constructor() { }
/**
*
* @param {string} configFile File path to config file defining the data stops and range values used to generate synthetic data. For an example, refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/config.js
*/
constructor(configFile) {
this.config = require(configFile);
}

nextStop(stops, index, direction) {
let nextIndex = index + 1 * direction;
Expand All @@ -58,15 +64,15 @@ class Synthetic {
_getStops(sensorType, time) {
let week = weekNum(time);
let day = time.getDay() % 7;
let sensorConfig = config["Strategy"][sensorType] || config["Strategy"]["Temperature"];
let sensorConfig = this.config["Strategy"][sensorType] || this.config["Strategy"]["Temperature"];
return sensorConfig[day][week];
}

value(sensorType, currentTime, interval) {
let hour = this._timeToDecimal(currentTime);
let self = this;
let stops = this._getStops(sensorType, currentTime);
let { min, max } = config["Range"][sensorType] || config["Range"]["Temperature"];
let { min, max } = this.config["Range"][sensorType] || this.config["Range"]["Temperature"];

function tweenValue(hour, start, end) {
let duration = end[0] - start[0];
Expand Down Expand Up @@ -107,24 +113,34 @@ class Synthetic {
* @alias Autodesk.DataVisualization.Data.SyntheticGateway
*/
class SyntheticGateway extends DataGateway {
constructor() {
/**
*
* @param {string} deviceModelFile File path to JSON file containing device model information. For an example, refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/device-models.json
* @param {string} deviceFile File path to JSON file containing device information. For an example, refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/devices.json
* @param {string} configFile File path to config file defining the data stops and range values used to generate synthetic data. For an example, refer to https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app/blob/main/server/gateways/synthetic-data/config.js
*/
constructor(deviceModelFile, deviceFile, configFile) {
super("SyntheticGateway");

this.deviceModelFile = deviceModelFile;
this.deviceFile = deviceFile;
this.configFile = configFile;
}

async getDeviceModels() {
return require("./synthetic-data/device-models.json");
return loadJSONFile(this.deviceModelFile);
}

async getDevicesInModel(deviceModelId) {
const devices = require("./synthetic-data/devices.json");
const devices = await loadJSONFile(this.deviceFile);
return devices.find((device) => device.deviceModelId === deviceModelId);
}

async getAggregates(deviceId, propertyId, startSecond, endSecond, resolution) {
deviceId; // Not used for synthetic data generation.
propertyId; // Not used for synthetic data generation.

let synthetic = new Synthetic();
let synthetic = new Synthetic(this.configFile);

// Just sample data, no need to validate existence of device/property IDs.
const totalSeconds = Math.abs(endSecond - startSecond);
Expand Down

0 comments on commit f8d0bfb

Please sign in to comment.