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

Implemented the Constants class

parent 74e773e2
Branches
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ import java.time.LocalDateTime; ...@@ -12,6 +12,8 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import static com.application.DB.Constants.*;
/** /**
* This class is responsible for handling database related activities * This class is responsible for handling database related activities
* *
...@@ -77,7 +79,7 @@ public class DB { ...@@ -77,7 +79,7 @@ public class DB {
// we use to execute jobs on // we use to execute jobs on
return BigQueryOptions.newBuilder(). return BigQueryOptions.newBuilder().
setCredentials(getCredentials()). setCredentials(getCredentials()).
setProjectId("sf-drying-optimization") setProjectId(PROJECT_ID)
.build().getService(); .build().getService();
} }
...@@ -279,7 +281,7 @@ public class DB { ...@@ -279,7 +281,7 @@ public class DB {
// Sqlstatement for Valåsen(124) // Sqlstatement for Valåsen(124)
final String sqlStatement = final String sqlStatement =
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n" + "SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n" +
"FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches` \n" + "FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches_v2` \n" +
"WHERE KilnName = 5 \n" + "WHERE KilnName = 5 \n" +
"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
"AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
...@@ -309,19 +311,52 @@ public class DB { ...@@ -309,19 +311,52 @@ public class DB {
for (FieldValueList row : result.iterateAll()) { for (FieldValueList row : result.iterateAll()) {
// Defining variables // Defining variables
String formatedInTidTork; String formatedInTidTork = "";
String formatedUtTidTork; String formatedUtTidTork = "";
// Retrieving the data // Retrieving the data
// DryingStarted: // DryingStarted:
if(!row.get("DryingStarted").isNull()){ if(!row.get("DryingStarted").isNull()){
long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000; // Check if response is given in millis
// Formating the data from long to a string in the correct date format if(row.get("DryingStarted").getValue() instanceof Integer) {
formatedInTidTork = getDateFormat().format(InTidTorkLong); long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000;
} else { // Formating the data from long to a string in the correct date format
formatedInTidTork = ""; formatedInTidTork = getDateFormat().format(InTidTorkLong);
}
// Checks if response is given in a string date format
else if(row.get("DryingStarted").getValue() instanceof String) {
// stores the value
String value = (String) row.get("DryingStarted").getValue();
// Splits the string based on 'T'
String[] splitValue = value.split("T");
// Combines the values into a new format
formatedInTidTork = splitValue[0]+" "+splitValue[1];
}
} }
// CalculatedStop:
// DryingCompleted:
if(!row.get("CalculatedStop").isNull()){
// Check if response is given in millis
if(row.get("CalculatedStop").getValue() instanceof Integer) {
long utTidTorkLong = row.get("CalculatedStop").getTimestampValue()/1000;
// Formating the data from long to a string in the correct date format
formatedUtTidTork = getDateFormat().format(utTidTorkLong);
}
else if(row.get("CalculatedStop").getValue() instanceof String) {
// stores the value
String value = (String) row.get("CalculatedStop").getValue();
// Splits the string based on 'T'
String[] splitValue = value.split("T");
// Combines the values into a new format
formatedUtTidTork = splitValue[0]+" "+splitValue[1];
}
}
System.out.println(formatedInTidTork);
System.out.println(formatedUtTidTork+"\n");
/*
// CalculatedStop: // CalculatedStop:
// DryingCompleted: // DryingCompleted:
if(!row.get("CalculatedStop").isNull()){ if(!row.get("CalculatedStop").isNull()){
...@@ -331,9 +366,10 @@ public class DB { ...@@ -331,9 +366,10 @@ public class DB {
} else { } else {
formatedUtTidTork = ""; formatedUtTidTork = "";
} }
*/
// Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list // Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list
if (!formatedInTidTork.equals("") && !formatedUtTidTork.equals("")){ if (!formatedInTidTork.isEmpty() && !formatedUtTidTork.isEmpty()){
// Adds the data to the dates map // Adds the data to the dates map
dates.put(formatedInTidTork,formatedUtTidTork); dates.put(formatedInTidTork,formatedUtTidTork);
} }
......
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