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

minor updates to the priority and the linechart

parent 8d0e638e
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,10 @@ 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";
......@@ -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,7 +56,9 @@ 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;
......@@ -73,13 +80,13 @@ public final class Constants {
public static final String KILIN_NAME = "KilinId";
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;
*/
......@@ -91,4 +98,7 @@ public final class Constants {
}
......@@ -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<String, Number>> 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<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
......@@ -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,9 +7,6 @@ import javafx.scene.layout.*;
import javafx.stage.*;
import static com.application.DB.Constants.*;
import com.application.Main;
import javax.sound.sampled.Line;
/**
* This class handles the popup input window
......@@ -74,19 +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.loadData();
//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.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
......@@ -34,19 +32,52 @@ public class LineChartFunctionality {
return lineChart;
}
public static XYChart.Series<String, Number> getSeries() {
return series;
}
public static void updateLineChart(XYChart.Series<String, Number> series){
lineChart.getData().add(series);
}
public static void loadData() throws Exception {
public static void clearLineChart(){
lineChart.getData().clear();
}
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.getKwh();
Map<Integer, Map<String, Number>> kWh = DB.setInputParameters();
//System.out.println(kWh.size());
for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) {
......@@ -71,6 +102,7 @@ public class LineChartFunctionality {
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());
......@@ -78,7 +110,4 @@ public class LineChartFunctionality {
*/
}
}
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