diff --git a/src/main/java/com/application/DB/Constants.java b/src/main/java/com/application/DB/Constants.java index 69d7d928f0b96be4e6558fc6520c310fe79e779a..b2f5926f17177cd6541a05c39dd4df3029c1f172 100644 --- a/src/main/java/com/application/DB/Constants.java +++ b/src/main/java/com/application/DB/Constants.java @@ -20,14 +20,13 @@ public final class Constants { // User inputs public static String TREE_SPECIES = ""; - public static String WIDTH_DIMENTION = ""; - public static String HEIGHT_DIMENTION = ""; + public static String DIMENSIONS = ""; public static String SAWSET = ""; public static String MOISTURE_GOAL = ""; // Number of wanted drying periods - public static int NUMBER_OF_PERIODS = 2; + public static int NUMBER_OF_PERIODS = 1; // Database ID/name public static final String PROJECT_ID = "sf-drying-optimization"; diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java index 7e976b115dd7dde36f660be69468b0d51ac4ea52..670782dfc726919e504465964010cf9a3c1cc8ad 100644 --- a/src/main/java/com/application/DB/DB.java +++ b/src/main/java/com/application/DB/DB.java @@ -127,32 +127,30 @@ 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+'%' +"%"+'"'+" "; + // If location is Valasen, then the database stores furu as fura, swedish. + if(LOCATION_ID == 124 && TREE_SPECIES.equalsIgnoreCase("Furu")) { + TREE_SPECIES = "Fura"; + } 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("Width: \t\t\t%s\n",DIMENSIONS); System.out.printf("Sawset: \t\t%s\n",SAWSET); System.out.printf("Moisture: \t\t%s\n",MOISTURE_GOAL); + String extraInputParameter = ""; + String treeSpecies = "AND LOWER(" +NAME_PARAMATERS+ ") LIKE LOWER("+'"'+"%"+ TREE_SPECIES +"%"+'"'+") "; + String dimensions = "AND LOWER(" +NAME_PARAMATERS+ ") LIKE LOWER("+'"'+"%"+ DIMENSIONS +"%"+'"'+") "; + String sawset = "AND LOWER(" +NAME_PARAMATERS+ ") LIKE LOWER("+'"'+"%"+ SAWSET +"%"+'"'+") "; + String moistureGoal = "AND LOWER(" +NAME_PARAMATERS+ ") LIKE LOWER("+'"'+"%"+ 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(!DIMENSIONS.isEmpty()){ + extraInputParameter += dimensions; } if(!SAWSET.isEmpty()){ extraInputParameter += sawset; @@ -163,7 +161,7 @@ public class DB { - Map<String, String> results = new HashMap<>(); + Map<String, String> results; while(true){ System.out.printf("\nExtra parameters:\n %s\n\n",extraInputParameter); // Retrieves the dates @@ -171,21 +169,15 @@ public class DB { // 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)) { + 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,""); + } else if(extraInputParameter.contains(dimensions)) { + extraInputParameter = extraInputParameter.replace(dimensions,""); 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"); @@ -329,6 +321,7 @@ public class DB { "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 + + "AND LOWER(" +NAME_PARAMATERS+ ") NOT LIKE LOWER("+'"'+"%"+ "test" +"%"+'"'+") " + "Group by "+ START_DRYING_NAME + " " + "Order by "+ START_DRYING_NAME + " ASC " + "LIMIT " + LIMIT; diff --git a/src/main/java/com/application/GUI/InputPopUpWindow.java b/src/main/java/com/application/GUI/InputPopUpWindow.java index d69a71d019f743952a134e5746d5468f40fd7007..0595c67b0da229f87cd43aec0f87325954b62926 100644 --- a/src/main/java/com/application/GUI/InputPopUpWindow.java +++ b/src/main/java/com/application/GUI/InputPopUpWindow.java @@ -1,16 +1,19 @@ package com.application.GUI; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.geometry.Pos; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; -import org.checkerframework.checker.units.qual.K; import java.util.Map; +import java.util.concurrent.*; import static com.application.DB.Constants.*; import static com.application.DB.DB.setInputParameters; +import static com.application.GUI.LineChartFunctionality.loadMultipleSeries; import static com.application.GUI.LineChartFunctionality.loadSingleSeries; @@ -22,8 +25,13 @@ import static com.application.GUI.LineChartFunctionality.loadSingleSeries; */ public class InputPopUpWindow { - public static void display() - { + private static final Integer SLEEP_MILLS = 3000; + private static final Integer RUN_SLEEP_MILLS = 1000; + private static int afterSeconds = SLEEP_MILLS / RUN_SLEEP_MILLS; + + + + public static void display() { Stage window = new Stage(); window.initModality(Modality.APPLICATION_MODAL); @@ -37,38 +45,60 @@ public class InputPopUpWindow { // Tree species Label treeSpeciesInputLabel = new Label("Tree Species"); treeSpeciesInputLabel.setId("inputLabel"); - TextField treeSpeciesInputText = new TextField(); - treeSpeciesInputText.setId("inputLabelText"); - treeSpeciesInputText.setPromptText("Bjørk"); - treeSpeciesInputText.getText(); - - // Width - Label widthInputLabel = new Label("Width"); - widthInputLabel.setId("inputLabel"); - TextField widthInputText = new TextField(); - widthInputText.setId("inputLabelText"); - widthInputText.setPromptText("47"); - - // Height - Label heightInputLabel = new Label("Height"); - heightInputLabel.setId("inputLabel"); - TextField heightInputText = new TextField(); - heightInputText.setId("inputLabelText"); - heightInputText.setPromptText("200"); + ObservableList<String> treeSpecies = FXCollections.observableArrayList( + "Furu", + "Gran" + ); + ComboBox<String> treeSpeciesList = new ComboBox<String>(treeSpecies); + treeSpeciesList.setPromptText("Select Tree Species"); + treeSpeciesList.setId("inputDropDownBox"); + treeSpeciesList.setEditable(true); + + // Dimensions + Label dimensionsInputLabel = new Label("Dimensions"); + dimensionsInputLabel.setId("inputLabel"); + ObservableList<String> dimensions = FXCollections.observableArrayList( + "47x150", + "47x200", + "50x150", + "50x200" + ); + ComboBox<String> dimensionsList = new ComboBox<String>(dimensions); + dimensionsList.setPromptText("Select Dimensions"); + dimensionsList.setId("inputDropDownBox"); + dimensionsList.setEditable(true); + + // Sawset Label sawsetInputLabel = new Label("Sawset"); sawsetInputLabel.setId("inputLabel"); - TextField sawsetInputText = new TextField(); - sawsetInputText.setId("inputLabelText"); - sawsetInputText.setPromptText("4x"); + ObservableList<String> sawset = FXCollections.observableArrayList( + "1ex", + "2ex", + "3ex", + "4ex" + ); + ComboBox<String> sawsetList = new ComboBox<String>(sawset); + sawsetList.setPromptText("Select Dimensions"); + sawsetList.setId("inputDropDownBox"); + sawsetList.setEditable(true); // Moisture Label moistureGoalInputLabel = new Label("Moisture Goal"); moistureGoalInputLabel.setId("inputLabel"); - TextField moistureGoalInputText = new TextField(); - moistureGoalInputText.setId("inputLabelText"); - moistureGoalInputText.setPromptText("12%"); + ObservableList<String> moistureGoal = FXCollections.observableArrayList( + "10%", + "12%", + "14%", + "16%", + "18%", + "20%" + ); + ComboBox<String> moistureList = new ComboBox<String>(moistureGoal); + moistureList.setPromptText("Select Dimensions"); + moistureList.setId("inputDropDownBox"); + moistureList.setEditable(true);; // Bottom - start button @@ -76,16 +106,89 @@ public class InputPopUpWindow { startButton.setId("inputButtonStart"); startButton.setOnAction(e -> { - TREE_SPECIES = treeSpeciesInputText.getText(); - WIDTH_DIMENTION = widthInputText.getText(); - HEIGHT_DIMENTION = heightInputText.getText(); - SAWSET = sawsetInputText.getText(); - MOISTURE_GOAL = moistureGoalInputText.getText(); + // Retrieves the user inputs + TREE_SPECIES = treeSpeciesList.getValue(); + DIMENSIONS = dimensionsList.getValue(); + SAWSET = sawsetList.getValue(); + MOISTURE_GOAL = moistureList.getValue(); + + // If the input is null, sets the corresponding value to be empty + if(treeSpeciesList.getValue() == null){TREE_SPECIES = "";} + if(dimensionsList.getValue() == null){DIMENSIONS = "";} + if(sawsetList.getValue() == null){SAWSET = "";} + if(moistureList.getValue() == null){MOISTURE_GOAL = "";} + + + + window.close(); + + + try { + loadSingleSeries(setInputParameters()); + //loadMultipleSeries(setInputParameters()); + //loadSingleSeries(); + //loadMultipleSeries(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + ); + + /* + try{ + Thread thread = new Thread(new Runnable() { + + @Override + public void run() { + try { + // Henter her data fra databasen + loadSingleSeries(setInputParameters()); + //loadSingleSeries(); + //loadMultipleSeries(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + thread.start(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + ); + + */ + +/* + // Fungerende ny thread!!@@@@@ + try{ + Thread thread = new Thread(new Runnable() { + + @Override + public void run() { + try { + // Henter her data fra databasen + loadSingleSeries(setInputParameters()); + //loadSingleSeries(); + //loadMultipleSeries(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + }); + thread.start(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } - window.close(); + ); + */ - class KwhThread implements Runnable { +/* + class KwhThread implements Runnable { Map<Integer, Map<String, Number>> dataVariable; private volatile boolean finished; @@ -104,8 +207,6 @@ public class InputPopUpWindow { } } - - public Map<Integer, Map<String, Number>> getDataVariable() throws InterruptedException { synchronized (this){ @@ -129,37 +230,17 @@ public class InputPopUpWindow { } + */ +/* - /* - // Fungerende ny thread!!@@@@@ - try{ - Thread thread = new Thread(new Runnable() { - - @Override - public void run() { - try { - loadSingleSeries(setInputParameters()); - //loadSingleSeries(); - //loadMultipleSeries(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }); - thread.start(); - //thread.join(); - } catch (Exception ex) { - ex.printStackTrace(); - } + */ - */ - }); VBox layout = new VBox(10); - layout.getChildren().addAll(inputLabel, treeSpeciesInputLabel, treeSpeciesInputText, widthInputLabel, widthInputText, heightInputLabel, heightInputText, - sawsetInputLabel, sawsetInputText, moistureGoalInputLabel, moistureGoalInputText, startButton); + layout.getChildren().addAll(inputLabel, treeSpeciesInputLabel, treeSpeciesList, dimensionsInputLabel, dimensionsList, + sawsetInputLabel, sawsetList, moistureGoalInputLabel, moistureList, startButton); layout.setAlignment(Pos.CENTER); Scene scene = new Scene(layout, 600, 500); diff --git a/src/main/java/com/application/GUI/LineChartFunctionality.java b/src/main/java/com/application/GUI/LineChartFunctionality.java index f856137e2c6fce477d7b180b86ba30736784cca9..2aa9836dc1803e90b90ccd6e1f0ffb97d7a63fa2 100644 --- a/src/main/java/com/application/GUI/LineChartFunctionality.java +++ b/src/main/java/com/application/GUI/LineChartFunctionality.java @@ -15,10 +15,10 @@ public class LineChartFunctionality { private static NumberAxis yAxis; - public LineChartFunctionality(){ + public LineChartFunctionality() { xAxis = new CategoryAxis(); yAxis = new NumberAxis(); - lineChart = new LineChart<>(xAxis,yAxis); + lineChart = new LineChart<>(xAxis, yAxis); xAxis.setLabel("Date"); xAxis.setAnimated(false); yAxis.setLabel("Kwh"); @@ -34,11 +34,11 @@ public class LineChartFunctionality { return lineChart; } - public static void updateLineChart(XYChart.Series<String, Number> series){ + public static void updateLineChart(XYChart.Series<String, Number> series) { lineChart.getData().add(series); } - public static void clearLineChart(){ + public static void clearLineChart() { lineChart.getData().clear(); } @@ -75,17 +75,17 @@ public class LineChartFunctionality { return getLineChart(); } - public static void loadMultipleSeries() throws Exception { + public static LineChart<String, Number> loadMultipleSeries(Map<Integer, Map<String, Number>> userInput) throws Exception { - Map<Integer, Map<String, Number>> kWh = DB.setInputParameters(); + //Map<Integer, Map<String, Number>> kWh = DB.setInputParameters(); //System.out.println(kWh.size()); - for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) { + for (Map.Entry<Integer, Map<String, Number>> entryKwh : userInput.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()){ + for (Object entryData : data.entrySet()) { //System.out.println("data: \t"+entryData); String entryString = entryData.toString(); String[] arr = entryString.split("="); @@ -96,18 +96,11 @@ public class LineChartFunctionality { // Connect the data to a series - newSeries.getData().add(new XYChart.Data<String, Number>(date,kwhValue)); + 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()); - } - */ + return getLineChart(); } - } diff --git a/src/main/resources/com.application/CSS/styleSheet.css b/src/main/resources/com.application/CSS/styleSheet.css index 9669a07744aad57b8c6008f9f4901770737b37ed..dcd1a78c1b47dc12787d9e7ad5a46a8a7802d9fd 100644 --- a/src/main/resources/com.application/CSS/styleSheet.css +++ b/src/main/resources/com.application/CSS/styleSheet.css @@ -93,7 +93,7 @@ -fx-font-family: Arial; } -#inputLabelText { +#inputDropDownBox { -fx-pref-height: 17; -fx-translate-x: 5; -fx-max-height: infinity; diff --git a/target/classes/com/application/GUI/InputPopUpWindow.class b/target/classes/com/application/GUI/InputPopUpWindow.class index 5c8bdbb587857b0435a8caf341dc7a0ab82de3d6..9ea2513d2c3ca6d86f03a8c1eccdbd16db02f761 100644 Binary files a/target/classes/com/application/GUI/InputPopUpWindow.class and b/target/classes/com/application/GUI/InputPopUpWindow.class differ