diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java index 5defc3d33d35d4117839ab11600934aba6352675..7e81652b1e392a09bf0160d0daffc9a9d9dbe32c 100644 --- a/src/main/java/com/application/DB/DB.java +++ b/src/main/java/com/application/DB/DB.java @@ -48,9 +48,9 @@ public class DB { } public static void main(String[] args) throws Exception { - //getKwh(); + getKwh(); //getName(); - getZeroPointDate(); + //getZeroPointDate(); } @@ -107,21 +107,38 @@ public class DB { */ public static Map<String, Number> getKwh() throws Exception { + /* + for (Map.Entry<String, String> entry : getZeroPointDate().entrySet()) { + //System.out.printf("Intid: \t%s\t\t\tOuttid: \t%s\n",entry.getKey(),entry.getValue()); + + // Preparing a query statement + final String sqlStatement = "SELECT TimeStamp, VariantValue " + + "FROM sf-drying-optimization.124.int_sd_winccsensordata " + + "WHERE TimeStamp BETWEEN " + entry.getKey() + " AND " + entry.getValue() + + "ORDER BY TimeStamp ASC";// Preparing a query statement + + } + + */ + // Initializing the data map to store the results Map<String, Number> data = new HashMap<>(); - // Preparing a query statement + + final String sqlStatement = "SELECT TimeStamp, VariantValue " + "FROM sf-drying-optimization.124.int_sd_winccsensordata " + "WHERE TimeStamp BETWEEN \"2021-01-30 08:51:03\" " + "AND \"2021-02-15 11:10:09\" ORDER BY TimeStamp ASC"; + + // Creates a job configuration queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build()); // Iterating through the results TableResult result = queryJob.getQueryResults(); - System.out.println("InTidTork \t UtTidTork"); + System.out.println("Timestamp \t KWh"); for (FieldValueList row : result.iterateAll()) { // Kwh @@ -136,8 +153,11 @@ public class DB { data.put(formatedTimeStamp, variantValue); } - //NavigableMap<String, Number> sortedData = new TreeMap<>(data); - return data; + for (Map.Entry<String, Number> entry : data.entrySet()) { + System.out.printf("Timestamp: \t%s\t\t\tKWh: \t%s\n",entry.getKey(),entry.getValue()); + } + + return data; } /** @@ -183,6 +203,18 @@ public class DB { //return data; } + /** + * This function retrieves the intidtork and uttidtork dates from the database. + * This variables are not sorted and thus this function iterates through the data in order to + * find the last intidtork date and the corresponding uttidtork data. + * These values will be used to reset the kwh. + * + * A possible extention of this function could be to limit the number of dring periodes. + * This could be done with counting the number of entries in + * + * @return A hashmap containing the correct intidtork and outtidtork dates + * @throws Exception Throws exception if an error occurs + */ private static Map<String, String> getZeroPointDate() throws Exception{ // Initializing a date format in the data type DateTimeFormatter @@ -232,10 +264,12 @@ public class DB { formatedUtTidTork = ""; } + // Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list + if (!formatedInTidTork.equals("") && !formatedUtTidTork.equals("")){ + // Adds the data to the dates map + dates.put(formatedInTidTork,formatedUtTidTork); + } //System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork); - - // Adds the data to the dates map - dates.put(formatedInTidTork,formatedUtTidTork); } // Defining a treemap to sort through the data @@ -265,7 +299,7 @@ public class DB { // if so the current date is the last intidtork date and // is the one we will use in order to reset the kwh. if(next.compareTo(formatedDateNowPlus) > 0){ - // Storing the dates that will be used for resetting kwh's. + // Storing the dates that will be used for resetting kwh. sortedDates.put(inTid,utTid); } } catch (NullPointerException e){ diff --git a/target/classes/com/application/DB/DB.class b/target/classes/com/application/DB/DB.class index b8c993545329c3ff8fe3fd7b263cd97cde2e4748..ec31148fa1f578a2ce3c089cb84d90f4678287d5 100644 Binary files a/target/classes/com/application/DB/DB.class and b/target/classes/com/application/DB/DB.class differ