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

Commit 9515f11

Browse files
committed
Updating formatting, adding package tags
1 parent be80672 commit 9515f11

11 files changed

+139
-73
lines changed

client/data/Hyperion.Data.Adapter.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ export class AzureDataAdapter extends DataAdapter {
180180
}
181181

182182
async getDevices(deviceModelId) {
183-
let devices = await fetch(`${this._baseName}/api/devices?provider=azure&project=test&model=${deviceModelId}`)
183+
let devices = await fetch(
184+
`${this._baseName}/api/devices?provider=azure&project=test&model=${deviceModelId}`
185+
)
184186
.then((response) => {
185187
if (!response.ok) {
186188
return Promise.reject(response.json());
@@ -271,11 +273,15 @@ export class AzureDataAdapter extends DataAdapter {
271273

272274
if (device.tags.position) {
273275
let p = device.tags.position;
274-
deviceObj.position = new THREE.Vector3(parseFloat(p.x), parseFloat(p.y), parseFloat(p.z));
276+
deviceObj.position = new THREE.Vector3(
277+
parseFloat(p.x),
278+
parseFloat(p.y),
279+
parseFloat(p.z)
280+
);
275281
}
276282
deviceObj.lastActivityTime = new Date(device.lastActivityTime);
277283
}
278-
})
284+
});
279285
});
280286
return deviceModels;
281287
});
@@ -306,7 +312,10 @@ export class AzureDataAdapter extends DataAdapter {
306312
const deviceData = new DeviceData(query.deviceId);
307313
for (let prop of query.propertyIds) {
308314
const aggrValues = new AggregatedValues(query.dateTimeSpan);
309-
aggrValues.tsValues = rawAggregates.timestamps.map((item) => getTimeInEpochSeconds(item));
315+
aggrValues.tsValues = rawAggregates.timestamps.map((item) =>
316+
getTimeInEpochSeconds(item)
317+
);
318+
310319
for (let property of rawAggregates.properties) {
311320
if (property.name === prop + "Count") {
312321
aggrValues.countValues = property.values;
@@ -444,7 +453,12 @@ export class RestApiDataAdapter extends DataAdapter {
444453
device.name = deviceInfo.name;
445454

446455
const p = deviceInfo.position;
447-
device.position = new THREE.Vector3(parseFloat(p.x), parseFloat(p.y), parseFloat(p.z));
456+
device.position = new THREE.Vector3(
457+
parseFloat(p.x),
458+
parseFloat(p.y),
459+
parseFloat(p.z)
460+
);
461+
448462
device.lastActivityTime = deviceInfo.lastActivityTime;
449463
device.deviceModel = deviceModel;
450464
device.sensorTypes = deviceModel.propertyIds;

client/data/Hyperion.Data.DeviceModel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ class DeviceModel {
232232
this._deviceModelId = deviceModelId;
233233
this._adapterId = adapterId;
234234

235-
/** @type {Object.<string, DeviceProperty>}
235+
/** @type {Object.<string, DeviceProperty>}
236236
* The properties belonging to this DeviceModel.
237-
*/
237+
*/
238238
this._properties = {};
239239

240240
/** @type {Object.<string, Device>}

client/data/Hyperion.Data.Storage.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/*
1818
eslint no-unused-vars: [ "error", {
19-
"varsIgnorePattern": "(QueryParam|DataAdapter|DeviceData|DeviceModel)"
19+
"varsIgnorePattern": "(QueryParam|DataAdapter|DeviceModel|DeviceProperty)"
2020
}]
2121
*/
2222

@@ -484,7 +484,7 @@ class DataStore extends EventSource {
484484
const deviceModel = this._deviceModels[deviceModelId];
485485
return deviceModel.adapterId;
486486
} else {
487-
return "RestApiDataAdapter"
487+
return "RestApiDataAdapter";
488488
}
489489
}
490490

@@ -512,11 +512,10 @@ class DataStore extends EventSource {
512512
getPropertiesFromDataStore() {
513513
const deviceModels = Object.values(this._deviceModels);
514514
const nestedList = deviceModels.map((dm) => Object.values(dm.properties)).flat();
515-
let filteredMap = new Map(nestedList.map(obj => [`${obj.id}`, obj]));
515+
let filteredMap = new Map(nestedList.map((obj) => [`${obj.id}`, obj]));
516516
return filteredMap;
517517
}
518518

519-
520519
get adapters() {
521520
return this._dataAdapters;
522521
}

client/data/Hyperion.Data.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import {
2222
RestApiDataAdapter,
2323
} from "./Hyperion.Data.Adapter.js";
2424

25-
import { PropertyValue, AggregatedValues, PropertyData, DeviceData } from "./Hyperion.Data.DataModel.js";
25+
import {
26+
PropertyValue,
27+
AggregatedValues,
28+
PropertyData,
29+
DeviceData,
30+
} from "./Hyperion.Data.DataModel.js";
2631

2732
import { Device, DeviceProperty, DeviceModel } from "./Hyperion.Data.DeviceModel.js";
2833

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"name": "forge-dataviz-iot-data-modules",
3-
"version": "0.1.9",
3+
"version": "0.1.10",
44
"description": "IoT data modules used by https://github.com/Autodesk-Forge/forge-dataviz-iot-reference-app",
55
"author": "Autodesk Inc",
66
"license": "Apache-2.0",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/Autodesk-Forge/forge-dataviz-iot-data-modules"
1010
},
11+
"keywords": [
12+
"autodesk",
13+
"forge",
14+
"iot",
15+
"js"
16+
],
1117
"dependencies": {
1218
"@azure/arm-iothub": "^4.0.0",
1319
"@azure/digital-twins-core": "^1.0.3",
@@ -38,4 +44,4 @@
3844
"webpack": "^5.11.0",
3945
"webpack-cli": "^4.5.0"
4046
}
41-
}
47+
}

server/gateways/FileUtility.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const FS = require('fs')
1+
const FS = require("fs");
22

33
var FileUtility = {};
44

@@ -14,14 +14,14 @@ FileUtility.loadFile = async function (file) {
1414
});
1515
};
1616

17-
FileUtility.loadJSONFile = async function(file) {
17+
FileUtility.loadJSONFile = async function (file) {
1818
let data = await FileUtility.loadFile(file);
1919
try {
2020
return JSON.parse(data);
2121
} catch (e) {
2222
console.error("Unable to parse file data. " + e);
2323
return {};
2424
}
25-
}
25+
};
2626

27-
module.exports = FileUtility;
27+
module.exports = FileUtility;

server/gateways/Hyperion.Server.AzureGateway.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
2525
const { IotHubClient } = require("@azure/arm-iothub");
2626
const { Registry, Twin } = require("azure-iothub");
2727
const Q = require("q");
28-
const { loadJSONFile } = require("./FileUtility.js")
28+
const { loadJSONFile } = require("./FileUtility.js");
2929

30-
function _interopDefault(ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
30+
function _interopDefault(ex) {
31+
return ex && typeof ex === "object" && "default" in ex ? ex["default"] : ex;
32+
}
3133

3234
const fetch = _interopDefault(require("node-fetch"));
3335

@@ -97,7 +99,11 @@ class AzureGateway extends DataGateway {
9799
process.env.AZURE_TENANT_ID
98100
);
99101

100-
const client = new IotHubClient(this.authRes.credentials, process.env.AZURE_SUBSCRIPTION_ID);
102+
const client = new IotHubClient(
103+
this.authRes.credentials,
104+
process.env.AZURE_SUBSCRIPTION_ID
105+
);
106+
101107
this.client = client;
102108
}
103109
return this.authRes;
@@ -132,7 +138,9 @@ class AzureGateway extends DataGateway {
132138
*/
133139
getRegistry() {
134140
if (!this.registry) {
135-
this.registry = Registry.fromConnectionString(process.env.AZURE_IOT_HUB_CONNECTION_STRING);
141+
this.registry = Registry.fromConnectionString(
142+
process.env.AZURE_IOT_HUB_CONNECTION_STRING
143+
);
136144
}
137145
return this.registry;
138146
}

server/gateways/Hyperion.Server.CsvGateway.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Q = require("q");
2020
const Path = require("path");
2121
const ES = require("event-stream");
2222
const timestring = require("timestring");
23-
const { loadJSONFile } = require("./FileUtility.js")
23+
const { loadJSONFile } = require("./FileUtility.js");
2424

2525
/**
2626
* @classdesc A data gateway that supplies CSV data from local
@@ -74,7 +74,7 @@ class CsvDataGateway extends DataGateway {
7474
timestamps: [],
7575
min: [],
7676
max: [],
77-
avg: []
77+
avg: [],
7878
});
7979
return defer.promise;
8080
}
@@ -96,34 +96,36 @@ class CsvDataGateway extends DataGateway {
9696

9797
const stream = FS.createReadStream(filePath)
9898
.pipe(ES.split())
99-
.pipe(ES.mapSync((line) => {
100-
let parts = line.split(self.delimiter);
101-
if (lineNumber++ == 0) {
102-
timeIndex = parts.findIndex((item) => item.trim() == self.timeStampColumn);
103-
propIndex = parts.findIndex((item) => item.trim() == propertyId);
104-
} else {
105-
let time = Math.round(new Date(parts[timeIndex].trim()).getTime() / 1000);
106-
if (time >= start && time <= end) {
107-
let value = parseFloat(parts[propIndex]);
108-
let index = Math.round((time - start) / resolution);
109-
110-
if (results[index]) {
111-
let [sum, count] = results[index];
112-
results[index] = [sum + value, count + 1];
113-
114-
min[index] = Math.min(min[index], value);
115-
max[index] = Math.max(max[index], value);
116-
counts[index] = count;
117-
} else {
118-
results[index] = [value, 1];
119-
120-
min[index] = value;
121-
max[index] = value;
122-
counts[index] = index;
99+
.pipe(
100+
ES.mapSync((line) => {
101+
let parts = line.split(self.delimiter);
102+
if (lineNumber++ == 0) {
103+
timeIndex = parts.findIndex((item) => item.trim() == self.timeStampColumn);
104+
propIndex = parts.findIndex((item) => item.trim() == propertyId);
105+
} else {
106+
let time = Math.round(new Date(parts[timeIndex].trim()).getTime() / 1000);
107+
if (time >= start && time <= end) {
108+
let value = parseFloat(parts[propIndex]);
109+
let index = Math.round((time - start) / resolution);
110+
111+
if (results[index]) {
112+
let [sum, count] = results[index];
113+
results[index] = [sum + value, count + 1];
114+
115+
min[index] = Math.min(min[index], value);
116+
max[index] = Math.max(max[index], value);
117+
counts[index] = count;
118+
} else {
119+
results[index] = [value, 1];
120+
121+
min[index] = value;
122+
max[index] = value;
123+
counts[index] = index;
124+
}
123125
}
124126
}
125-
}
126-
}))
127+
})
128+
)
127129
.on("error", (err) => {
128130
defer.reject("something wrong." + err);
129131
})
@@ -149,7 +151,7 @@ class CsvDataGateway extends DataGateway {
149151
max,
150152
count: counts,
151153
sum: sums,
152-
avg: aggregate
154+
avg: aggregate,
153155
});
154156
});
155157

server/gateways/Hyperion.Server.SyntheticGateway.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class Synthetic {
6464
_getStops(sensorType, time) {
6565
let week = weekNum(time);
6666
let day = time.getDay() % 7;
67-
let sensorConfig = this.config["Strategy"][sensorType] || this.config["Strategy"]["Temperature"];
67+
let sensorConfig =
68+
this.config["Strategy"][sensorType] || this.config["Strategy"]["Temperature"];
6869
return sensorConfig[day][week];
6970
}
7071

shared/TaskQueue.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var TaskQueue = function (cocurrent, name, hideProgress) {
66
this.hideProgress = hideProgress;
77
};
88

9-
109
TaskQueue.prototype.addTask = function (task, atBeginning) {
1110
if (atBeginning) {
1211
this.queue.unshift(task);
@@ -15,7 +14,14 @@ TaskQueue.prototype.addTask = function (task, atBeginning) {
1514
}
1615

1716
if (!this.hideProgress) {
18-
console.log("TaskAdd Queue:", this.name, "Length:", this.queue.length, "OnGoing:", this.onGoingTask);
17+
console.log(
18+
"TaskAdd Queue:",
19+
this.name,
20+
"Length:",
21+
this.queue.length,
22+
"OnGoing:",
23+
this.onGoingTask
24+
);
1925
}
2026
this.executeNext();
2127
};
@@ -33,12 +39,19 @@ TaskQueue.prototype.executeNext = function () {
3339
executed = 1;
3440
self.onTaskFinished();
3541
}
36-
}
42+
};
3743
})();
3844

3945
try {
4046
if (!this.hideProgress) {
41-
console.log("TaskStart Queue:", this.name, "Length:", this.queue.length, "OnGoing:", this.onGoingTask);
47+
console.log(
48+
"TaskStart Queue:",
49+
this.name,
50+
"Length:",
51+
this.queue.length,
52+
"OnGoing:",
53+
this.onGoingTask
54+
);
4255
}
4356

4457
// no mater the task is finished or not, we need to make sure the onFinished has been called
@@ -61,22 +74,28 @@ TaskQueue.prototype.onTaskFinished = function () {
6174
this.onGoingTask = this.onGoingTask - 1;
6275
this.onGoingTask = this.onGoingTask < 0 ? 0 : this.onGoingTask;
6376
if (!this.hideProgress) {
64-
console.log("TaskFinished Queue:", this.name, "Length:", this.queue.length, "OnGoing:", this.onGoingTask);
77+
console.log(
78+
"TaskFinished Queue:",
79+
this.name,
80+
"Length:",
81+
this.queue.length,
82+
"OnGoing:",
83+
this.onGoingTask
84+
);
6585
}
6686
var self = this;
6787
setTimeout(function () {
6888
self.executeNext();
6989
}, 0);
70-
7190
};
7291

7392
/**
7493
* Remove the taskqueue to fresh states
7594
*/
76-
TaskQueue.prototype.reset = function() {
77-
while(this.queue.length > 0) {
95+
TaskQueue.prototype.reset = function () {
96+
while (this.queue.length > 0) {
7897
this.queue.pop();
79-
};
98+
}
8099
this.onGoingTask = 0;
81100
};
82101

0 commit comments

Comments
 (0)