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

Implemented today's date into the sql statements

parent 69a7e386
No related branches found
No related tags found
No related merge requests found
package com.application.DB;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
/**
* This class contains constants to be used related to database activities
*/
public final class Constants {
// Format for today's date
static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private Constants() {
// Empty constructor
}
// Today's date
public static final String TODAYS_DATE = format.format(LocalDateTime.now());
// Database ID/name
public static final String PROJECT_ID = "sf-drying-optimization";
// Location Valasen
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
/*
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";
*/
}
......@@ -158,7 +158,7 @@ public class DB {
// Preparing a query statement
/*
final String sqlStatement = "SELECT DISTINCT TimeStamp, VariantValue " +
"FROM sf-drying-optimization.124.int_sd_winccsensordata " +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' +
" ORDER BY TimeStamp ASC";
......@@ -168,7 +168,7 @@ public class DB {
// Preparing a query statement
// Query statement 124 Valåsen
final String sqlStatement = "SELECT `TimeStamp`, `VariantValue` " +
"FROM `sf-drying-optimization.124.int_sd_winccsensordata` " +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' +
" AND ValueID = 51" +
......@@ -178,12 +178,13 @@ public class DB {
/*
// Query statement 174 Årjang
final String sqlStatement =
"SELECT Timestamp, RealValue FROM `sf-drying-optimization.174.int_sd_swappconsensordata` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' +
"AND ValueID = 19 " +
"AND RealValue <> 0 " +
"ORDER BY TimeStamp ASC";
"SELECT Timestamp, RealValue
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' +
"AND ValueID = 19 " +
"AND RealValue <> 0 " +
"ORDER BY TimeStamp ASC";
*/
......@@ -210,16 +211,12 @@ public class DB {
// Riktig format, men i string
String formatedTimeStamp = getDateFormat().format(timeStamp);
/*
// Checks for negative values and unresonable large values
if(variantValue > 0){ //&& variantValue < 5000000){
// Checks for negative values
if(variantValue > 0) {
// Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue);
}
*/
data.put(formatedTimeStamp, variantValue);
//System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\t\t\tBaseline: %s\n",formatedTimeStamp,variantValue,baseline);
// Checks if the data is empty
}
......@@ -243,7 +240,6 @@ public class DB {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
}
return sortedFinalResults;
}
......@@ -280,21 +276,26 @@ public class DB {
// Sqlstatement for Valåsen(124)
final String sqlStatement =
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n" +
"FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches_v2` \n" +
"WHERE KilnName = 5 \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(CalculatedStart) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
"Group by DryingStarted\n" +
"Order by DryingStarted ASC";
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop " +
"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 ";
System.out.println(sqlStatement);
/*
// Sqlstatement for Årjang(174)
final String sqlStatement =
"SELECT MAX(Name) as DryingSchedule, MAX(KilinId)+1 as KilnName, DryingStarted, Max(DryingCompleted) as DryingCompleted\n" +
"FROM `sf-drying-optimization.174.int_dk_valmaticsdryingbatches` \n" +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_VALMATICS + "` " +
"WHERE KilinId = 16 \n" +
"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
"AND DATE(DryingCompleted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
......
File added
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