Skip to content
Snippets Groups Projects
Commit 33639486 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Full functionality of the getZeroPointDate() function! Returns a hashmap...

Full functionality of the getZeroPointDate() function! Returns a hashmap containging the final intditork and the corresponding uttidtork values.
parent 96d0c351
No related branches found
No related tags found
No related merge requests found
......@@ -7,12 +7,9 @@ import com.google.cloud.bigquery.*;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
/**
......@@ -186,13 +183,13 @@ public class DB {
//return data;
}
private static void getZeroPointDate() throws Exception{
private static Map<String, String> getZeroPointDate() throws Exception{
// Initializing a date format in the data type DateTimeFormatter
// Required for iterating through the dates.
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// Initializing the data map to store the results
// Initializing the dates map to store the results
Map<String, String> dates = new HashMap<>();
// Preparing a query statement
......@@ -204,16 +201,19 @@ public class DB {
// Creates a job configuration
queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build());
// Iterating through the results
// Retrieves the results from the queryjob
TableResult result = queryJob.getQueryResults();
System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results
for (FieldValueList row : result.iterateAll()) {
// Defining variables
String formatedInTidTork;
String formatedUtTidTork;
// Retrieving the wanted data
// Retrieving the data
// InTidTork:
if(!row.get("InTidTork").isNull()){
long InTidTorkLong = row.get("InTidTork").getTimestampValue()/1000;
......@@ -232,42 +232,47 @@ public class DB {
formatedUtTidTork = "";
}
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
NavigableMap<String, String> dataSet = new TreeMap<>(dates);
/*
for (Map.Entry<String, String> entry : dataSet.entrySet()) {
System.out.printf("Key: %s\t\t\tValue: %s\n",entry.getKey(),entry.getValue());
}
*/
// Defining a hashmap to store the final sorted data
Map<String, String> sortedDates = new HashMap<>();
// Iterating through the data in order to find and set a zeropoint for the dates.
for (Map.Entry<String, String> entry : dataSet.entrySet()) {
// Retrieving the entry key
String key = entry.getKey();
// Retrieving the entry key and value
String inTid = entry.getKey();
String utTid = entry.getValue();
// Format the date to LocalDateTime datatype
LocalDateTime date = LocalDateTime.parse(key, format);
// Creates a future date to compare against
LocalDateTime date = LocalDateTime.parse(inTid, format);
// Creates a future date to compare against one day forward in time
LocalDateTime dateNowPlus = date.plusDays(1);
String formatedDateNowPlus = format.format(dateNowPlus);
try {
String next = dataSet.higherEntry(entry.getKey()).getKey(); // next
System.out.printf("Current date: %s\t\t\tPluss 1: %s\t\t\tNext date: %s\n",key,formatedDateNowPlus,next);
// Retrieves the next entry in the list
String next = dataSet.higherEntry(entry.getKey()).getKey();
//System.out.printf("Neste: %s\n\n",next);
// Checks if the next date is longer than 1 day,
// 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){
System.out.printf("Inni if!!@@, Er next mindre enn formated?\nNext, skal være større: %s\nFormated, skal være mindre: %s\n\n",next,formatedDateNowPlus);
// Storing the dates that will be used for resetting kwh's.
sortedDates.put(inTid,utTid);
}
} catch (NullPointerException e){
System.out.println(e.getMessage());
// Can't find any more iterations, breaks out of the loop.
break;
}
}
return sortedDates;
}
}
\ No newline at end of file
......@@ -55,14 +55,14 @@
<left>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true" translateX="5.0" BorderPane.alignment="CENTER">
<image>
<Image url="@moelven_logo_m.jpg" />
<Image url="@moelven_logo_m.png" />
</image>
</ImageView>
</left>
<center>
<ImageView fitHeight="30.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@moelven_logo_title.jpg" />
<Image url="@moelven_logo_title.png" />
</image>
</ImageView>
</center>
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment