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

Merge branch 'Eilerts_branch' into 'master'

Eilerts branch

See merge request mesji/bacheloroppgave_2022!33
parents 69a7e386 c2e4f346
No related branches found
No related tags found
No related merge requests found
package com.application.DB; package com.application.DB;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/** /**
* This class contains constants to be used related to database activities * This class contains constants to be used related to database activities
*/ */
public final class Constants { public final class Constants {
// Format for today's date
static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private Constants() { private Constants() {
// Empty constructor // Empty constructor
} }
// Today's date
public static final String TODAYS_DATE = format.format(LocalDateTime.now());
// User inputs
public static final String TREE_SPECIES = "";
public static final String WIDTH_DIMENTION = "";
public static final String HEIGHT_DIMENTION = "";
public static final String SAWSET = "";
public static final int MOISTURE_GOAL = 0;
// Database ID/name
public static final String PROJECT_ID = "sf-drying-optimization"; public static final String PROJECT_ID = "sf-drying-optimization";
/*
// 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";
// 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 int KILIN_ID = 5;
// Winccsensordata
public static final String KWH_NAME = "VariantValue";
public static final String TIMESTAMP_NAME = "Timestamp";
public static final String VALUE_ID_NAME = "ValueID";
public static final int VALUE_ID = 51;
public static final int LIMIT = 1000;
*/
// 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 int KILIN_ID = 18;
public static int KILIN_ID = 18133;
// Swappconsensordata
public static final String KWH_NAME = "RealValue";
public static final String TIMESTAMP_NAME = "Timestamp";
public static final String VALUE_ID_NAME = "ValueID";
public static final int VALUE_ID = 19;
public static final int LIMIT = 1000;
} }
...@@ -6,12 +6,10 @@ import com.google.cloud.bigquery.*; ...@@ -6,12 +6,10 @@ import com.google.cloud.bigquery.*;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
/** /**
...@@ -158,7 +156,7 @@ public class DB { ...@@ -158,7 +156,7 @@ public class DB {
// Preparing a query statement // Preparing a query statement
/* /*
final String sqlStatement = "SELECT DISTINCT TimeStamp, VariantValue " + 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() + '"' + "WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' + " AND " + '"' + entry.getValue() + '"' +
" ORDER BY TimeStamp ASC"; " ORDER BY TimeStamp ASC";
...@@ -167,18 +165,21 @@ public class DB { ...@@ -167,18 +165,21 @@ public class DB {
// Preparing a query statement // Preparing a query statement
// Query statement 124 Valåsen // Query statement 124 Valåsen
final String sqlStatement = "SELECT `TimeStamp`, `VariantValue` " + final String sqlStatement = "SELECT `" + TIMESTAMP_NAME + "`, `"+KWH_NAME+"` " +
"FROM `sf-drying-optimization.124.int_sd_winccsensordata` " + "FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' + "WHERE " + TIMESTAMP_NAME + " BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' + " AND " + '"' + entry.getValue() + '"' +
" AND ValueID = 51" + " AND " + VALUE_ID_NAME + " = " + VALUE_ID + " " +
" ORDER BY TimeStamp ASC"; " AND " + KWH_NAME + " <> 0 " +
" ORDER BY " + TIMESTAMP_NAME + " ASC";
/* /*
// Query statement 174 Årjang // Query statement 174 Årjang
final String sqlStatement = final String sqlStatement =
"SELECT Timestamp, RealValue FROM `sf-drying-optimization.174.int_sd_swappconsensordata` " + "SELECT Timestamp, RealValue
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_KWH + "` " +
"WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' + "WHERE TimeStamp BETWEEN " + '"'+ entry.getKey() + '"' +
" AND " + '"' + entry.getValue() + '"' + " AND " + '"' + entry.getValue() + '"' +
"AND ValueID = 19 " + "AND ValueID = 19 " +
...@@ -198,28 +199,24 @@ public class DB { ...@@ -198,28 +199,24 @@ public class DB {
// Sets the baseline in order to reset the kWh counter // Sets the baseline in order to reset the kWh counter
if (baseline == 0){ if (baseline == 0){
baseline = row.get("VariantValue").getNumericValue().intValue(); baseline = row.get(""+KWH_NAME+"").getNumericValue().intValue();
} }
//System.out.println("baseline: "+baseline); //System.out.println("baseline: "+baseline);
// kWh value // 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 // Retrieving the wanted data
long timeStamp = row.get("TimeStamp").getTimestampValue() / 1000; long timeStamp = row.get(""+TIMESTAMP_NAME+"").getTimestampValue() / 1000;
// Riktig format, men i string // Riktig format, men i string
String formatedTimeStamp = getDateFormat().format(timeStamp); String formatedTimeStamp = getDateFormat().format(timeStamp);
/* // Checks for negative values
// Checks for negative values and unresonable large values if(variantValue > 0) {
if(variantValue > 0){ //&& variantValue < 5000000){
// Adding the data to a list in order to sort through later // Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue); 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); //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 // Checks if the data is empty
} }
...@@ -243,7 +240,6 @@ public class DB { ...@@ -243,7 +240,6 @@ public class DB {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue()); System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
} }
return sortedFinalResults; return sortedFinalResults;
} }
...@@ -262,10 +258,6 @@ public class DB { ...@@ -262,10 +258,6 @@ public class DB {
*/ */
private static Map<String, String> 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 dates map to store the results // Initializing the dates map to store the results
Map<String, String> dates = new HashMap<>(); Map<String, String> dates = new HashMap<>();
...@@ -278,23 +270,36 @@ public class DB { ...@@ -278,23 +270,36 @@ 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 + "\" ";
}
if(LOCATION_ID == 174){
// KILIN_ID starts at 0 not 1 in the database.
KILIN_ID -= 1;
}
// 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("+OTHER_PARAMETERS_NAME+") as DryingSchedule, MAX("+KILIN_NAME+") as Kiln_ID, " + START_DRYING_NAME + ", MAX("+STOP_DRYING_NAME+") as DryingCompleted " +
"FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches_v2` \n" + "FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + TABLE_NAME_VALMATICS + "` " +
"WHERE KilnName = 5 \n" + "WHERE " + KILIN_NAME + " = " + KILIN_ID + " " +
"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND "+START_DRYING_NAME+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND "+STOP_DRYING_NAME+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND DATE(CalculatedStart) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + extraInputParameter +
"Group by DryingStarted\n" + "Group by "+ START_DRYING_NAME + " " +
"Order by DryingStarted ASC"; "Order by "+ START_DRYING_NAME + " ASC " +
"LIMIT " + LIMIT;
System.out.println(sqlStatement);
/* /*
// Sqlstatement for Årjang(174) // Sqlstatement for Årjang(174)
final String sqlStatement = final String sqlStatement =
"SELECT MAX(Name) as DryingSchedule, MAX(KilinId)+1 as KilnName, DryingStarted, Max(DryingCompleted) as DryingCompleted\n" + "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" + "WHERE KilinId = 16 \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(DryingCompleted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" + "AND DATE(DryingCompleted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n" +
...@@ -314,17 +319,26 @@ public class DB { ...@@ -314,17 +319,26 @@ public class DB {
String formatedInTidTork = ""; String formatedInTidTork = "";
String formatedUtTidTork = ""; String formatedUtTidTork = "";
//System.out.println("Start: "+row.get("DryingStarted").getTimestampValue());
//System.out.println("Stop: "+row.get("DryingCompleted").getTimestampValue());
// Retrieving the data // Retrieving the data
// DryingStarted: // DryingStarted:
if(!row.get("DryingStarted").isNull()){ if(!row.get("DryingStarted").isNull()){
// Check if response is given in millis // Check if response is given in millis
if(row.get("DryingStarted").getValue() instanceof Integer) { try{
long InTidTorkLong = row.get("DryingStarted").getTimestampValue()/1000; long doubleValue = row.get("DryingStarted").getTimestampValue();
long InTidTorkLong = doubleValue/1000;
// Formating the data from long to a string in the correct date format // Formating the data from long to a string in the correct date format
formatedInTidTork = getDateFormat().format(InTidTorkLong); formatedInTidTork = getDateFormat().format(InTidTorkLong);
} //System.out.println("LONG!!@@@@");
// Checks if response is given in a string date format } catch(NumberFormatException e){
else if(row.get("DryingStarted").getValue() instanceof String) { //not long value, must be of type string
//System.out.println("Must be a string!!@@@@");
// stores the value // stores the value
String value = (String) row.get("DryingStarted").getValue(); String value = (String) row.get("DryingStarted").getValue();
// Splits the string based on 'T' // Splits the string based on 'T'
...@@ -332,41 +346,34 @@ public class DB { ...@@ -332,41 +346,34 @@ public class DB {
// Combines the values into a new format // Combines the values into a new format
formatedInTidTork = splitValue[0]+" "+splitValue[1]; 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: // CalculatedStop:
// DryingCompleted: // DryingCompleted:
if(!row.get("CalculatedStop").isNull()){
// Check if response is given in millis // Check if response is given in millis
if(row.get("CalculatedStop").getValue() instanceof Integer) { try{
long utTidTorkLong = row.get("CalculatedStop").getTimestampValue()/1000; long doubleValue = row.get("DryingCompleted").getTimestampValue();
long utTidTorkLong = doubleValue/1000;
// Formating the data from long to a string in the correct date format // Formating the data from long to a string in the correct date format
formatedUtTidTork = getDateFormat().format(utTidTorkLong); formatedUtTidTork = getDateFormat().format(utTidTorkLong);
} } catch(NumberFormatException e) {
else if(row.get("CalculatedStop").getValue() instanceof String) { //not long value, must be of type string
// stores the value // stores the value
String value = (String) row.get("CalculatedStop").getValue(); String value = (String) row.get("DryingCompleted").getValue();
// Splits the string based on 'T' // Splits the string based on 'T'
String[] splitValue = value.split("T"); String[] splitValue = value.split("T");
// Combines the values into a new format // Combines the values into a new format
formatedUtTidTork = splitValue[0] + " " + splitValue[1]; formatedUtTidTork = splitValue[0] + " " + splitValue[1];
} }
}
System.out.println(formatedInTidTork);
System.out.println(formatedUtTidTork+"\n");
/* //System.out.println("Inn formated: "+formatedInTidTork);
// CalculatedStop: //System.out.println("Ut formated: "+formatedUtTidTork+"\n");
// DryingCompleted:
if(!row.get("CalculatedStop").isNull()){
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 {
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.isEmpty() && !formatedUtTidTork.isEmpty()){ if (!formatedInTidTork.isEmpty() && !formatedUtTidTork.isEmpty()){
...@@ -375,7 +382,7 @@ public class DB { ...@@ -375,7 +382,7 @@ public class DB {
} }
//System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork); //System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork);
} }
System.out.printf("Size of dates: %s\n", dates.size()); System.out.printf("Size of dates: %s\n\n", dates.size());
// Returns a treemap that sorts the dates incrementally // Returns a treemap that sorts the dates incrementally
return new TreeMap<>(dates); return new TreeMap<>(dates);
......
package com.application.GUI;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
/**
* This class handles the popup input window
*/
public class Input {
public static void display()
{
Stage popupwindow=new Stage();
popupwindow.initModality(Modality.APPLICATION_MODAL);
popupwindow.setTitle("Input Parameters");
Label inputLabel= new Label("Input");
inputLabel.setAlignment(Pos.TOP_CENTER);
Button close= new Button("Close this pop up window");
close.setAlignment(Pos.BOTTOM_CENTER);
close.setOnAction(e -> popupwindow.close());
BorderPane layout= new BorderPane();
//layout.set(inputLabel);
//layout.setCenter();
//layout.setBottom(close);
layout.getChildren().addAll(inputLabel, close);
Scene scene1= new Scene(layout, 300, 250);
popupwindow.setScene(scene1);
popupwindow.showAndWait();
}
}
package com.application; package com.application;
import com.application.DB.DB; import com.application.DB.DB;
import com.application.GUI.Input;
import com.application.GUI.RingProgressIndicator; import com.application.GUI.RingProgressIndicator;
import com.sun.corba.se.spi.orbutil.threadpool.Work;
import javafx.application.Application; import javafx.application.Application;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.chart.LineChart; import javafx.scene.chart.LineChart;
...@@ -133,6 +133,7 @@ public class Main extends Application { ...@@ -133,6 +133,7 @@ public class Main extends Application {
Menu menuEdit = new Menu("Edit"); Menu menuEdit = new Menu("Edit");
Menu menuHelp = new Menu("Help"); Menu menuHelp = new Menu("Help");
// Adding the menus to the menubar // Adding the menus to the menubar
menuBar.getMenus().add(menuFile); menuBar.getMenus().add(menuFile);
menuBar.getMenus().add(menuEdit); menuBar.getMenus().add(menuEdit);
...@@ -155,6 +156,7 @@ public class Main extends Application { ...@@ -155,6 +156,7 @@ public class Main extends Application {
TextField treeSpeciesText = new TextField(); TextField treeSpeciesText = new TextField();
treeSpeciesText.setId("sideBarLabelText"); treeSpeciesText.setId("sideBarLabelText");
treeSpeciesText.setPromptText("Bjørk"); treeSpeciesText.setPromptText("Bjørk");
treeSpeciesText.getText();
Label dimensionsLabel = new Label("Width x Height"); Label dimensionsLabel = new Label("Width x Height");
dimensionsLabel.setId("sideBarLabelText"); dimensionsLabel.setId("sideBarLabelText");
...@@ -176,6 +178,7 @@ public class Main extends Application { ...@@ -176,6 +178,7 @@ public class Main extends Application {
Button finish = new Button("Finish"); Button finish = new Button("Finish");
finish.setId("sideBarButtonFinish"); finish.setId("sideBarButtonFinish");
finish.setOnAction(e -> Input.display());
// Creating the circular progressbar // Creating the circular progressbar
RingProgressIndicator ringProgressIndicator = new RingProgressIndicator(); RingProgressIndicator ringProgressIndicator = new RingProgressIndicator();
......
File added
No preview for this file type
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.
Please register or to comment