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

Added function to graph the livedata, should be functional now

parent 1c6ffdf6
Branches
No related tags found
No related merge requests found
......@@ -16,11 +16,14 @@ public final class Constants {
}
// Today's date
public static final String TODAYS_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
public static final String CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
// Start- & end time
public static String START_TIME = "";
public static String STOP_TIME = TODAYS_DATE;
public static String STOP_TIME = CURRENT_DATE;
// Boolean variable to tell if the drying process is finished
public static boolean IS_FINISHED = false;
// User inputs
public static String TREE_SPECIES = "";
......@@ -31,6 +34,9 @@ public final class Constants {
// Number of wanted drying periods
public static int NUMBER_OF_PERIODS = 1;
// Number of seconds to wait before updating live data, in seconds
public static int NUMBER_OF_SECONDS_LIVE_DATA = 10;
// Non linear regression
public static final double ADJUST_REGRESSION = 5.5;
......
......@@ -158,6 +158,7 @@ public class DB {
// Sets the lowest number of chambers to iterate through
assert valmeticsChamberIDS != null;
numberOfChambers = Math.min(valmeticsChamberIDS.size(), kwhChamberIDS.size());
System.out.printf("\nnumberOfChambers: \t%d\n",numberOfChambers);
......@@ -297,10 +298,6 @@ public class DB {
// Defining a treemap to sort the data incrementally
NavigableMap<Integer, Map<String, Number>> sortedFinalResults = new TreeMap<>(finalResults);
for (Map.Entry<String, String> entry : dates.entrySet()) {
}
for (Map.Entry<Integer, Map<String, Number>> entry : sortedFinalResults.entrySet()) {
Map<String, Number> data = entry.getValue();
......@@ -357,7 +354,7 @@ public class DB {
String extraInputParameter = "";
extraInputParameter += extraUserInput;
if(locationID == 124){
extraInputParameter += "AND CalculatedStart BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" ";
extraInputParameter += "AND CalculatedStart BETWEEN \"1990-01-01 00:00:00\" AND \"" + CURRENT_DATE + "\" ";
}
if(locationID == 174){
// KILIN_ID starts at 0 not 1 in the database.
......@@ -370,8 +367,8 @@ public class DB {
"SELECT MAX("+ nameParameter +") as DryingSchedule, MAX("+kilinName+") as Kiln_ID, " + startDryingTime + ", MAX("+stopDryingTime+") as DryingCompleted " +
"FROM `" + PROJECT_ID + "." + locationID + "." + valmeticsTableName + "` " +
"WHERE " + kilinName + " = " + kilinID + " " +
"AND "+startDryingTime+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND "+stopDryingTime+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + TODAYS_DATE + "\" " +
"AND "+startDryingTime+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + CURRENT_DATE + "\" " +
"AND "+stopDryingTime+" BETWEEN \"1990-01-01 00:00:00\" AND \"" + CURRENT_DATE + "\" " +
extraInputParameter +
"AND LOWER(" +nameParameter+ ") NOT LIKE LOWER("+'"'+"%"+ "test" +"%"+'"'+") " +
"Group by "+ startDryingTime + " " +
......
......@@ -9,11 +9,13 @@ import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying;
import static com.application.GUI.LineChartFunctionality.loadLiveData;
import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters;
import static com.application.GUI.LineChartFunctionality.loadSingleSeries;
......@@ -118,7 +120,7 @@ public class InputPopUpWindow {
// Sets the start time
START_TIME = TODAYS_DATE;
START_TIME = CURRENT_DATE;
// Retrieves the user inputs
TREE_SPECIES = treeSpeciesList.getValue();
......@@ -249,30 +251,34 @@ public class InputPopUpWindow {
}
// 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();
try{
Thread thread = new Thread(() -> {
try {
while(!IS_FINISHED){
STOP_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
Map<String, Number> data = getCurrentDrying();
Platform.runLater(() -> {
try {
loadLiveData(data);
} catch (Exception ex) {
ex.printStackTrace();
}
});
Thread.sleep(1000L *NUMBER_OF_SECONDS_LIVE_DATA);
}
});
} catch (Exception ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
);
thread.setDaemon(true);
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
......
......@@ -257,12 +257,23 @@ public class LineChartFunctionality {
//simpleRegression.add
return getLineChart();
}
public static void loadLiveData(Map<String, Number> userInput) throws Exception {
clearLineChart();
int index = 0;
XYChart.Series<String, Number> newSeries = new XYChart.Series<String, Number>();
return getLineChart();
}
for (Map.Entry<String, Number> entryKwh : userInput.entrySet()) {
Double kwhValue = entryKwh.getValue().doubleValue();
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(index), kwhValue));
index++;
}
updateLineChart(newSeries);
}
public static double getNonLinearRegression(Map<Integer, ArrayList<Double>> confidenceIntervalData, double y0, double alpha, double j, int n) {
......
......@@ -42,7 +42,7 @@ public class OutputPopUpWindow {
finishButton.setAlignment(Pos.BOTTOM_CENTER);
finishButton.setOnAction(e -> {
try {
STOP_TIME = TODAYS_DATE;
STOP_TIME = CURRENT_DATE;
DB.pushManMoisture(moistureCheckTextField.getCharacters().toString());
} catch (Exception ex) {
ex.printStackTrace();
......
No preview for this file type
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