30 |
30 |
analyticsData: any[] = [];
|
31 |
31 |
observationsData: any[] = [];
|
32 |
32 |
sensorGroups = [];
|
33 |
|
selectedSensors: number[] = [];
|
|
33 |
selectedSensors: string[] = [];
|
34 |
34 |
sensors: Sensor[];
|
35 |
35 |
showAggregation = false;
|
36 |
36 |
aggregationFunction: AggregationModel[];
|
... | ... | |
55 |
55 |
this.sensorService.getUnitSensors({unit_id: this.unitId}).pipe(
|
56 |
56 |
tap(sens => {
|
57 |
57 |
this.sensors = sens;
|
|
58 |
this.sensors.sort((a, b) => a.sensorId - b.sensorId);
|
58 |
59 |
}),
|
59 |
60 |
tap(() => {
|
60 |
61 |
if (this.sensors && this.sensors.length > 0) {
|
... | ... | |
75 |
76 |
ngOnInit(): void {
|
76 |
77 |
}
|
77 |
78 |
|
78 |
|
showGraph(changedDate: boolean = true, changedSensor: number = null) {
|
|
79 |
showGraph(changedDate: boolean = true, changedSensor: string = null) {
|
79 |
80 |
const range: Date[] = [moment().subtract(7, 'days').toDate(), moment().toDate()];
|
80 |
81 |
|
81 |
82 |
if (this.from && !this.to || !this.from && this.to) {
|
... | ... | |
98 |
99 |
}
|
99 |
100 |
}
|
100 |
101 |
|
101 |
|
getAnalytics(range: Date[], changedDate: boolean, changedSensor: number) {
|
|
102 |
getAnalytics(range: Date[], changedDate: boolean, changedSensor: string) {
|
102 |
103 |
if (changedDate) {
|
103 |
104 |
this.selectedSensors.forEach(selectSens => {
|
104 |
|
this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: selectSens,
|
|
105 |
this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: parseInt(selectSens, 10),
|
105 |
106 |
from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
106 |
107 |
to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: this.selectedAggregationFunction}).pipe(
|
107 |
108 |
map((response: HttpResponse<any>) => {
|
... | ... | |
133 |
134 |
}, err => this.toastService.showError(err.error.message));
|
134 |
135 |
});
|
135 |
136 |
} else {
|
136 |
|
this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: changedSensor,
|
|
137 |
this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: parseInt(changedSensor, 10),
|
137 |
138 |
from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
138 |
139 |
to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: this.selectedAggregationFunction}).pipe(
|
139 |
140 |
map((response: HttpResponse<any>) => {
|
... | ... | |
170 |
171 |
* @param sensorId checked sensorId
|
171 |
172 |
* @param event event for getting if checked or unchecked
|
172 |
173 |
*/
|
173 |
|
addSensorToGraph(sensorId: number, event) {
|
|
174 |
addSensorToGraph(sensorId: string, event) {
|
174 |
175 |
const groupId = sensorId.toString().slice(0, 5);
|
175 |
176 |
const sensorGroupElement = '#vega_container_' + groupId;
|
176 |
177 |
if (!this.selectedSensors.find(sensId => sensId.toString().slice(0, 5) === groupId)) { // if group of sensors is empty show empty graph
|
... | ... | |
190 |
191 |
}
|
191 |
192 |
} else { // use observations data
|
192 |
193 |
if (event.checked) { // if checked > add to graph
|
193 |
|
if (this.observationsData.some(sens => sens.sensorId === sensorId)) { // if already data for selected sensor in memory
|
|
194 |
if (this.observationsData.some(sens => sens.sensorId.toString() === sensorId)) { // if already data for selected sensor in memory
|
194 |
195 |
GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
|
195 |
196 |
} else { // get data from server for added sensor and show graph for selected sensors
|
196 |
197 |
this.showGraph(false, sensorId);
|
... | ... | |
218 |
219 |
return this.analyticsData.filter(sen => this.selectedSensors.includes(sen.sensorId.toString()));
|
219 |
220 |
}
|
220 |
221 |
|
221 |
|
private getObservations(range: Date[], changedDate: boolean, changedSensorId: number) {
|
|
222 |
private getObservations(range: Date[], changedDate: boolean, changedSensorId: string) {
|
222 |
223 |
if (changedDate) { // if changed date we need new data for all sensors
|
223 |
224 |
this.observationsData = []; // empty observation data
|
224 |
225 |
this.selectedSensors.forEach(selectSens => {
|
225 |
226 |
this.observationService.getObservation$Response({
|
226 |
227 |
unit_id: this.unitId,
|
227 |
|
sensor_id: selectSens,
|
|
228 |
sensor_id: parseInt(selectSens, 10),
|
228 |
229 |
from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
229 |
230 |
to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3)
|
230 |
231 |
}).pipe(
|
... | ... | |
250 |
251 |
setTimeout(() => {
|
251 |
252 |
console.log(this.selectedSensors);
|
252 |
253 |
GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(selectSens.toString().slice(0, 5)), view);
|
253 |
|
}, 0);
|
|
254 |
}, 10);
|
254 |
255 |
}
|
255 |
256 |
})
|
256 |
257 |
).toPromise().then().catch(err => this.toastService.showError(err));
|
... | ... | |
258 |
259 |
} else {
|
259 |
260 |
this.observationService.getObservation$Response({
|
260 |
261 |
unit_id: this.unitId,
|
261 |
|
sensor_id: changedSensorId,
|
|
262 |
sensor_id: parseInt(changedSensorId, 10),
|
262 |
263 |
from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
|
263 |
264 |
to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3)
|
264 |
265 |
}).pipe(
|
... | ... | |
278 |
279 |
this.sensors.find(sens => sens.sensorId.toString() === changedSensorId.toString()), data: observations});
|
279 |
280 |
const view = '#vega_container_' + changedSensorId.toString().slice(0, 5);
|
280 |
281 |
if (observations) {
|
|
282 |
console.log(this.observationsData);
|
281 |
283 |
GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view);
|
282 |
284 |
} else {
|
283 |
285 |
GraphLoader.getMultilineGraph(null, null, null);
|
Re #8851 - Unit page - implementace