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

Merge branch 'Eilerts_branch' into 'master'

Eilerts branch

See merge request mesji/bacheloroppgave_2022!36
parents 9337a676 a1c06e04
No related branches found
No related tags found
No related merge requests found
......@@ -25,11 +25,15 @@ public final class Constants {
public static String SAWSET = "";
public static String MOISTURE_GOAL = "";
// Number of wanted drying periods
public static int NUMBER_OF_PERIODS = 2;
// Database ID/name
public static final String PROJECT_ID = "sf-drying-optimization";
/*
// Location Valasen(124)
// Project settings
public static final int LOCATION_ID = 124;
......@@ -44,6 +48,7 @@ public final class Constants {
public static final String KILIN_NAME = "KilnName";
public static int KILIN_ID = 5; // Kammer 5
//public static int KILIN_ID = 6; // Kammer 6
public static final int LIMIT = 1000;
// Winccsensordata
public static final String KWH_NAME = "VariantValue";
......@@ -51,14 +56,16 @@ public final class Constants {
public static final String VALUE_ID_NAME = "ValueID";
public static final int VALUE_ID = 51; // Kammer 5
//public static final int VALUE_ID = 56; // Kammer 6
public static final int LIMIT = 1000;
*/
/*
// Location Arjang(174)
// Project settings
public static final int LOCATION_ID = 174;
......@@ -71,15 +78,20 @@ public final class Constants {
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 = 18554;
public static int KILIN_ID = 18;
//public static int KILIN_ID = 18554;
public static final int LIMIT = 1000;
// 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;
*/
......
......@@ -57,7 +57,7 @@ public class DB {
* @throws Exception throws exception in case of error
*/
public static void main(String[] args) throws Exception {
getKwh();
//getKwh();
//getName();
//getZeroPointDate();
}
......@@ -125,6 +125,78 @@ public class DB {
}
public static Map<Integer, Map<String, Number>> setInputParameters() throws Exception {
String extraInputParameter = "";
String treeSpecies = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ TREE_SPECIES +"%"+'"'+" ";
String width = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ WIDTH_DIMENTION +"%"+'"'+" ";
String height = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ HEIGHT_DIMENTION +"%"+'"'+" ";
String widthXHeight = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ WIDTH_DIMENTION+"x"+HEIGHT_DIMENTION +"%"+'"'+" ";
String sawset = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ SAWSET +"%"+'"'+" ";
String moistureGoal = "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ MOISTURE_GOAL+'%' +"%"+'"'+" ";
System.out.printf("Tree species: \t%s\n",TREE_SPECIES);
System.out.printf("Width: \t\t\t%s\n",WIDTH_DIMENTION);
System.out.printf("Height: \t\t%s\n",HEIGHT_DIMENTION);
System.out.printf("Sawset: \t\t%s\n",SAWSET);
System.out.printf("Moisture: \t\t%s\n",MOISTURE_GOAL);
// Input parameters
if(!TREE_SPECIES.isEmpty()){
extraInputParameter += treeSpecies;
}
if(!WIDTH_DIMENTION.isEmpty() && !HEIGHT_DIMENTION.isEmpty()){
extraInputParameter += widthXHeight;
}
else if(!WIDTH_DIMENTION.isEmpty()){
extraInputParameter += width;
}
else if(!HEIGHT_DIMENTION.isEmpty()){
extraInputParameter += height;
}
if(!SAWSET.isEmpty()){
extraInputParameter += sawset;
}
if(!MOISTURE_GOAL.isEmpty()){
extraInputParameter += moistureGoal;
}
Map<String, String> results = new HashMap<>();
while(true){
System.out.printf("\nExtra parameters:\n %s\n\n",extraInputParameter);
// Retrieves the dates
results = getZeroPointDate(extraInputParameter);
// Checks if any dates where found, if not parameters are removed until dates are found
if(results.size()<NUMBER_OF_PERIODS){
if(extraInputParameter.contains(width)) {
extraInputParameter = extraInputParameter.replace(width,"");
System.out.println("Width is removed");
} else if(extraInputParameter.contains(sawset)) {
extraInputParameter = extraInputParameter.replace(sawset,"");
System.out.println("Sawset is removed");
} else if(extraInputParameter.contains(treeSpecies)) {
extraInputParameter = extraInputParameter.replace(treeSpecies,"");
System.out.println("Tree species is removed");
} else if(extraInputParameter.contains(height)) {
extraInputParameter = extraInputParameter.replace(height,"");
System.out.println("Height is removed");
} else if(extraInputParameter.contains(widthXHeight)) {
extraInputParameter = extraInputParameter.replace(widthXHeight,"");
System.out.println("widthXHeight is removed");
} else if(extraInputParameter.contains(moistureGoal)) {
extraInputParameter = extraInputParameter.replace(moistureGoal,"");
System.out.println("Moisture goal is removed");
} else break;
}
else break;
}
return getKwh(results);
}
/**
* Retrieves information about kWh and the corresponding date
......@@ -132,14 +204,14 @@ public class DB {
* @return the results
* @throws Exception returns potential error
*/
public static Map<Integer, Map> getKwh() throws Exception {
public static Map<Integer, Map<String, Number>> getKwh(Map<String, String> dates) throws Exception {
// Initializing the data map to store the results
Map<Integer, Map> finalResults = new HashMap<>();
Map<Integer, Map<String, Number>> finalResults = new HashMap<>();
int index = 0;
for (Map.Entry<String, String> entry : getZeroPointDate().entrySet()) {
for (Map.Entry<String, String> entry : dates.entrySet()) {
//System.out.printf("Intid: \t%s\t\t\tOuttid: \t%s\n",entry.getKey(),entry.getValue());
// Initializing the data map to store the results
......@@ -201,10 +273,10 @@ public class DB {
System.out.println("\nFinal results size: "+finalResults.size());
// Defining a treemap to sort the data incrementally
NavigableMap<Integer, Map> sortedFinalResults = new TreeMap<>(finalResults);
NavigableMap<Integer, Map<String, Number>> sortedFinalResults = new TreeMap<>(finalResults);
for (Map.Entry<Integer, Map> entry : sortedFinalResults.entrySet()) {
for (Map.Entry<Integer, Map<String, Number>> entry : sortedFinalResults.entrySet()) {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
}
......@@ -224,7 +296,7 @@ public class DB {
* @return Returns a treemap that sorts the Start- and End time for each drying period incrementally
* @throws Exception Throws exception if an error occurs
*/
private static Map<String, String> getZeroPointDate() throws Exception{
private static Map<String, String> getZeroPointDate(String extraUserInput) throws Exception{
// Initializing the dates map to store the results
Map<String, String> dates = new HashMap<>();
......@@ -240,6 +312,7 @@ public class DB {
// Defining extra parameters if required
String extraInputParameter = "";
extraInputParameter += extraUserInput;
if(LOCATION_ID == 124){
extraInputParameter += "AND CalculatedStart BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" ";
}
......@@ -247,24 +320,6 @@ public class DB {
// KILIN_ID starts at 0 not 1 in the database.
KILIN_ID -= 1;
}
// Input parameters
if(!TREE_SPECIES.isEmpty()){
extraInputParameter += "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ TREE_SPECIES +"%"+'"'+" ";
}
if(!WIDTH_DIMENTION.isEmpty()){
extraInputParameter += "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ WIDTH_DIMENTION +"%"+'"'+" ";
}
if(!HEIGHT_DIMENTION.isEmpty()){
extraInputParameter += "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ HEIGHT_DIMENTION +"%"+'"'+" ";
}
if(!SAWSET.isEmpty()){
extraInputParameter += "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ SAWSET +"%"+'"'+" ";
}
if(!MOISTURE_GOAL.isEmpty()){
extraInputParameter += "AND " +NAME_PARAMATERS+ " LIKE "+'"'+"%"+ MOISTURE_GOAL +"%"+'"'+" ";
}
// Sqlstatement for Valåsen(124)
final String sqlStatement =
......@@ -305,6 +360,9 @@ public class DB {
String formatedInTidTork = "";
String formatedUtTidTork = "";
System.out.println(row.get("DryingSchedule").getStringValue());
//System.out.println("Start: "+row.get("DryingStarted").getTimestampValue());
//System.out.println("Stop: "+row.get("DryingCompleted").getTimestampValue());
......@@ -372,12 +430,13 @@ public class DB {
// Defining a treemap to sort the data incrementally
NavigableMap<String, String> sortedFinalResults = new TreeMap<>(dates);
System.out.println("\n");
for (Map.Entry<String, String> entry : sortedFinalResults.entrySet()) {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
System.out.printf("Intid: \t%s\t\t\tUttid: \t%s\n",entry.getKey(),entry.getValue());
}
System.out.printf("Size of dates: %s\n\n", dates.size());
System.out.printf("Size of dates: %s\n\n", sortedFinalResults.size());
// Returns a treemap that sorts the dates incrementally
......
......@@ -7,7 +7,6 @@ import javafx.scene.layout.*;
import javafx.stage.*;
import static com.application.DB.Constants.*;
import com.application.Main;
/**
* This class handles the popup input window
......@@ -72,18 +71,22 @@ public class InputPopUpWindow {
startButton.setOnAction(e -> {
TREE_SPECIES = treeSpeciesInputText.getText();
WIDTH_DIMENTION = treeSpeciesInputText.getText();
WIDTH_DIMENTION = widthInputText.getText();
HEIGHT_DIMENTION = heightInputText.getText();
SAWSET = sawsetInputText.getText();
MOISTURE_GOAL = moistureGoalInputText.getText();
window.close();
// Call på getKwh()
try {
//LineChartFunctionality.loadSingleSeries();
LineChartFunctionality.loadMultipleSeries();
//Main.createLineChart();
} catch (Exception ex) {
ex.printStackTrace();
}
window.close();
});
VBox layout = new VBox(10);
......
package com.application.GUI;
import com.application.DB.DB;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import java.util.Map;
public class LineChartFunctionality {
private LineChart<String, Number> lineChart;
private XYChart.Series<String, Number> series;
private final CategoryAxis xAxis;
private final NumberAxis yAxis;
private static LineChart<String, Number> lineChart;
private static XYChart.Series<String, Number> series;
private static XYChart.Data<String, Number> chartData;
private static CategoryAxis xAxis;
private static NumberAxis yAxis;
public LineChartFunctionality(){
this.xAxis = new CategoryAxis();
this.yAxis = new NumberAxis();
this.series = new XYChart.Series<String, Number>();
this.lineChart = new LineChart<>(xAxis,yAxis);
this.lineChart.getData().add(series);
this.xAxis.setLabel("Date");
this.yAxis.setLabel("Kwh");
this.lineChart.setTitle("Drying Processes");
xAxis = new CategoryAxis();
yAxis = new NumberAxis();
series = new XYChart.Series<String, Number>();
chartData = new XYChart.Data<String, Number>();
lineChart = new LineChart<>(xAxis,yAxis);
xAxis.setLabel("Date");
yAxis.setLabel("Kwh");
lineChart.setTitle("Drying Processes");
}
public LineChart<String, Number> getLineChart() {
return this.lineChart;
return lineChart;
}
public static XYChart.Series<String, Number> getSeries() {
return series;
}
public void setLineChart(LineChart<String, Number> lineChart) {
this.lineChart = lineChart;
public static void updateLineChart(XYChart.Series<String, Number> series){
lineChart.getData().add(series);
}
public XYChart.Series<String, Number> getSeries() {
return this.series;
public static void clearLineChart(){
lineChart.getData().clear();
}
public void setSeries(XYChart.Series<String, Number> series) {
this.series = series;
this.lineChart.getData().add(series);
public static void loadSingleSeries() throws Exception {
clearLineChart();
Map<Integer, Map<String, Number>> kWh = DB.setInputParameters();
//System.out.println(kWh.size());
for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
//System.out.println(data.size());
XYChart.Series<String, Number> newSeries = new XYChart.Series<String, Number>();
int index = 0;
for (Object entryData : data.entrySet()) {
//System.out.println("data: \t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(index), kwhValue));
index += 1;
}
updateLineChart(newSeries);
}
}
public static void loadMultipleSeries() throws Exception {
Map<Integer, Map<String, Number>> kWh = DB.setInputParameters();
//System.out.println(kWh.size());
for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
//System.out.println(data.size());
XYChart.Series<String, Number> newSeries = new XYChart.Series<String, Number>();
for (Object entryData : data.entrySet()){
//System.out.println("data: \t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(date,kwhValue));
}
updateLineChart(newSeries);
}
/*
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
System.out.printf("Index: \t%s\t\t\tkWh: \t%s\n",entryKwh.getKey(),entryKwh.getValue());
}
*/
}
}
......@@ -266,40 +266,6 @@ public class Main extends Application {
return new HBox(imageViewM, region1, imageViewTitle, region2);
}
/*
Map<Integer, Map> kWh = DB.getKwh();
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
XYChart.Series series = new XYChart.Series();
for (Object entryData : data.entrySet()){
//System.out.println("data: \t\t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
//System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
series.getData().add(new XYChart.Data(date,kwhValue));
}
lineChart.getData().add(series);
//System.out.println("\n\nNew line\n\n");
}
*/
/*
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
System.out.printf("Index: \t%s\t\t\tkWh: \t%s\n",entryKwh.getKey(),entryKwh.getValue());
}
*/
}
No preview for this file type
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