diff --git a/src/components/SensorInstall/constants.js b/src/components/SensorInstall/constants.js index c1db48bd72c4477f8226602029a8b3ae68299f36..f1c3f1242164ca81f81e3645a455f448924610ea 100644 --- a/src/components/SensorInstall/constants.js +++ b/src/components/SensorInstall/constants.js @@ -28,4 +28,5 @@ export const SENSOR_TYPES = { // eslint-disable-line senseware: 1, awair: 2, other: 3, + machineq: 4, }; diff --git a/src/containers/Sensors/SensorGraph.js b/src/containers/Sensors/SensorGraph.js index 1a0c05344513c65c2a3392d21633afef8938540e..0657457728c52c5849cea206165d6f831267deb1 100644 --- a/src/containers/Sensors/SensorGraph.js +++ b/src/containers/Sensors/SensorGraph.js @@ -30,7 +30,7 @@ import { TEMPERATURE_PROBE_LOCATION_REVERSE, SENSOR_TYPES } from '../../componen import Loading from '../../components/Loading'; export class SensorGraph extends Component { - NUM_DAYS = 10; // eslint-disable-line + NUM_DAYS = 2; // eslint-disable-line constructor(props) { super(props); @@ -60,6 +60,7 @@ export class SensorGraph extends Component { nodes: '', data: '', from: this.state.from.toUTCString(), + to: this.state.today.toUTCString(), }); this.props.loadWeather({ measurement: 'temperature', @@ -130,6 +131,27 @@ export class SensorGraph extends Component { return oneNode; }); } + } else if (gateway.sensor_type === SENSOR_TYPES.machineq) { + if (gateway.nodes) { + gateway.nodes.filter(oneNode => ( + oneNode.data.length > 0 + )).map((oneNode) => { + // If it's an apartment node + if (oneNode.node_type === 1) { + const timeSeriesData = this.generateTimeSeriesFromSensor(oneNode, props); + Object.keys(timeSeriesData.timeseries).map((key) => { + acc[key].push(timeSeriesData.timeseries[key]); + return key; + }); + // Add the latest readings + latestReadings[ + timeSeriesData.latestReading.id + ] = timeSeriesData.latestReading.reading; + // Handle boiler nodes differently + } + return oneNode; + }); + } } return acc; }, { @@ -144,6 +166,7 @@ export class SensorGraph extends Component { const weatherPoints = props.weather.weatherData['New_York:NY'].hourly.map(point => ( [new Date(point.ts), point.val] )); + if (weatherPoints.length > 0) { lines.temperature.push(new TimeSeries({ name: 'Outdoor Temperature', @@ -151,7 +174,6 @@ export class SensorGraph extends Component { points: weatherPoints, })); } - if (Object.keys(lines).length === 0) { return; } @@ -265,6 +287,7 @@ export class SensorGraph extends Component { id: sensor.id, data: measurements[measurement], }; + // Find space for the node const spaceOfNode = this.findDeviceLocation(device, props); name = spaceOfNode.deviceName ? spaceOfNode.deviceName : `device ${device.id}`; @@ -274,8 +297,7 @@ export class SensorGraph extends Component { value: device.data[device.data.length - 1].value, }; latestReading.name = name; - - // Generate the time series + // Generate the time series for this measurement acc[measurement] = this.generateTimeSeries( device.data, `${name} - ${measurement}`, @@ -348,14 +370,18 @@ export class SensorGraph extends Component { newDate = new Date(newDate.getTime() + (300 * 1000)); } } + // Hack since I am expecting to have data already in order ignore that value for now + if (new Date(i.ts) > new Date(prevPoint.ts)) { + acc.push([new Date(i.ts), i.value]); + prevPoint = i; + } + } else { + acc.push([new Date(i.ts), i.value]); + prevPoint = i; } - acc.push([new Date(i.ts), i.value]); - - prevPoint = i; return acc; }, []); - return new TimeSeries({ name: deviceName, columns: ['time', deviceName], @@ -369,12 +395,13 @@ export class SensorGraph extends Component { width: 1, }) - fetchData = debounce((from) => { + fetchData = debounce((from, to) => { this.props.loadAllNodeData({ building_id: this.props.buildingId, nodes: '', data: '', from: from.toUTCString(), + to: to.toUTCString(), }); this.props.loadWeather({ measurement: 'temperature', @@ -388,7 +415,7 @@ export class SensorGraph extends Component { updateTimeRangeStart = (momentDate) => { const date = momentDate.toDate(); if (date < this.state.from) { - this.fetchData(date); + this.fetchData(date, this.state.to); } this.setState({ @@ -399,6 +426,9 @@ export class SensorGraph extends Component { updateTimeRangeEnd = (momentDate) => { const date = momentDate.toDate(); + if (date > this.state.to) { + this.fetchData(this.state.from, date); + } this.setState({ timerange: new TimeRange([this.state.timerange.begin(), date]), }); diff --git a/src/utils/restServices.js b/src/utils/restServices.js index 3e763e1e41d8562ea92091575c2e8c6e371ea4ff..cd5c030ce7b6b9e353b43d48e46f61dc9cc15f3f 100644 --- a/src/utils/restServices.js +++ b/src/utils/restServices.js @@ -46,6 +46,7 @@ export const customImpactReportURL = `${reportService}/customimpact/`; export const gatewayURL = `${iotService}/gateway/`; export const sensewareNodeURL = `${iotService}/sensewarenode/`; +export const machineqNodeURL = `${iotService}/machineqnode/`; export const sensorImageURL = `${iotService}/sensorimage/`; export const eventsURL = `${iotService}/event/`; export const alertSubscribersURL = `${iotService}/alertsubscription/`;