Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 66c042f1

Přidáno uživatelem Štěpán Červenka před více než 3 roky(ů)

Re #8775 - Agregovat grafy se stejným typem sensoru

  • bugs fixed
  • sensors and units sending request to new methods
  • ready for observation data

Zobrazit rozdíly:

src/app/unit/components/unit.component.ts
65 65
              this.sensorGroups.push(sensorType);
66 66
              setTimeout(() => {
67 67
                //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5));
68
                GraphLoader.getGraph(null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5),null );
68
                GraphLoader.getGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5),null );
69 69
              }, 0);
70 70
            }
71 71
          });
......
101 101
  }
102 102

  
103 103
  getAnalytics(range: Date[], changedDate: boolean, changedSensor: string) {
104
    const groupId = changedSensor.toString().slice(0, 5);
104 105
    if (changedDate) {
105 106
      this.selectedSensors.forEach(selectSens => {
106 107
        this.analyticsService.getAnalytics$Response({unit_id: this.unitId, sensor_id: parseInt(selectSens, 10),
......
111 112
              return response.body;
112 113
            } else if (response.status === 204) {
113 114
              //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5));
114
              GraphLoader.getGraph(null, null, '#vega_container_' + selectSens.toString().slice(0, 5),null );
115
              GraphLoader.getGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5),null );
115 116
              this.toastService.showWarningNoData();
116 117
              return response.body;
117 118
            } else {
......
129 130
                  //GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
130 131
                  //GraphLoader.getGraph(this.selectedSensors, this.filteredAnalyticsData(groupId), view, true);
131 132
                } else {
132
                  GraphLoader.getGraph(null, null, view, null);
133
                  GraphLoader.getGraph(null, null, null, view, null);
133 134
                }
134 135
              }
135 136
            }
......
159 160
              const view = '#vega_container_' + key.slice(0, 5);
160 161
              if (this.selectedSensors.some(sens => sens.toString() === key)) {
161 162
               // GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
162
                GraphLoader.getGraph(this.selectedSensors, this.analyticsData, view, true);
163
                GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), view, true);
163 164
              } else {
164 165
                //GraphLoader.getAnalyticsGraph(null, null, null, view);
165
                GraphLoader.getGraph(null, null, view, null);
166
                GraphLoader.getGraph(null, null, null, view, null);
166 167
              }
167 168
            }
168 169
          }
......
181 182
    const sensorGroupElement = '#vega_container_' + groupId;
182 183
    if (!this.selectedSensors.find(sensId => sensId.toString().slice(0, 5) === groupId)) { // if group of sensors is empty show empty graph
183 184
      //GraphLoader.getAnalyticsGraph(null, null, null, sensorGroupElement);
184
      GraphLoader.getGraph(null, null, sensorGroupElement, null);
185
      GraphLoader.getGraph(null, null, null, sensorGroupElement, null);
185 186
    } else {
186 187
      if (this.useAnalyticsData) { // use analytics data
187 188
        if (event.checked) { // if checked > add to graph
188 189
          if (this.analyticsData.some(sens => sens.sensorId === sensorId)) { // if already data for selected sensor in memory
189 190
            //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
190 191
            // this.analyticsData.find((sens => sens.sensorId === sensorId).interval, sensorGroupElement);
191
            GraphLoader.getGraph(this.selectedSensors, this.analyticsData, sensorGroupElement, true);
192
            GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
192 193

  
193 194
          } else { // get data from server for added sensor and show graph for selected sensors
194 195
            this.showGraph(false, sensorId);
......
196 197
        } else { // remove sensor from graph
197 198
          //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
198 199
          // this.analyticsData.find(sens => sens.sensorId === sensorId).interval, sensorGroupElement);
199
          GraphLoader.getGraph(this.selectedSensors, this.analyticsData, sensorGroupElement, true);
200
          GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
200 201

  
201 202
        }
202 203
      } else { // use observations data
203 204
        if (event.checked) { // if checked > add to graph
204 205
          if (this.observationsData.some(sens => sens.sensorId.toString() === sensorId)) { // if already data for selected sensor in memory
205
            GraphLoader.getGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement, false);
206
            GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
206 207
            //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
207 208
          } else { // get data from server for added sensor and show graph for selected sensors
208 209
            this.showGraph(false, sensorId);
209 210
          }
210 211
        } else { // remove sensor from graph
211 212
          //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
212
          GraphLoader.getGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement, false);
213
          GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
214

  
213 215
        }
214 216
      }
215 217
    }
......
232 234
      sen.sensorId.toString().slice(0, 5) === sensorGroupId);
233 235
  }
234 236

  
237

  
238
  filteredSelectedSensors(sensorGroupId: string): any {
239
    return this.selectedSensors.filter(sen => sen.toString().slice(0, 5) == sensorGroupId );
240
  }
241

  
242
  filteredSensorsInfos(sensorGroupId: string): any {
243
    return this.sensors.filter(sen => this.selectedSensors.includes(sen.sensorId.toString()) &&
244
      sen.sensorId.toString().slice(0, 5) == sensorGroupId);
245
  }
246

  
235 247
  private getObservations(range: Date[], changedDate: boolean, changedSensorId: string) {
248
    const groupId = changedSensorId.toString().slice(0, 5);
236 249
    if (changedDate) { // if changed date we need new data for all sensors
237 250
      this.observationsData = []; // empty observation data
238 251
      this.selectedSensors.forEach(selectSens => {
......
264 277
              setTimeout(() => {
265 278
                console.log(this.selectedSensors);
266 279
                //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(selectSens.toString().slice(0, 5)), view);
267
                GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
280
                GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
268 281
              }, 10);
269 282
            }
270 283
          })
......
292 305
          this.observationsData.push({sensorId: changedSensorId, sensor:
293 306
              this.sensors.find(sens => sens.sensorId.toString() === changedSensorId.toString()), data: observations});
294 307
          const view = '#vega_container_' + changedSensorId.toString().slice(0, 5);
295
          if (observations) {
296
            console.log(this.observationsData);
297
            GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
298
            //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view);
299
          } else {
300
            //GraphLoader.getMultilineGraph(null, null, null);
301
            GraphLoader.getGraph(this.selectedSensors,  this.filteredObservationData(changedSensorId.toString().slice(0, 5)), view, false);
302
          }
308

  
309
            GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
303 310
        }, err => this.toastService.showError(err.error.message));
304 311
    }
305 312
  }

Také k dispozici: Unified diff