|
|
@@ -121,7 +121,7 @@ public class FieldClimateFetcher implements ConnectorFetcher<FieldClimateModel>
|
|
|
|
|
|
logger.debug("Getting a start date time for station {}.", stationId);
|
|
|
LocalDateTime localFrom = stationTimeRanges.get(stationId);
|
|
|
- LocalDateTime localTo = localFrom.plusDays(1); // default interval (5h around 600 observations)
|
|
|
+ LocalDateTime localTo = localFrom.plusHours(5); // default interval (5h around 600 observations)
|
|
|
|
|
|
StationTimeRange timeRange = getTimeRangeForStation(stationId);
|
|
|
if (timeRange == null) break;
|
|
|
@@ -156,35 +156,49 @@ public class FieldClimateFetcher implements ConnectorFetcher<FieldClimateModel>
|
|
|
HttpResponse response = httpClient.send(request);
|
|
|
logger.info("Received a response with a status: {}.", response.getStatus());
|
|
|
|
|
|
- if (response.isError()) {
|
|
|
- logger.error("Can not get data from the station {}. Error {} {}",
|
|
|
- stationId, response.getStatus(), response.getBody());
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
- StationData stationData;
|
|
|
- try {
|
|
|
- logger.debug("Parsing body of the response to the class {}.", StationData.class);
|
|
|
- stationData = jsonToObject(response.getBody(), StationData.class);
|
|
|
- logger.info("Received {} records for the sensor {}.", stationData.getData().size(), stationId);
|
|
|
- } catch (SyntaxException e) {
|
|
|
- logger.catching(e); continue;
|
|
|
- }
|
|
|
+ if (response.isOk()) {
|
|
|
+
|
|
|
+ StationData stationData;
|
|
|
+ try {
|
|
|
+ logger.debug("Parsing body of the response to the class {}.", StationData.class);
|
|
|
+ stationData = jsonToObject(response.getBody(), StationData.class);
|
|
|
+ logger.info("Received {} records for the sensor {}.", stationData.getData().size(), stationId);
|
|
|
+ } catch (SyntaxException e) {
|
|
|
+ logger.catching(e);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- stationData.setId(stationId);
|
|
|
+ stationData.setId(stationId);
|
|
|
|
|
|
- LocalDateTime latestTimestamp = LocalDateTime.MIN;
|
|
|
- for (Map<String, String> sensorDataMap : stationData.getData()) {
|
|
|
- String strDate = sensorDataMap.getOrDefault("date", "");
|
|
|
- LocalDateTime timestamp = LocalDateTime.parse(strDate, ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
- sensorDataMap.put("date", timestamp.format(ISO_DATE_TIME));
|
|
|
+ LocalDateTime latestTimestamp = LocalDateTime.MIN;
|
|
|
+ for (Map<String, String> sensorDataMap : stationData.getData()) {
|
|
|
+ String strDate = sensorDataMap.getOrDefault("date", "");
|
|
|
+ LocalDateTime timestamp = LocalDateTime.parse(strDate, ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ sensorDataMap.put("date", timestamp.format(ISO_DATE_TIME));
|
|
|
|
|
|
- if (latestTimestamp.isBefore(timestamp)) {
|
|
|
- latestTimestamp = timestamp;
|
|
|
+ if (latestTimestamp.isBefore(timestamp)) {
|
|
|
+ latestTimestamp = timestamp;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- localTo = latestTimestamp.isAfter(localTo) ? latestTimestamp : localTo;
|
|
|
+ localTo = latestTimestamp.isAfter(localTo) ? latestTimestamp : localTo;
|
|
|
+
|
|
|
+ stationDataList.add(stationData);
|
|
|
+
|
|
|
+ int records = stationData.getSensors().size();
|
|
|
+ totalFetched += records;
|
|
|
+
|
|
|
+ logger.info("Fetched {} records for the station {}.", records, stationId);
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (response.getStatus() >= 300) {
|
|
|
+ logger.error("Can not get data from the station {}. Error {} {}",
|
|
|
+ stationId, response.getStatus(), response.getBody());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
stationTimeRanges.put(stationId, localTo);
|
|
|
|
|
|
@@ -195,13 +209,6 @@ public class FieldClimateFetcher implements ConnectorFetcher<FieldClimateModel>
|
|
|
if (globalTo.isBefore(localTo)) {
|
|
|
globalTo = localTo;
|
|
|
}
|
|
|
-
|
|
|
- stationDataList.add(stationData);
|
|
|
-
|
|
|
- int records = stationData.getSensors().size();
|
|
|
- totalFetched += records;
|
|
|
-
|
|
|
- logger.info("Fetched {} records for the station {}.", records, stationId);
|
|
|
}
|
|
|
|
|
|
FieldClimateModel model;
|