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

Connected the data to the graph plot

parent d8333184
No related branches found
No related tags found
No related merge requests found
...@@ -159,26 +159,27 @@ public class DB { ...@@ -159,26 +159,27 @@ public class DB {
String formatedTimeStamp = getDateFormat().format(timeStamp); String formatedTimeStamp = getDateFormat().format(timeStamp);
// Checks for negative values, // Checks for negative values,
if(variantValue > 0){ if(variantValue > 0 && variantValue < 5000000){
// Adding the data to a list in order to sort through later // Adding the data to a list in order to sort through later
data.put(formatedTimeStamp, variantValue); data.put(formatedTimeStamp, variantValue);
} }
//System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\t\t\tBaseline: %s\n",formatedTimeStamp,variantValue,baseline); //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 // Checks if the data is empty
} }
if(!data.isEmpty()) { NavigableMap<String, Number> sortedData = new TreeMap<>(data);
finalResults.put(index,data); if(!sortedData.isEmpty()) {
finalResults.put(index,sortedData);
index += 1; index += 1;
} }
} }
// Defining a treemap to sort through the data // Defining a treemap to sort through the data
NavigableMap<Integer, Map> sortedFinalResults = new TreeMap<>(finalResults); NavigableMap<Integer, Map> sortedFinalResults = new TreeMap<>(finalResults);
/*
for (Map.Entry<Integer, Map> entry : sortedFinalResults.entrySet()) { for (Map.Entry<Integer, Map> entry : sortedFinalResults.entrySet()) {
System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue()); System.out.printf("Timestamp: \t%s\t\t\tkWh: \t%s\n",entry.getKey(),entry.getValue());
} }
*/
return sortedFinalResults; return sortedFinalResults;
} }
...@@ -259,7 +260,7 @@ public class DB { ...@@ -259,7 +260,7 @@ public class DB {
// Retrieves the results from the queryjob // Retrieves the results from the queryjob
TableResult result = queryJob.getQueryResults(); TableResult result = queryJob.getQueryResults();
System.out.println("InTidTork\t\t\tUtTidTork"); //System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results // Iterating through the results
for (FieldValueList row : result.iterateAll()) { for (FieldValueList row : result.iterateAll()) {
......
...@@ -269,16 +269,35 @@ public class Main extends Application { ...@@ -269,16 +269,35 @@ public class Main extends Application {
final LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis); final LineChart<String, Number> lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setTitle("Drying Process"); lineChart.setTitle("Drying Processes");
Map<String, Number> kwh = null;// = DB.getKwh(); Map<Integer, Map> kWh = DB.getKwh();
Map<String, Number> sortedKwh = new TreeMap<>(kwh);
XYChart.Series series1 = new XYChart.Series();
series1.setName("Drying 1");
sortedKwh.forEach((key, value) -> series1.getData().add(new XYChart.Data(key,value)));
lineChart.getData().add(series1); for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
Map data = entryKwh.getValue();
XYChart.Series series = new XYChart.Series();
for (Object entryData : data.entrySet()){
//System.out.println("data: \t\t"+entryData);
String entryString = entryData.toString();
String[] arr = entryString.split("=");
String date = arr[0];
int kwhValue = Integer.parseInt(arr[1]);
System.out.printf("Date: \t%s\t\t\tkWh: \t%s\n",date,kwhValue);
// Connect the data to a series
series.getData().add(new XYChart.Data(date,kwhValue));
}
lineChart.getData().add(series);
System.out.println("\n\nNew line\n\n");
}
/*
for (Map.Entry<Integer, Map> entryKwh : kWh.entrySet()) {
System.out.printf("Index: \t%s\t\t\tkWh: \t%s\n",entryKwh.getKey(),entryKwh.getValue());
}
*/
return lineChart; return lineChart;
} }
} }
......
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