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

Merge branch 'Eilerts_branch' into 'master'

Eilerts branch

See merge request mesji/bacheloroppgave_2022!42
parents 067d1857 12a76b6b
Branches
No related tags found
No related merge requests found
......@@ -53,5 +53,6 @@
<orderEntry type="library" name="Maven: com.google.apis:google-api-services-storage:v1-rev20211201-1.32.1" level="project" />
<orderEntry type="library" name="Maven: com.google.auto.value:auto-value-annotations:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.10.14" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -35,7 +35,11 @@
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.14</version>
</dependency>
</dependencies>
<properties>
......
......@@ -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;
}
......
......@@ -3,6 +3,7 @@ package com.application.DB;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.*;
import org.joda.time.DateTime;
import java.io.File;
import java.io.FileInputStream;
......@@ -319,6 +320,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
*
......@@ -423,6 +469,19 @@ public class DB {
String stopDryingTime, String valmeticsTableName, int limit)
throws Exception {
// Defining variables to be used later
String treeSort = "";
String thickness = "";
String width = "";
String sawSet = "";
String moistureGoal = "";
String moistureMeasured = "";
String formatedInTidTork = "";
String formatedUtTidTork = "";
String formatedUtTidTorkPlussDays = "";
// Initializing the dates map to store the results
Map<String, String> dates = new HashMap<>();
......@@ -463,11 +522,28 @@ public class DB {
// Iterating through the results
for (FieldValueList row : result.iterateAll()) {
// Defining variables
String formatedInTidTork = "";
String formatedUtTidTork;
// Gets parameters from DryingSchedule
System.out.println(row.get("DryingSchedule").getStringValue());
if(!row.get("DryingSchedule").isNull()){
String[] nameParameters = row.get("DryingSchedule").getValue().toString().split(" ");
for (int i = 0; i < nameParameters.length; i++) {
if (nameParameters[i].contains("Fur")) {
treeSort = "F";
}
if (nameParameters[i].contains("Gran")) {
treeSort = "G";
}
if (nameParameters[i].matches("\\d{2}x\\d{3}")) {
String[] dimensions = nameParameters[i].split("x");
width = dimensions[0];
thickness = dimensions[1];
}
if (nameParameters[i].matches("\\d{1}ex")) {
sawSet = nameParameters[i];
}
}
}
//System.out.println("Start: "+row.get("DryingStarted").getTimestampValue());
......@@ -541,16 +617,61 @@ public class DB {
//System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork);
}
// Adding days to search between
DateTime addedDays = new DateTime(formatedUtTidTork.split(" ")[0]);
formatedUtTidTorkPlussDays = addedDays.plusDays(2).toString();
formatedUtTidTorkPlussDays = formatedUtTidTorkPlussDays.split("T")[0];
// Getting manual measurement
// Sqlstatement
final String manMeasurement = "SELECT Tork, Dato ,Treslag, Tykkelse, Bredde, Planketype, Malfukt, GjeFukt " +
"FROM `sf-drying-optimization.174.int_ds_manfuktreg` " +
"WHERE Tork LIKE " + kilinID + " " +
"AND Treslag = " + treeSort + " " +
"AND Tykkelse = " + thickness + " " +
"AND Bredde = " + width + " " +
"AND Planketype = " + sawSet + " " +
"AND Dato BETWEEN \""+ formatedUtTidTork.split(" ")[0] +"\" AND \"" + formatedUtTidTorkPlussDays + "\" " +
"ORDER BY Dato";
System.out.println(manMeasurement);
// Retrieves the results from the queryjob
TableResult resultManMeasurement = createQueryJob(manMeasurement);
//System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results
for (FieldValueList row : resultManMeasurement.iterateAll()) {
System.out.println(row);
moistureGoal = row.get("Malfukt").getValue().toString();
moistureMeasured = row.get("GjeFukt").getValue().toString();
}
System.out.println("moistureGoal: " + moistureGoal);
System.out.println("moistureMeasured: " + moistureMeasured);
// 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());
......
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,32 @@ 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.interrupt();
thread.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
);
/*
// Fungerende ny thread!!@@@@@
try{
......@@ -239,8 +271,11 @@ public class InputPopUpWindow {
}
);
*/
*/
/*
class KwhThread implements Runnable {
......
......@@ -17,7 +17,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;
......@@ -91,6 +90,7 @@ public class LineChartFunctionality {
public static LineChart<String, Number> loadSingleSeries(Map<Integer, Map<String, Number>> userInput) throws Exception {
clearLineChart();
Map<Integer, ArrayList<Double>> multiMap = new HashMap<>();
for (Map.Entry<Integer, Map<String, Number>> entryKwh : userInput.entrySet()) {
......@@ -113,12 +113,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 +135,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,36 +165,40 @@ 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();
simpleRegression.addData(data);
simpleRegression.regress();
//simpleRegression.regress();
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
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