Quellcode durchsuchen

Fixed time zone for local time

Lukas Cerny vor 10 Monaten
Ursprung
Commit
7acc13f387

+ 2 - 2
config/senslog1Analytics.yaml

@@ -6,7 +6,7 @@ settings:
 
         timeZone: "Europe/Prague"
         startDate: now # 2024-04-17T11:00:00+02:00
-        delayStartDate: 20 # minutes
+        delayStartDate: 10 # minutes
         interval: 10 # minutes
         user: "osek"
 
@@ -29,5 +29,5 @@ connectors:
         fetcher: "Senslog"
         pusher: "Analytics"
         period: 600 # 10 minutes
-        startAt: "00:10:00" # at 10 AM
+        startAt: "08:00:00"
 #        initDelay: 5

+ 3 - 1
connector-fetch-senslog-v1/src/main/java/cz/senslog/connector/fetch/senslog/v1/SenslogConfig.java

@@ -11,6 +11,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.time.Instant;
 import java.time.LocalDateTime;
+import java.time.ZoneOffset;
 import java.util.TimeZone;
 
 public class SenslogConfig {
@@ -52,7 +53,8 @@ public class SenslogConfig {
         if (startDate.equalsIgnoreCase("now")) {
             tempStartDate = LocalDateTime.ofInstant(Instant.now(), timeZone.toZoneId());
         } else {
-            tempStartDate = defaultConfig.getLocalDateTimeProperty("startDate");
+            LocalDateTime configSystemTime = defaultConfig.getLocalDateTimeProperty("startDate");
+            tempStartDate = LocalDateTime.ofInstant(configSystemTime.atZone(ZoneOffset.systemDefault()).toInstant(), timeZone.toZoneId());
         }
 
         if (defaultConfig.containsProperty("delayStartDate")) {

+ 7 - 17
connector-fetch-senslog-v1/src/main/java/cz/senslog/connector/fetch/senslog/v1/SenslogFetcher.java

@@ -55,28 +55,16 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
     protected static class ObservationInfo { Float value; OffsetDateTime time; }
 
     private synchronized HttpCookie getAuthCookie() {
-        /*
-        if (authCookie.getItem1()) {
-            return authCookie.getItem2();
-        }
-
-        if (config.getAuth() == null) {
-            authCookie = Tuple.of(true, null);
-            return authCookie.getItem2();
-        }
-
-         */
-
         HttpRequest request = HttpRequest.newBuilder().GET()
                 .url(URLBuilder.newBuilder(config.getBaseUrl(), "/ControllerServlet")
                         .addParam("username", config.getAuth().getUsername())
                         .addParam("password", config.getAuth().getPassword())
                         .build()
                 ).build();
-        logger.info("Getting new auth cookie from the server: {}.", config.getBaseUrl());
+        logger.debug("Getting new auth cookie from the server: {}.", config.getBaseUrl());
 
         HttpResponse response = httpClient.send(request);
-        logger.info("Received new auth token with the status '{}' from the server {}.", response.getStatus(), config.getBaseUrl());
+        logger.info("Refreshed auth token with status: '{}'", response.getStatus());
 
         if (response.isError()) {
             logger.warn("Authorization failed. Error code {} with the reason '{}'.", response.getStatus(), response.getBody());
@@ -111,10 +99,10 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
         }
 
         HttpRequest request = reqBuilder.addCookie(authCookie).build();
-        logger.info("Getting new data from the server: {}.", request.getUrl());
+        logger.debug("Getting new data from the server: {}.", request.getUrl());
 
         HttpResponse response = httpClient.send(request);
-        logger.info("Received new data with the status '{}' from the server {}.", response.getStatus(), request.getUrl());
+        logger.debug("Received new data with the status '{}' from the server {}.", response.getStatus(), request.getUrl());
 
         if (response.getStatus() == HttpCode.UNAUTHORIZED && authErrors.get() <= MAX_AUTH_ERRORS) {
             this.authCookie = Tuple.of(false, null);
@@ -184,7 +172,9 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
     public SenslogV1Model fetch(Optional<SensLogSession> persistenceSession) {
         HttpCookie authCookie = getAuthCookie();
 
+        // get 'now' time at the configured time zone (i.e., the 'timeZone' parameter in the config)
         OffsetDateTime now = ZonedDateTime.ofInstant(Instant.now(), config.getTimeZone().toZoneId()).toOffsetDateTime();
+        // get the 'startDate' at the configured time zone
         OffsetDateTime startDate = ZonedDateTime.of(config.getStartDate(), config.getTimeZone().toZoneId()).toOffsetDateTime();
 
         SensLogSession session = persistenceSession.filter(ProxySessionModel::isActive).orElse(localSession);
@@ -204,7 +194,7 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
                     toDate = now;
                 }
 
-                logger.info("Getting new observations for the unit {} and the sensor {} from {} to {}.", unit.getUnitId(), sensor.getSensorId(), fromDate, toDate);
+                logger.info("Data request: unit <{}> | sensor <{}> | interval  {} - {}.", unit.getUnitId(), sensor.getSensorId(), fromDate, toDate);
 
                 final DateTimeFormatter pattern = ofPattern("yyyy-MM-dd HH:mm:ssZ");
                 HttpRequest observationRequest = HttpRequest.newBuilder().GET()

+ 1 - 1
connector-fetch-senslog-v1/src/test/java/cz/senslog/connector/fetch/senslog/v1/SenslogFetcherTest.java

@@ -26,7 +26,7 @@ class SenslogFetcherTest {
         defaultConfig.setProperty("timeZone", "Europe/Prague");
         defaultConfig.setProperty("baseUrl", "http://sensor.lesprojekt.cz/senslog15");
         defaultConfig.setProperty("user", "osek");
-        defaultConfig.setProperty("delayStartDate", 30);
+        defaultConfig.setProperty("delayStartDate", 20);
         defaultConfig.setProperty("interval", 10);
 
         Map<String, String> auth = new HashMap<>();