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

Started fixing searching for parameters

parent 1ddcc128
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ public class DB {
//getKwh();
//getName();
//getZeroPointDate();
System.out.println(setInputParameters());
System.out.println(setInputParameters(false,false,false,false));
}
......@@ -128,15 +128,23 @@ public class DB {
}
public static Map<Integer, Map<String, Number>> setInputParameters() throws Exception {
public static Map<Integer, Map<String, Number>> setInputParameters(boolean sawsetRemoved,
boolean treespeciesRemoved,
boolean dimensionsRemoved,
boolean moistureRemoved) throws Exception {
//public static Map<String, String> setInputParameters() throws Exception {
Map<Integer, Map<String, Number>> allDryingPeriods = new TreeMap<>();
Map<Integer, Map<String, Number>> allDryingPeriods = null;
String extraInputParameter = "";
int locationID = 0;
int locationID;
int index = 0;
String treeSpecies = "";
String dimensions = "";
String sawset = "";
String moistureGoal = "";
// Valmetics parameters
String nameParameter = "";
String kilinName = "";
......@@ -156,6 +164,8 @@ public class DB {
for (HashMap.Entry<Integer, HashMap<String, HashMap<String, String>>> location : Constants.getSawmills().entrySet()) {
System.out.printf("\n\nLocation ID: \t%s\t\t\tRest of map: \t%s\n", location.getKey(), location.getValue());
allDryingPeriods = new TreeMap<>();
locationID = location.getKey();
//System.out.println(location.getValue());
......@@ -208,10 +218,10 @@ public class DB {
String treeSpecies = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + TREE_SPECIES + "%" + '"' + ") ";
String dimensions = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + DIMENSIONS + "%" + '"' + ") ";
String sawset = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + SAWSET + "%" + '"' + ") ";
String moistureGoal = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + MOISTURE_GOAL + "%" + '"' + ") ";
if (!treespeciesRemoved) treeSpecies = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + TREE_SPECIES + "%" + '"' + ") ";
if (!dimensionsRemoved) dimensions = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + DIMENSIONS + "%" + '"' + ") ";
if (!sawsetRemoved) sawset = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + SAWSET + "%" + '"' + ") ";
if (!moistureRemoved) moistureGoal = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + MOISTURE_GOAL + "%" + '"' + ") ";
// Input parameters
......@@ -229,34 +239,40 @@ public class DB {
}
Map<Integer, Map<String, Number>> results = new TreeMap<>();
results = getKwh(getZeroPointDate(locationID, extraInputParameter, nameParameter, kilinName, kilinID, startDryingTime, stopDryingTime, valmeticsTableName, limit),
locationID, kwhTableName, KwhName, timestamp,valueIDName, valueID, index);
while (true) {
System.out.printf("\nExtra parameters:\n %s\n\n", extraInputParameter);
// Retrieves the dates
//results = getKwh(getZeroPointDate(locationID, extraInputParameter, nameParameter, kilinName, kilinID, startDryingTime, stopDryingTime, valmeticsTableName, limit));
results = getKwh(getZeroPointDate(locationID, extraInputParameter, nameParameter, kilinName, kilinID, startDryingTime, stopDryingTime, valmeticsTableName, limit),
locationID, kwhTableName, KwhName, timestamp,valueIDName, valueID, index);
// Checks if any dates where found, if not parameters are removed until dates are found
if (results.size() < NUMBER_OF_PERIODS) {
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(dimensions)) {
extraInputParameter = extraInputParameter.replace(dimensions, "");
System.out.println("Dimensions is removed");
} else if (extraInputParameter.contains(moistureGoal)) {
extraInputParameter = extraInputParameter.replace(moistureGoal, "");
System.out.println("Moisture goal is removed");
} else break;
} else break;
}
allDryingPeriods.putAll(results);
index += results.size();
}
while (true) {
System.out.printf("\nExtra parameters:\n %s\n\n", extraInputParameter);
// Retrieves the dates
//results = getKwh(getZeroPointDate(locationID, extraInputParameter, nameParameter, kilinName, kilinID, startDryingTime, stopDryingTime, valmeticsTableName, limit));
// Checks if any dates where found, if not parameters are removed until dates are found
if (allDryingPeriods.size() < NUMBER_OF_PERIODS) {
if (extraInputParameter.contains(sawset) && !sawsetRemoved) {
extraInputParameter = extraInputParameter.replace(sawset, "");
System.out.println("Sawset is removed");
setInputParameters(true,false,false,false);
} else if (extraInputParameter.contains(treeSpecies) && !treespeciesRemoved) {
extraInputParameter = extraInputParameter.replace(treeSpecies, "");
System.out.println("Tree species is removed");
setInputParameters(true,true,false,false);
} else if (extraInputParameter.contains(dimensions) && !dimensionsRemoved) {
extraInputParameter = extraInputParameter.replace(dimensions, "");
System.out.println("Dimensions is removed");
setInputParameters(true,true,true,false);
} else if (extraInputParameter.contains(moistureGoal) && !moistureRemoved) {
extraInputParameter = extraInputParameter.replace(moistureGoal, "");
System.out.println("Moisture goal is removed");
setInputParameters(true,true,true,true);
} else break;
} else break;
}
System.out.println(allDryingPeriods.size());
for (Map.Entry<Integer, Map<String, Number>> entry : allDryingPeriods.entrySet()) {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n", entry.getKey(), entry.getValue());
......
......@@ -4,10 +4,13 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.chart.LineChart;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import java.util.concurrent.*;
import static com.application.DB.Constants.*;
import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters;
......@@ -22,6 +25,19 @@ import static com.application.GUI.LineChartFunctionality.loadSingleSeries;
*/
public class InputPopUpWindow {
public static CompletableFuture<LineChart<String, Number>> getData(){
CompletableFuture<LineChart<String, Number>> completableFuture = new CompletableFuture<>();
Executors.newCachedThreadPool().submit(() -> {
Thread.sleep(500);
completableFuture.complete(loadSingleSeries(setInputParameters(false,
false,false,false)));
return null;
});
return completableFuture;
}
public static void display() {
Stage window = new Stage();
......@@ -110,10 +126,18 @@ public class InputPopUpWindow {
MOISTURE_GOAL = moistureList.getValue();
// If the input is null, sets the 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 = "";}
if (treeSpeciesList.getValue() == null) {
TREE_SPECIES = "";
}
if (dimensionsList.getValue() == null) {
DIMENSIONS = "";
}
if (sawsetList.getValue() == null) {
SAWSET = "";
}
if (moistureList.getValue() == null) {
MOISTURE_GOAL = "";
}
setTreeSpeciesText(TREE_SPECIES);
setDimensionsText(DIMENSIONS);
......@@ -123,8 +147,30 @@ public class InputPopUpWindow {
window.close();
/*
FutureTask[] randomNumberTasks = new FutureTask[1];
Callable callable = new CallableExample();
randomNumberTasks[0] = new FutureTask(callable);
Thread t = new Thread(randomNumberTasks[0]);
t.start();
try {
loadSingleSeries(setInputParameters());
System.out.println(randomNumberTasks[0].get());
} catch (InterruptedException | ExecutionException ex) {
ex.printStackTrace();
}
});
*/
try {
getData();
//loadSingleSeries(setInputParameters(false,false,false,false));
//loadMultipleSeries(setInputParameters());
//loadSingleSeries();
//loadMultipleSeries();
......@@ -135,7 +181,11 @@ public class InputPopUpWindow {
);
/*
/*
try{
Thread thread = new Thread(new Runnable() {
......@@ -143,7 +193,7 @@ public class InputPopUpWindow {
public void run() {
try {
// Henter her data fra databasen
loadSingleSeries(setInputParameters());
loadSingleSeries(setInputParameters(false,false,false,false));
//loadSingleSeries();
//loadMultipleSeries();
} catch (Exception ex) {
......@@ -158,7 +208,7 @@ public class InputPopUpWindow {
}
);
*/
*/
/*
// Fungerende ny thread!!@@@@@
......
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.
Finish editing this message first!
Please register or to comment