diff --git a/src/main/java/com/application/DB/DB.java b/src/main/java/com/application/DB/DB.java index 344382b2143fed164b00aea6c2597f7408cbfd50..cf7c7d89f78b46132533fbfb15ba35b7b7eb3065 100644 --- a/src/main/java/com/application/DB/DB.java +++ b/src/main/java/com/application/DB/DB.java @@ -13,36 +13,28 @@ import static com.application.DB.HelpingFunctions.getNoOfChambers; * This class is responsible for handling database related activities * * @author Eilert Tunheim, Karin Pettersen, Mads Arnesen - * @version 1.0 + * @version 1.0.0 */ public class DB { /** - * Launching the functions + * This function gathers all input parameters from the user and search for data * - * @param args default param - * @throws Exception throws exception in case of error + * @return a map containing drying cycles + * @throws Exception throws exception if error occurs */ - public static void main(String[] args) throws Exception { - //getKwh(); - //getName(); - //getZeroPointDate(); - //System.out.println(setInputParameters()); - //getNoOfChambers(); - - } - - public static Map<Integer, Map<String, Number>> setInputParameters() throws Exception { + // Map to store data Map<Integer, Map<String, Number>> allDryingPeriods = new HashMap<>(); + // Variables to indicate if the parameters have been deleted or not boolean sawsetRemoved = false; boolean treespeciesRemoved = false; boolean dimensionsRemoved = false; boolean moistureRemoved = false; - + // Defining variables HashMap<java.lang.String, java.lang.String> locationTables = null; ArrayList<Integer> valmeticsChamberIDS = null; ArrayList<Integer> kwhChamberIDS = null; @@ -76,11 +68,13 @@ public class DB { getNoOfChambers(); int chamberNo = 1; - + // While loop that check for data while(true){ + // Map to store data Map<Integer, Map<String, Number>> intermediateHashMap = new HashMap<>(); + // Iterating through all the sawmills for (HashMap.Entry<Integer, HashMap<String, HashMap<String, String>>> location : Settings.getSawmills().entrySet()) { // Clears the extraInputs variable @@ -89,12 +83,9 @@ public class DB { System.out.printf("\nLocation ID: \t%s\t\t\tRest of map: \t%s\n", location.getKey(), location.getValue()); System.out.println("Number of sawmills: "+ Settings.getSawmills().size()); - //allDryingPeriods = new TreeMap<>(); - locationID = location.getKey(); - //System.out.println(location.getValue()); - + // If the location is 124, "Furu" is stored as "Fura" in the database, swedish if (location.getKey() == 124) { // If location is Valasen, then the database stores furu as fura, swedish. if (Constants.TREE_SPECIES.equalsIgnoreCase("Furu")) { @@ -226,6 +217,7 @@ public class DB { } } + // Prints all the drying periods 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()); @@ -283,7 +275,7 @@ public class DB { finalResults.put(index, sortedData); index += 1; - // entry.value burde matche med en av de og går igjennom alle + // checks for manual moisture for (Map.Entry<String, String> moistureEntry : HelpingFunctions.getManMoist().entrySet()) { if(moistureEntry.getKey().equals(entry.getValue())){ @@ -304,17 +296,7 @@ public class DB { // Defining a treemap to sort the data incrementally NavigableMap<Integer, Map<String, Number>> sortedFinalResults = new TreeMap<>(finalResults); - for (Map.Entry<Integer, Map<String, Number>> entry : sortedFinalResults.entrySet()) { - - Map<String, Number> data = entry.getValue(); - for (Map.Entry<String, Number> moistureEntry : data.entrySet()) { - - //System.out.println("Data key: "+moistureEntry.getKey()); // Key = datetime: 2022-01-18 20:23:36 - //System.out.println("Data Value: "+moistureEntry.getValue()); // Value = kwh: 5422 - } - - } - + // Prints the values 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()); } @@ -388,8 +370,6 @@ public class DB { kilinID += 1; } - - // Retrieves the results from the queryjob TableResult result = HelpingFunctions.createQueryJob(sqlStatement); @@ -420,11 +400,6 @@ public class DB { } } - - //System.out.println("Start: "+row.get("DryingStarted").getTimestampValue()); - //System.out.println("Stop: "+row.get("DryingCompleted").getTimestampValue()); - - // Retrieving the data // DryingStarted: if(!row.get("DryingStarted").isNull()){ @@ -451,14 +426,8 @@ public class DB { } else formatedInTidTork = row.get("DryingStarted").getValue().toString(); } - - // Checks if response is given in a string date format - //if(row.get("DryingStarted").getValue().equals(Long.parseLong(row.get("DryingStarted").getValue().toString()))) { - - } - // CalculatedStop: // DryingCompleted: // Check if response is given in millis try{ @@ -481,8 +450,6 @@ public class DB { } - - // Getting manual measurement: // Adding days to search between String date = formatedUtTidTork.split(" ")[0]; @@ -529,18 +496,11 @@ public class DB { */ - - - - //System.out.println("Inn formated: "+formatedInTidTork); - //System.out.println("Ut formated: "+formatedUtTidTork+"\n"); - // Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list if (!formatedInTidTork.isEmpty() && !formatedUtTidTork.isEmpty()){ // Adds the data to the dates map dates.put(formatedInTidTork,formatedUtTidTork); } - //System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork); } // Defining a treemap to sort the data incrementally @@ -566,6 +526,12 @@ public class DB { } + /** + * This function push the manual moisture level + * + * @param moisture input parameter for measured value + * @throws Exception throws exception in case of error + */ public static void pushManMoisture(String moisture) throws Exception { String startTime = null; @@ -639,11 +605,8 @@ public class DB { // Retrieves the results from the queryjob TableResult result = HelpingFunctions.createQueryJob(sqlStatement); - //System.out.println("InTidTork\t\t\tUtTidTork"); // Iterating through the results HelpingFunctions.iterateKwhValues(data, result, KWH_NAME_PARAMETER, KWH_TIMESTAMP_NAME_PARAMETER); return new TreeMap<>(data); } - - }