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

Fully functional quick switching using constans class

parent f13d4efc
No related branches found
No related tags found
No related merge requests found
......@@ -23,16 +23,51 @@ public final class Constants {
// Database ID/name
public static final String PROJECT_ID = "sf-drying-optimization";
// Location Valasen
// Location Valasen(124)
// Project settings
public static final int LOCATION_ID = 124;
public static final String TABLE_NAME_VALMATICS = "int_dk_valmaticsdryingbatches_v2";
public static final String TABLE_NAME_KWH = "int_sd_winccsensordata";
// Location Arjang
/*
// Parameters settings
// Valmatics
public static final String OTHER_PARAMETERS_NAME = "Name";
public static final String START_DRYING_NAME = "DryingStarted";
public static final String STOP_DRYING_NAME = "CalculatedStop";
public static final String KILIN_NAME = "KilnName";
public static final int KILIN_ID = 5;
// Winccsensordata
public static final String KWH_NAME = "VariantValue";
public static final int VALUE_ID = 51;
/*
// Location Arjang(174)
// Project settings
public static final int LOCATION_ID = 174;
public static final String TABLE_NAME_VALMATICS = "int_dk_valmaticsdryingbatches";
public static final String TABLE_NAME_KWH = "int_sd_swappconsensordata";
*/
// Parameters settings
// Valmatics
public static final String OTHER_PARAMETERS_NAME = "Name";
public static final String START_DRYING_NAME = "DryingStarted";
public static final String STOP_DRYING_NAME = "DryingCompleted";
public static final String KILIN_NAME = "KilinId";
public static final int KILIN_ID = 16;
// Winccsensordata
public static final String KWH_NAME = "RealValue";
public static final int VALUE_ID = 19;
*/
}
......@@ -12,6 +12,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import static com.application.DB.Constants.*;
/**
......@@ -167,14 +168,15 @@ public class DB {
// Preparing a query statement
// Query statement 124 Valåsen
final String sqlStatement = "SELECT `TimeStamp`, `VariantValue` " +
final String sqlStatement = "SELECT `TimeStamp`, `"+KWH_NAME+"` " +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' +
" AND ValueID = 51" +
" AND ValueID = " + VALUE_ID + " " +
" ORDER BY TimeStamp ASC";
/*
// Query statement 174 Årjang
final String sqlStatement =
......@@ -199,12 +201,12 @@ public class DB {
// Sets the baseline in order to reset the kWh counter
if (baseline == 0){
baseline = row.get("VariantValue").getNumericValue().intValue();
baseline = row.get(""+KWH_NAME+"").getNumericValue().intValue();
}
//System.out.println("baseline: "+baseline);
// kWh value
int variantValue = row.get("VariantValue").getNumericValue().intValue()-baseline; //-baseline
int variantValue = row.get(""+KWH_NAME+"").getNumericValue().intValue()-baseline; //-baseline
// Retrieving the wanted data
long timeStamp = row.get("TimeStamp").getTimestampValue() / 1000;
......@@ -258,10 +260,6 @@ public class DB {
*/
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 dates map to store the results
Map<String, String> dates = new HashMap<>();
......@@ -274,19 +272,22 @@ public class DB {
*/
// Defining extra parameters if required
String extraInputParameter = "";
if(LOCATION_ID == 124){
extraInputParameter = "AND CalculatedStart BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" ";
}
// Sqlstatement for Valåsen(124)
final String sqlStatement =
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop " +
"SELECT MAX("+OTHER_PARAMETERS_NAME+") as DryingSchedule, MAX("+KILIN_NAME+") as Kiln_ID, " + START_DRYING_NAME + ", MAX("+STOP_DRYING_NAME+") as DryingCompleted " +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_VALMATICS + "` " +
"WHERE KilnName = 5 " +
//"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\" " +
//"AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\" " +
//"AND DATE(CalculatedStart) BETWEEN \"1990-08-17\" AND \"2022-08-17\" " +
"AND DryingStarted BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND CalculatedStop BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND CalculatedStart BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"Group by DryingStarted " +
"Order by DryingStarted ASC ";
"WHERE " + KILIN_NAME + " = " + KILIN_ID + " " +
"AND "+START_DRYING_NAME+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND "+STOP_DRYING_NAME+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
extraInputParameter +
"Group by "+ START_DRYING_NAME + " " +
"Order by "+ START_DRYING_NAME + " ASC ";
System.out.println(sqlStatement);
......@@ -315,17 +316,26 @@ public class DB {
String formatedInTidTork = "";
String formatedUtTidTork = "";
//System.out.println("Start: "+row.get("DryingStarted").getTimestampValue());
//System.out.println("Stop: "+row.get("DryingCompleted").getTimestampValue());
// Retrieving the data
// DryingStarted:
if(!row.get("DryingStarted").isNull()){
// Check if response is given in millis
if(row.get("DryingStarted").getValue() instanceof Integer) {
long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000;
try{
long doubleValue = row.get("DryingStarted").getTimestampValue();
long InTidTorkLong = doubleValue/1000;
// Formating the data from long to a string in the correct date format
formatedInTidTork = getDateFormat().format(InTidTorkLong);
}
// Checks if response is given in a string date format
else if(row.get("DryingStarted").getValue() instanceof String) {
//System.out.println("LONG!!@@@@");
} catch(NumberFormatException e){
//not long value, must be of type string
//System.out.println("Must be a string!!@@@@");
// stores the value
String value = (String) row.get("DryingStarted").getValue();
// Splits the string based on 'T'
......@@ -333,29 +343,34 @@ public class DB {
// Combines the values into a new format
formatedInTidTork = splitValue[0]+" "+splitValue[1];
}
// Checks if response is given in a string date format
//if(row.get("DryingStarted").getValue().equals(Long.parseLong(row.get("DryingStarted").getValue().toString()))) {
}
// 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];
}
// Check if response is given in millis
try{
long doubleValue = row.get("DryingCompleted").getTimestampValue();
long utTidTorkLong = doubleValue/1000;
// Formating the data from long to a string in the correct date format
formatedUtTidTork = getDateFormat().format(utTidTorkLong);
} catch(NumberFormatException e) {
//not long value, must be of type string
// stores the value
String value = (String) row.get("DryingCompleted").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");
System.out.println("Inn formated: "+formatedInTidTork);
System.out.println("Ut formated: "+formatedUtTidTork+"\n");
/*
// CalculatedStop:
......
No preview for this file type
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