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

Connected progressbar to live data

parent f523b625
No related branches found
No related tags found
No related merge requests found
Showing
with 53 additions and 20 deletions
...@@ -16,7 +16,7 @@ public final class Constants { ...@@ -16,7 +16,7 @@ public final class Constants {
} }
// Today's date // Today's date
public static final String CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()); public static String CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
public static String TIME_LEFT = ""; public static String TIME_LEFT = "";
......
...@@ -21,6 +21,7 @@ public class HelpingFunctions { ...@@ -21,6 +21,7 @@ public class HelpingFunctions {
public static String STOP_TIME = ""; public static String STOP_TIME = "";
// Boolean variable to tell if the drying process is finished // Boolean variable to tell if the drying process is finished
public static boolean IS_FINISHED = false; public static boolean IS_FINISHED = false;
public static boolean LOADED_DATA = false;
// User inputs // User inputs
public static String TREE_SPECIES = ""; public static String TREE_SPECIES = "";
public static String DIMENSIONS = ""; public static String DIMENSIONS = "";
...@@ -179,4 +180,12 @@ public class HelpingFunctions { ...@@ -179,4 +180,12 @@ public class HelpingFunctions {
} }
return noOfChambers; return noOfChambers;
} }
public static boolean isLoadedData() {
return LOADED_DATA;
}
public static void setLoadedData(boolean loadedData) {
LOADED_DATA = loadedData;
}
} }
package com.application.GUI; package com.application.GUI;
import com.application.DB.Constants;
import com.application.DB.HelpingFunctions; import com.application.DB.HelpingFunctions;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
...@@ -16,6 +17,8 @@ import java.util.Map; ...@@ -16,6 +17,8 @@ import java.util.Map;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
import static com.application.DB.DB.getCurrentDrying; import static com.application.DB.DB.getCurrentDrying;
import static com.application.DB.HelpingFunctions.LOADED_DATA;
import static com.application.DB.HelpingFunctions.setLoadedData;
import static com.application.GUI.LineChartFunctionality.loadLiveData; import static com.application.GUI.LineChartFunctionality.loadLiveData;
import static com.application.Main.*; import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters; import static com.application.DB.DB.setInputParameters;
...@@ -122,7 +125,7 @@ public class InputPopUpWindow { ...@@ -122,7 +125,7 @@ public class InputPopUpWindow {
startButton.setOnAction(e -> { startButton.setOnAction(e -> {
// Sets the start time // Sets the start time
Constants.CURRENT_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
HelpingFunctions.START_TIME = CURRENT_DATE; HelpingFunctions.START_TIME = CURRENT_DATE;
// Retrieves the user inputs // Retrieves the user inputs
...@@ -189,6 +192,7 @@ public class InputPopUpWindow { ...@@ -189,6 +192,7 @@ public class InputPopUpWindow {
Platform.runLater(() -> { Platform.runLater(() -> {
try { try {
loadSingleSeries(data); loadSingleSeries(data);
setLoadedData(true);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
...@@ -27,6 +27,7 @@ public class LineChartFunctionality { ...@@ -27,6 +27,7 @@ public class LineChartFunctionality {
private static NumberAxis yAxis; private static NumberAxis yAxis;
private static final double CONFIDENCE_INTERVAL = 0.90; private static final double CONFIDENCE_INTERVAL = 0.90;
private static int dataPoints = 0; private static int dataPoints = 0;
private static Map<String, Number> liveData;
public LineChartFunctionality() { public LineChartFunctionality() {
...@@ -268,6 +269,7 @@ public class LineChartFunctionality { ...@@ -268,6 +269,7 @@ public class LineChartFunctionality {
public static void loadLiveData(Map<String, Number> userInput) throws Exception { public static void loadLiveData(Map<String, Number> userInput) throws Exception {
setLiveData(userInput);
getTimeLeft(userInput.size()); getTimeLeft(userInput.size());
int index = 0; int index = 0;
...@@ -284,10 +286,10 @@ public class LineChartFunctionality { ...@@ -284,10 +286,10 @@ public class LineChartFunctionality {
int time = 0; int time = 0;
if(liveData == 0) { if(liveData == 0) {
time = dataPoints*10; time = getDataPoints()*10;
} else { } else {
time = (dataPoints/liveData)*10; time = (getDataPoints()/liveData)*10;
} }
if(time > 60){ if(time > 60){
time = time/60; time = time/60;
...@@ -330,4 +332,16 @@ public class LineChartFunctionality { ...@@ -330,4 +332,16 @@ public class LineChartFunctionality {
return p_t; return p_t;
} }
public static int getDataPoints() {
return dataPoints;
}
public static Map<String, Number> getLiveData() {
return liveData;
}
public static void setLiveData(Map<String, Number> input) {
liveData = input;
}
} }
...@@ -22,6 +22,9 @@ import java.io.IOException; ...@@ -22,6 +22,9 @@ import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
import static com.application.DB.HelpingFunctions.*;
import static com.application.GUI.LineChartFunctionality.getDataPoints;
import static com.application.GUI.LineChartFunctionality.getLiveData;
import static java.util.logging.Level.SEVERE; import static java.util.logging.Level.SEVERE;
/** /**
...@@ -226,28 +229,31 @@ public class Main extends Application { ...@@ -226,28 +229,31 @@ public class Main extends Application {
} }
@Override @Override
public void run(){ public void run() {
while (!IS_FINISHED) {
try {
//Thread.sleep(10000);
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
while (true){
try { try {
Thread.sleep(100); Thread.sleep(1000L * NUMBER_OF_SECONDS_LIVE_DATA);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Logger.getLogger(getClass().getName()).log(SEVERE,null,e);
} }
Platform.runLater(() -> {rpi.setProgress(progress);});
progress += 1; while (isLoadedData()) {
if(progress>100){ try {
break; Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
Logger.getLogger(getClass().getName()).log(SEVERE, null, e);
}
Platform.runLater(() -> {
rpi.setProgress(progress);
});
progress = getLiveData().size()/getDataPoints();
if (progress > 100) {
break;
}
} }
} }
} }
......
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
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