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

Added function to search for live data during drying process

parent 675052bf
No related branches found
No related tags found
No related merge requests found
...@@ -18,10 +18,9 @@ public final class Constants { ...@@ -18,10 +18,9 @@ public final class Constants {
// Today's date // Today's date
public static final String TODAYS_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()); public static final String TODAYS_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
// Start- & end time // Start- & end time
public static String START_TIME = ""; public static String START_TIME = "";
public static String STOP_TIME = ""; public static String STOP_TIME = TODAYS_DATE;
// User inputs // User inputs
public static String TREE_SPECIES = ""; public static String TREE_SPECIES = "";
...@@ -35,11 +34,15 @@ public final class Constants { ...@@ -35,11 +34,15 @@ public final class Constants {
// Non linear regression // Non linear regression
public static final double ADJUST_REGRESSION = 5.5; public static final double ADJUST_REGRESSION = 5.5;
// Database ID/name // Current sawmill settings;
public static final String PROJECT_ID = "sf-drying-optimization"; public static final String PROJECT_ID = "sf-drying-optimization";
public static final int LOCATION_ID = 124; public static final int LOCATION_ID = 124;
public static final String MAN_MOISTURE_TABLE = "int_dk_manMoisture"; public static final String MAN_MOISTURE_TABLE = "int_dk_manMoisture";
public static final String KWH_TABLE_NAME = "int_sd_winccsensordata";
public static final String KWH_NAME_PARAMETER = "VariantValue";
public static final String KWH_TIMESTAMP_NAME_PARAMETER = "Timestamp";
public static final String KWH_VALUE_ID_NAME_PARAMETER = "ValueID";
public static final String KWH_VALUE_ID_VALUE_PARAMETER = "51"; // Which chamber is used
// Location Valasen(124) // Location Valasen(124)
......
...@@ -267,31 +267,7 @@ public class DB { ...@@ -267,31 +267,7 @@ public class DB {
//System.out.println("Timestamp \t kWh"); //System.out.println("Timestamp \t kWh");
int baseline = 0; int baseline = 0;
for (FieldValueList row : result.iterateAll()) { HelpingFunctions.iterateKwhValues(data, baseline, result, KwhName, timestamp);
// Sets the baseline in order to reset the kWh counter
if (baseline == 0) {
baseline = row.get("" + KwhName + "").getNumericValue().intValue();
}
//System.out.println("baseline: "+baseline);
// kWh value
int variantValue = row.get("" + KwhName + "").getNumericValue().intValue() - baseline; //-baseline
// Retrieving the wanted data
long timeStamp = row.get("" + timestamp + "").getTimestampValue() / 1000;
// Riktig format, men i string
String formatedTimeStamp = HelpingFunctions.getDateFormat().format(timeStamp);
// Checks for negative values
if (variantValue > 0) {
// Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue);
}
//System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\t\t\tBaseline: %s\n",formatedTimeStamp,variantValue,baseline);
// Checks if the data is empty
}
System.out.println("Data size: " + data.size()); System.out.println("Data size: " + data.size());
...@@ -597,4 +573,39 @@ public class DB { ...@@ -597,4 +573,39 @@ public class DB {
HelpingFunctions.createQueryJob(sqlStatement); HelpingFunctions.createQueryJob(sqlStatement);
} }
/**
* Retrieves data from current drying process
*
* @return a map consisting of Timestamp(date&time) and Kwh value
* @throws Exception throws execution if anything is wrong
*/
public static Map<String, Number> getCurrentDrying() throws Exception {
// Initializing the data map to store the results
Map<String, Number> data = new HashMap<>();
// Initializing baseline
int baseline = 0;
// Sqlstatement
final String sqlStatement = "SELECT `" + KWH_TIMESTAMP_NAME_PARAMETER + "`, `" + KWH_NAME_PARAMETER + "` " +
"FROM `" + PROJECT_ID + "." + LOCATION_ID + "." + KWH_TABLE_NAME + "` " +
"WHERE " + KWH_TIMESTAMP_NAME_PARAMETER + " BETWEEN " + '"' + START_TIME + '"' +
" AND " + '"' + STOP_TIME + '"' +
" AND " + KWH_VALUE_ID_NAME_PARAMETER + " = " + KWH_VALUE_ID_VALUE_PARAMETER + " " +
" AND " + KWH_NAME_PARAMETER + " <> 0 " +
" ORDER BY " + KWH_TIMESTAMP_NAME_PARAMETER + " ASC";
System.out.println(sqlStatement);
// 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, baseline, result, KWH_NAME_PARAMETER, KWH_TIMESTAMP_NAME_PARAMETER);
return new TreeMap<>(data);
}
} }
...@@ -117,4 +117,36 @@ public class HelpingFunctions { ...@@ -117,4 +117,36 @@ public class HelpingFunctions {
public static Map<String, String> getManMoist() { public static Map<String, String> getManMoist() {
return manMoist; return manMoist;
} }
/**
* Function to iterate through all the Kwh values and storing them in a map
*
* @param data a map to store all the data
* @param baseline a baseline to base all the next values of to get a zero point
* @param result TableResult to iterate through
* @param kwhNameParameter Name of the Kwh name parameter in the database
* @param kwhTimestampNameParameter Name of the timestamp parameter in the database
*/
static void iterateKwhValues(Map<String, Number> data, int baseline, TableResult result, String kwhNameParameter, String kwhTimestampNameParameter) {
for (FieldValueList row : result.iterateAll()) {
// Sets the baseline in order to reset the kWh counter
if (baseline == 0) {
baseline = row.get("" + kwhNameParameter + "").getNumericValue().intValue();
}
// kWh value
int variantValue = row.get("" + kwhNameParameter + "").getNumericValue().intValue() - baseline; //-baseline
// Retrieving the wanted data
long timeStamp = row.get("" + kwhTimestampNameParameter + "").getTimestampValue() / 1000;
// Riktig format, men i string
String formatedTimeStamp = getDateFormat().format(timeStamp);
// Checks for negative values
if (variantValue > 0) {
// Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue);
}
}
}
} }
...@@ -13,6 +13,7 @@ import java.util.Map; ...@@ -13,6 +13,7 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying;
import static com.application.Main.*; import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters; import static com.application.DB.DB.setInputParameters;
import static com.application.GUI.LineChartFunctionality.loadSingleSeries; import static com.application.GUI.LineChartFunctionality.loadSingleSeries;
...@@ -247,7 +248,31 @@ public class InputPopUpWindow { ...@@ -247,7 +248,31 @@ public class InputPopUpWindow {
ex.printStackTrace(); ex.printStackTrace();
} }
// Retrieve data for current drying period
try{
Thread thread = new Thread(() -> {
try {
// Henter her data fra databasen
Map<String, Number> data = getCurrentDrying();
Platform.runLater(() -> {
try {
//loadSingleSeries(data);
} catch (Exception ex) {
ex.printStackTrace();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
} }
......
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