diff --git a/client/data/Hyperion.Data.Storage.js b/client/data/Hyperion.Data.Storage.js index ea6ada6..07e085e 100644 --- a/client/data/Hyperion.Data.Storage.js +++ b/client/data/Hyperion.Data.Storage.js @@ -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) { @@ -503,7 +503,7 @@ class DataStore extends EventSource { /** * Gets a map of all uninque properties from all the deviceModels in the datastore. - * @returns {Map.} Map of all the properties across all devicesModels in a {@link Autodesk.DataVisualization.Data.DataStore} object. + * @returns {Map.} Map of all the properties across all devicesModels in a {@link DataStore} object. */ getPropertiesFromDataStore() { const deviceModels = Object.values(this._deviceModels); diff --git a/package.json b/package.json index 9650946..70ecbd5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/gateways/Hyperion.Server.CsvGateway.js b/server/gateways/Hyperion.Server.CsvGateway.js index 52033ca..082b3f5 100644 --- a/server/gateways/Hyperion.Server.CsvGateway.js +++ b/server/gateways/Hyperion.Server.CsvGateway.js @@ -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( diff --git a/server/gateways/Hyperion.Server.SyntheticGateway.js b/server/gateways/Hyperion.Server.SyntheticGateway.js index 8d9e700..7b0607d 100644 --- a/server/gateways/Hyperion.Server.SyntheticGateway.js +++ b/server/gateways/Hyperion.Server.SyntheticGateway.js @@ -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"); @@ -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; @@ -58,7 +64,7 @@ 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]; } @@ -66,7 +72,7 @@ class Synthetic { 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]; @@ -107,16 +113,26 @@ 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); } @@ -124,7 +140,7 @@ class SyntheticGateway extends DataGateway { 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);