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

Merge branch 'Eilerts_branch' into 'master'

Started implementing the correct dates into kwh function

See merge request mesji/bacheloroppgave_2022!30
parents 95dec771 a1f9e2b8
Branches
No related tags found
No related merge requests found
......@@ -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){
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment