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

Implemented linear regression and fixed splitting process into two threads

parent f564b448
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ public final class Constants {
public static final String VALASEN_START_DRYING_NAME = "DryingStarted";
public static final String VALASEN_STOP_DRYING_NAME = "CalculatedStop";
public static final String VALASEN_KILIN_NAME = "KilnName";
public static int VALASEN_KILIN_ID = 5; // Kammer 5
//public static int VALASEN_KILIN_ID = 5; // Kammer 5
//public static int VALASEN_KILIN_ID = 6; // Kammer 6
public static final int VALASEN_LIMIT = 1000;
public static final ArrayList<Integer> VALASEN_VALMETICS_CHAMBER_IDS = new ArrayList<>(Arrays.asList(5,6));
......@@ -52,7 +52,7 @@ public final class Constants {
public static final String VALASEN_KWH_NAME = "VariantValue";
public static final String VALASEN_TIMESTAMP_NAME = "Timestamp";
public static final String VALASEN_VALUE_ID_NAME = "ValueID";
public static final int VALASEN_VALUE_ID = 51; // Kammer 5
//public static final int VALASEN_VALUE_ID = 51; // Kammer 5
//public static final int VALASEN_VALUE_ID = 56; // Kammer 6
public static final ArrayList<Integer> VALASEN_KWH_CHAMBER_IDS = new ArrayList<>(Arrays.asList(51,56));
......@@ -131,7 +131,7 @@ public final class Constants {
valasenWinccsensordataParameters.put("KwhName", VALASEN_KWH_NAME);
valasenWinccsensordataParameters.put("Timestamp", VALASEN_TIMESTAMP_NAME);
valasenWinccsensordataParameters.put("ValueIDName", VALASEN_VALUE_ID_NAME);
valasenWinccsensordataParameters.put("ValueID", String.valueOf(VALASEN_VALUE_ID));
//valasenWinccsensordataParameters.put("ValueID", String.valueOf(VALASEN_VALUE_ID));
//valasenWinccsensordataParameters.put("ValueID", String.valueOf(VALASEN_VALUE_ID));
return valasenWinccsensordataParameters;
}
......
......@@ -319,6 +319,51 @@ public class DB {
}
/**
*
*
* @throws Exception
*/
/*
public static void getManualMeasurements() throws Exception {
// Sqlstatement
final String sqlStatement = "";
System.out.println(sqlStatement);
// Retrieves the results from the queryjob
TableResult result = createQueryJob(sqlStatement);
//System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results
for (FieldValueList row : result.iterateAll()) {
row.get("DryingStarted").getTimestampValue();
}
// Defining a treemap to sort the data incrementally
//NavigableMap<String, String> sortedFinalResults = new TreeMap<>(dates);
System.out.println("\n");
for (Map.Entry<String, String> entry : sortedFinalResults.entrySet()) {
System.out.printf("Intid: \t%s\t\t\tUttid: \t%s\n",entry.getKey(),entry.getValue());
}
//System.out.printf("Size of dates: %s\n\n", sortedFinalResults.size());
// Returns a treemap that sorts the dates incrementally
//return new TreeMap<>(sortedFinalResults);
}
*/
/**
* Retrieves information about kWh and the corresponding date
*
......
package com.application.GUI;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
......@@ -9,6 +10,7 @@ import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import java.util.Map;
import java.util.concurrent.*;
import static com.application.DB.Constants.*;
......@@ -171,7 +173,7 @@ public class InputPopUpWindow {
*/
/*
try {
//getData();
......@@ -186,6 +188,10 @@ public class InputPopUpWindow {
);
*/
......@@ -215,6 +221,31 @@ public class InputPopUpWindow {
*/
// Fungerende ny thread!!@@@@@
try{
Thread thread = new Thread(() -> {
try {
// Henter her data fra databasen
Map<Integer, Map<String, Number>> data = setInputParameters();
Platform.runLater(() -> {
try {
loadSingleSeries(data);
} catch (Exception ex) {
ex.printStackTrace();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
});
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
/*
// Fungerende ny thread!!@@@@@
try{
......@@ -239,8 +270,11 @@ public class InputPopUpWindow {
}
);
*/
*/
/*
class KwhThread implements Runnable {
......
package com.application.GUI;
import javafx.collections.ObservableList;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
......@@ -9,6 +10,7 @@ import org.apache.commons.math3.distribution.TDistribution;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.apache.commons.math3.*;
import java.util.*;
......@@ -17,7 +19,6 @@ public class LineChartFunctionality {
private static LineChart<String, Number> lineChart;
private static CategoryAxis xAxis;
private static NumberAxis yAxis;
private static final double CONFIDENCE_INTERVAL = 0.90;
......@@ -89,7 +90,9 @@ public class LineChartFunctionality {
public static LineChart<String, Number> loadSingleSeries(Map<Integer, Map<String, Number>> userInput) throws Exception {
clearLineChart();
//clearLineChart();
//newSeries.setData(null);
Map<Integer, ArrayList<Double>> multiMap = new HashMap<>();
......@@ -113,12 +116,15 @@ public class LineChartFunctionality {
// Connect the data to a series
newSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(index), kwhValue));
index += 1;
index++;
}
//allSeries.add(newSeries);
updateLineChart(newSeries);
lineChart.setOpacity(0.5);
//lineChart.setOpacity(1);
}
//System.out.println("Series size: "+allSeries.size());
// Stores the data from the confidence interval in a new map
Map<Integer, ArrayList<Double>> confidenceIntervalData = statistics(multiMap);
......@@ -132,18 +138,21 @@ public class LineChartFunctionality {
// Defines an array to be used for the regression
double[][] data = new double[confidenceIntervalData.size()][jMaxSize];
double[][] data = new double[confidenceIntervalData.size()*jMaxSize][2];
int index = 0;
System.out.println(confidenceIntervalData);
for (int i = 0; i < confidenceIntervalData.size(); i++) {
ArrayList<Double> list = confidenceIntervalData.get(i);
System.out.println(list.size());
for (int j = 0; j < list.size(); j++) {
data[i][j] = list.get(j);
data[index][0] = i;
data[index][1] = list.get(j);
index++;
}
/*
for (int j = 0; j < data[i].length; j++) {
System.out.println("data[i][j]: "+data[i][j]);
if(data[i][j] == 0.0){
......@@ -159,11 +168,13 @@ public class LineChartFunctionality {
data[i][j] = sum/index;
}
}
*/
}
System.out.println(data.length);
System.out.println(data[12][1]);
//System.out.println(data[12][1]);
SimpleRegression simpleRegression = new SimpleRegression();
......@@ -172,23 +183,25 @@ public class LineChartFunctionality {
for (double[] datum : data) {
System.out.println("");
for (double v : datum) {
System.out.println(v);
System.out.println("Data: "+v);
}
}
XYChart.Series<String, Number> regressionSeries = new XYChart.Series<String, Number>();
for (int i = 0; i < simpleRegression.getN(); i++) {
for (int i = 0; i < confidenceIntervalData.size(); i++) {
// Connect the data to a series
System.out.println(simpleRegression.predict(i));
regressionSeries.getData().add(new XYChart.Data<String, Number>(String.valueOf(i), simpleRegression.predict(i)));
}
updateLineChart(regressionSeries);
lineChart.setOpacity(1);
//lineChart.setOpacity(1);
System.out.println("Get R: " + simpleRegression.getR());
System.out.println("Get getRSquare: " + simpleRegression.getRSquare());
......
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