|
@@ -11,9 +11,7 @@ import cz.senslog.common.http.HttpRequest;
|
|
|
import cz.senslog.common.http.HttpResponse;
|
|
import cz.senslog.common.http.HttpResponse;
|
|
|
import cz.senslog.common.http.URLBuilder;
|
|
import cz.senslog.common.http.URLBuilder;
|
|
|
import cz.senslog.connector.model.api.ProxySessionModel;
|
|
import cz.senslog.connector.model.api.ProxySessionModel;
|
|
|
-import cz.senslog.connector.model.fieldclimate.FieldClimateModel;
|
|
|
|
|
-import cz.senslog.connector.model.fieldclimate.StationData;
|
|
|
|
|
-import cz.senslog.connector.model.fieldclimate.StationInfo;
|
|
|
|
|
|
|
+import cz.senslog.connector.model.fieldclimate.*;
|
|
|
import cz.senslog.common.util.Tuple;
|
|
import cz.senslog.common.util.Tuple;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.apache.logging.log4j.Logger;
|
|
@@ -96,8 +94,8 @@ public class FieldClimateFetcher implements ConnectorFetcher<FieldClimateSession
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
stationInfos = new ArrayList<>(stations.size());
|
|
stationInfos = new ArrayList<>(stations.size());
|
|
|
- for (StationInfo station : stations) { // TODO change to whitelist
|
|
|
|
|
- if (!config.getBlockedStations().contains(station.getName().getOriginal())) {
|
|
|
|
|
|
|
+ for (StationInfo station : stations) {
|
|
|
|
|
+ if (config.getAllowedStation().isAllowed(station.getName().getOriginal())) {
|
|
|
stationInfos.add(station);
|
|
stationInfos.add(station);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -183,21 +181,49 @@ public class FieldClimateFetcher implements ConnectorFetcher<FieldClimateSession
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ List<SensorDataInfo> filteredSensors = new ArrayList<>(stationData.getSensors().size());
|
|
|
|
|
+ for (SensorDataInfo sensor : stationData.getSensors()) {
|
|
|
|
|
+ if (SensorType.of(sensor.getCode()).isChanneled()) {
|
|
|
|
|
+ if (config.getAllowedStation().isAllowed(stationId, sensor.getCode(), sensor.getCh())) {
|
|
|
|
|
+ filteredSensors.add(sensor);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (config.getAllowedStation().isAllowed(stationId, sensor.getCode())) {
|
|
|
|
|
+ filteredSensors.add(sensor);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
stationData.setId(stationId);
|
|
stationData.setId(stationId);
|
|
|
|
|
+ stationData.setSensors(filteredSensors);
|
|
|
|
|
|
|
|
OffsetDateTime latestTimestamp = OffsetDateTime.MIN;
|
|
OffsetDateTime latestTimestamp = OffsetDateTime.MIN;
|
|
|
|
|
+ List<Map<String, String>> filteredDataList = new ArrayList<>(stationData.getData().size());
|
|
|
for (Map<String, String> sensorDataMap : stationData.getData()) {
|
|
for (Map<String, String> sensorDataMap : stationData.getData()) {
|
|
|
|
|
+ Map<String, String> filteredSensorData = new HashMap<>(sensorDataMap.size());
|
|
|
|
|
+
|
|
|
String strDate = sensorDataMap.getOrDefault("date", "");
|
|
String strDate = sensorDataMap.getOrDefault("date", "");
|
|
|
final DateTimeFormatter formatter = ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
final DateTimeFormatter formatter = ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
LocalDateTime date = LocalDateTime.parse(strDate, formatter);
|
|
LocalDateTime date = LocalDateTime.parse(strDate, formatter);
|
|
|
ZonedDateTime zonedDate = ZonedDateTime.of(date, config.getTimeZone().toZoneId());
|
|
ZonedDateTime zonedDate = ZonedDateTime.of(date, config.getTimeZone().toZoneId());
|
|
|
OffsetDateTime timestamp = zonedDate.toOffsetDateTime();
|
|
OffsetDateTime timestamp = zonedDate.toOffsetDateTime();
|
|
|
- sensorDataMap.put("date", timestamp.format(ISO_OFFSET_DATE_TIME));
|
|
|
|
|
|
|
+ filteredSensorData.put("date", timestamp.format(ISO_OFFSET_DATE_TIME));
|
|
|
|
|
+
|
|
|
|
|
+ for (SensorDataInfo sensor : filteredSensors) {
|
|
|
|
|
+ for (String aggrType : sensor.getAggr().keySet()) {
|
|
|
|
|
+ String sensorDataHash = format("%s_%s_%s_%s_%s",
|
|
|
|
|
+ sensor.getCh(), sensor.getMac(), sensor.getSerial(), sensor.getCode(), aggrType);
|
|
|
|
|
+ if (sensorDataMap.containsKey(sensorDataHash)) {
|
|
|
|
|
+ filteredSensorData.put(sensorDataHash, sensorDataMap.get(sensorDataHash));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ filteredDataList.add(filteredSensorData);
|
|
|
|
|
|
|
|
if (latestTimestamp.isBefore(timestamp)) {
|
|
if (latestTimestamp.isBefore(timestamp)) {
|
|
|
latestTimestamp = timestamp;
|
|
latestTimestamp = timestamp;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ stationData.setData(filteredDataList);
|
|
|
|
|
|
|
|
localTo = latestTimestamp.isAfter(localTo) ? latestTimestamp : localTo;
|
|
localTo = latestTimestamp.isAfter(localTo) ? latestTimestamp : localTo;
|
|
|
|
|
|