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

Searching all drying locations before removing user parameters in the search

parent d3222c01
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(false,false,false,false));
System.out.println(setInputParameters());
}
......@@ -127,14 +127,19 @@ public class DB {
}
public static void getData(){
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 = null;
}
public static Map<Integer, Map<String, Number>> setInputParameters() throws Exception {
Map<Integer, Map<String, Number>> allDryingPeriods = new HashMap<>();
boolean sawsetRemoved = false;
boolean treespeciesRemoved = false;
boolean dimensionsRemoved = false;
boolean moistureRemoved = false;
String extraInputParameter = "";
int locationID;
......@@ -161,116 +166,140 @@ public class DB {
String valueIDName = "";
int valueID = 0;
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<>();
while(true){
locationID = location.getKey();
Map<Integer, Map<String, Number>> intermediateHashMap = new HashMap<>();
//System.out.println(location.getValue());
for (HashMap.Entry<Integer, HashMap<String, HashMap<String, String>>> location : Constants.getSawmills().entrySet()) {
if (location.getKey() == 124) {
// Valmetics
valmeticsTableName = getValasenTableNames().get("Valmetics");
nameParameter = location.getValue().get(getValasenTableNames().get("Valmetics")).get("Name");
startDryingTime = location.getValue().get(getValasenTableNames().get("Valmetics")).get("DryingStarted");
stopDryingTime = location.getValue().get(getValasenTableNames().get("Valmetics")).get("DryingStopped");
kilinName = location.getValue().get(getValasenTableNames().get("Valmetics")).get("KilnName");
kilinID = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Valmetics")).get("KilinID"));
limit = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Valmetics")).get("Limit"));
System.out.printf("\nLocation ID: \t%s\t\t\tRest of map: \t%s\n", location.getKey(), location.getValue());
System.out.println("Number of entries: "+Constants.getSawmills().size());
// Kwh
kwhTableName = getValasenTableNames().get("Kwh");
KwhName = location.getValue().get(getValasenTableNames().get("Kwh")).get("KwhName");
timestamp = location.getValue().get(getValasenTableNames().get("Kwh")).get("Timestamp");
valueIDName = location.getValue().get(getValasenTableNames().get("Kwh")).get("ValueIDName");
valueID = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Kwh")).get("ValueID"));
}
if (location.getKey() == 174) {
// Valmetics
valmeticsTableName = getArjangTableNames().get("Valmetics");
nameParameter = location.getValue().get(getArjangTableNames().get("Valmetics")).get("Name");
startDryingTime = location.getValue().get(getArjangTableNames().get("Valmetics")).get("DryingStarted");
stopDryingTime = location.getValue().get(getArjangTableNames().get("Valmetics")).get("DryingStopped");
kilinName = location.getValue().get(getArjangTableNames().get("Valmetics")).get("KilnName");
kilinID = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Valmetics")).get("KilinID"));
limit = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Valmetics")).get("Limit"));
// Kwh
kwhTableName = getArjangTableNames().get("Kwh");
KwhName = location.getValue().get(getArjangTableNames().get("Kwh")).get("KwhName");
timestamp = location.getValue().get(getArjangTableNames().get("Kwh")).get("Timestamp");
valueIDName = location.getValue().get(getArjangTableNames().get("Kwh")).get("ValueIDName");
valueID = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Kwh")).get("ValueID"));
}
//allDryingPeriods = new TreeMap<>();
// If location is Valasen, then the database stores furu as fura, swedish.
if (location.getKey() == 124 && TREE_SPECIES.equalsIgnoreCase("Furu")) {
TREE_SPECIES = "Fura";
}
locationID = location.getKey();
//System.out.println(location.getValue());
System.out.printf("Tree species: \t%s\n", TREE_SPECIES);
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);
if (location.getKey() == 124) {
// Valmetics
valmeticsTableName = getValasenTableNames().get("Valmetics");
nameParameter = location.getValue().get(getValasenTableNames().get("Valmetics")).get("Name");
startDryingTime = location.getValue().get(getValasenTableNames().get("Valmetics")).get("DryingStarted");
stopDryingTime = location.getValue().get(getValasenTableNames().get("Valmetics")).get("DryingStopped");
kilinName = location.getValue().get(getValasenTableNames().get("Valmetics")).get("KilnName");
kilinID = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Valmetics")).get("KilinID"));
limit = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Valmetics")).get("Limit"));
// Kwh
kwhTableName = getValasenTableNames().get("Kwh");
KwhName = location.getValue().get(getValasenTableNames().get("Kwh")).get("KwhName");
timestamp = location.getValue().get(getValasenTableNames().get("Kwh")).get("Timestamp");
valueIDName = location.getValue().get(getValasenTableNames().get("Kwh")).get("ValueIDName");
valueID = Integer.parseInt(location.getValue().get(getValasenTableNames().get("Kwh")).get("ValueID"));
}
if (location.getKey() == 174) {
// Valmetics
valmeticsTableName = getArjangTableNames().get("Valmetics");
nameParameter = location.getValue().get(getArjangTableNames().get("Valmetics")).get("Name");
startDryingTime = location.getValue().get(getArjangTableNames().get("Valmetics")).get("DryingStarted");
stopDryingTime = location.getValue().get(getArjangTableNames().get("Valmetics")).get("DryingStopped");
kilinName = location.getValue().get(getArjangTableNames().get("Valmetics")).get("KilnName");
kilinID = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Valmetics")).get("KilinID"));
limit = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Valmetics")).get("Limit"));
// Kwh
kwhTableName = getArjangTableNames().get("Kwh");
KwhName = location.getValue().get(getArjangTableNames().get("Kwh")).get("KwhName");
timestamp = location.getValue().get(getArjangTableNames().get("Kwh")).get("Timestamp");
valueIDName = location.getValue().get(getArjangTableNames().get("Kwh")).get("ValueIDName");
valueID = Integer.parseInt(location.getValue().get(getArjangTableNames().get("Kwh")).get("ValueID"));
}
// If location is Valasen, then the database stores furu as fura, swedish.
if (location.getKey() == 124 && TREE_SPECIES.equalsIgnoreCase("Furu")) {
TREE_SPECIES = "Fura";
}
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 + "%" + '"' + ") ";
System.out.printf("Tree species: \t%s\n", TREE_SPECIES);
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);
// Input parameters
if (!TREE_SPECIES.isEmpty()) {
extraInputParameter += treeSpecies;
}
if (!DIMENSIONS.isEmpty()) {
extraInputParameter += dimensions;
}
if (!SAWSET.isEmpty()) {
extraInputParameter += sawset;
}
if (!MOISTURE_GOAL.isEmpty()) {
extraInputParameter += moistureGoal;
}
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);
// Defining the extra sql statements for extra parameters
treeSpecies = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + TREE_SPECIES + "%" + '"' + ") ";
dimensions = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + DIMENSIONS + "%" + '"' + ") ";
sawset = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + SAWSET + "%" + '"' + ") ";
moistureGoal = "AND LOWER(" + nameParameter + ") LIKE LOWER(" + '"' + "%" + MOISTURE_GOAL + "%" + '"' + ") ";
// 1. Checking if user input is empty.
// 2. Checking if the extraInputParameter variable already contains the extra parameters,
// if so not adding a second time.
// 3. Checking if the while loop have previously removed the parameter, if so, not adding again.
if (!TREE_SPECIES.isEmpty() && !extraInputParameter.contains(treeSpecies) && !treespeciesRemoved) {
extraInputParameter += treeSpecies;
}
if (!DIMENSIONS.isEmpty() && !extraInputParameter.contains(dimensions) && !dimensionsRemoved) {
extraInputParameter += dimensions;
}
if (!SAWSET.isEmpty() && !extraInputParameter.contains(sawset) && !sawsetRemoved) {
extraInputParameter += sawset;
}
if (!MOISTURE_GOAL.isEmpty() && !extraInputParameter.contains(moistureGoal) && !moistureRemoved) {
extraInputParameter += moistureGoal;
}
System.out.printf("\nExtra parameters:\n %s\n\n", extraInputParameter);
//System.out.println("Før results");
Map<Integer, Map<String, Number>> results = new TreeMap<>(getKwh(getZeroPointDate(locationID, extraInputParameter, nameParameter, kilinName, kilinID, startDryingTime, stopDryingTime, valmeticsTableName, limit),
locationID, kwhTableName, KwhName, timestamp, valueIDName, valueID, index));
//System.out.println("\n\nResults size: "+results.size()+"\n\n");
intermediateHashMap.putAll(results);
index += results.size();
//System.out.println("Etter results");
}
allDryingPeriods.putAll(results);
index += results.size();
}
while (true) {
System.out.printf("\nExtra parameters:\n %s\n\n", extraInputParameter);
System.out.println("\n\nAll drying periods size: "+intermediateHashMap.size()+"\n\n");
// 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 (intermediateHashMap.size() <= NUMBER_OF_PERIODS) {
//System.out.println("\nInni if, sletter parameter:\n");
if (extraInputParameter.contains(sawset) && !sawsetRemoved) {
extraInputParameter = extraInputParameter.replace(sawset, "");
System.out.println("Sawset is removed");
setInputParameters(true,false,false,false);
sawsetRemoved = true;
//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);
treespeciesRemoved = true;
//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);
dimensionsRemoved = true;
//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);
moistureRemoved = true;
//setInputParameters(true,true,true,true);
} else break;
} else break;
} else {
// Adding all periods to the hashmap to return
allDryingPeriods.putAll(intermediateHashMap);
break;
}
}
System.out.println(allDryingPeriods.size());
......
......@@ -30,8 +30,7 @@ public class InputPopUpWindow {
Executors.newCachedThreadPool().submit(() -> {
Thread.sleep(500);
completableFuture.complete(loadSingleSeries(setInputParameters(false,
false,false,false)));
completableFuture.complete(loadSingleSeries(setInputParameters()));
return null;
});
......
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