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

Merge branch 'Eilerts_branch' into 'master'

Fixed clear regression series outside of for-loop.

See merge request mesji/bacheloroppgave_2022!52
parents d52b7948 84a3fbdc
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 43 deletions
package com.application.DB;
import com.application.GUI.Panes.LogoBar;
import com.application.GUI.Panes.CreateLogoBar;
import com.application.GUI.PopUpWindows.NotificationPopUp;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.TableResult;
......@@ -8,7 +8,6 @@ import com.google.cloud.bigquery.TableResult;
import static com.application.DB.Constants.*;
import static com.application.DB.Settings.*;
import static com.application.GUI.PopUpWindows.LoginPopup.getPasswordTextField;
import static java.lang.System.err;
public class Account_handler {
......@@ -20,7 +19,7 @@ public class Account_handler {
for (FieldValueList row : result.iterateAll()) {
if (row.get("Username").getValue().equals(username)) {
LogoBar.getLogin().setText(username);
CreateLogoBar.getLogin().setText(username);
setUserName(username);
if (!row.get("Phone_no").isNull()) {
......
......@@ -274,8 +274,7 @@ public class DB {
TableResult result = HelpingFunctions.createQueryJob(sqlStatement);
//System.out.println("Timestamp \t kWh");
int baseline = 0;
HelpingFunctions.iterateKwhValues(data, baseline, result, KwhName, timestamp);
HelpingFunctions.iterateKwhValues(data, result, KwhName, timestamp);
System.out.println("Data size: " + data.size());
......@@ -625,7 +624,6 @@ public class DB {
// Initializing the data map to store the results
Map<String, Number> data = new HashMap<>();
// Initializing baseline
int baseline = 0;
// Sqlstatement
final String sqlStatement = "SELECT `" + KWH_TIMESTAMP_NAME_PARAMETER + "`, `" + KWH_NAME_PARAMETER + "` " +
......@@ -643,7 +641,7 @@ public class DB {
//System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results
HelpingFunctions.iterateKwhValues(data, baseline, result, KWH_NAME_PARAMETER, KWH_TIMESTAMP_NAME_PARAMETER);
HelpingFunctions.iterateKwhValues(data, result, KWH_NAME_PARAMETER, KWH_TIMESTAMP_NAME_PARAMETER);
return new TreeMap<>(data);
}
......
......@@ -31,7 +31,7 @@ public class HelpingFunctions {
}
/**
* Retrieves the credentials file
* Retrieves the credentials file and grants access to the database
*
* @return the credentials
* @throws Exception for potential errors
......@@ -39,9 +39,6 @@ public class HelpingFunctions {
private static GoogleCredentials getCredentials() throws Exception {
File credentialsPath = new File("./src/main/resources/com.application/"+KEY_FILE_NAME);
// Load credentials from JSON key file. If you can't set the GOOGLE_APPLICATION_CREDENTIALS
// environment variable, you can explicitly load the credentials file to construct the
// credentials.
GoogleCredentials credentials;
try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
......@@ -50,16 +47,13 @@ public class HelpingFunctions {
}
/**
* Creates a bigquery builder
* Creates a bigquery builder. Here we set the project ID and get the `BigQuery` service object.
* this is the interface to our BigQuery instance that we use to execute jobs on.
*
* @return a builder
* @throws Exception returns potential error
*/
private static BigQuery getBuilder() throws Exception {
// Step 1: Initialize BigQuery service
// Here we set our project ID and get the `BigQuery` service object
// this is the interface to our BigQuery instance that
// we use to execute jobs on
return BigQueryOptions.newBuilder().
setCredentials(getCredentials()).
setProjectId(PROJECT_ID)
......@@ -77,9 +71,9 @@ public class HelpingFunctions {
// Step 3: Run the job on BigQuery
// create a `Job` instance from the job configuration using the BigQuery service
// the job starts executing once the `create` method executes
Job queryJob = getBuilder().create(JobInfo.newBuilder(queryConfig).build());
queryJob = queryJob.waitFor();
// the waitFor method blocks until the job completes
// and returns `null` if the job doesn't exist anymore
if (queryJob == null) {
......@@ -107,7 +101,6 @@ public class HelpingFunctions {
// Retrieves the results from the queryjob
return queryJob.getQueryResults();
}
/**
......@@ -120,15 +113,17 @@ public class HelpingFunctions {
}
/**
* Function to iterate through all the Kwh values and storing them in a map
* Iterates through all the Kwh values and storing them in a map
*
* @param data a map to store all the data
* @param baseline a baseline to base all the next values of to get a zero point
* @param result TableResult to iterate through
* @param kwhNameParameter Name of the Kwh name parameter in the database
* @param kwhTimestampNameParameter Name of the timestamp parameter in the database
*/
static void iterateKwhValues(Map<String, Number> data, int baseline, TableResult result, String kwhNameParameter, String kwhTimestampNameParameter) {
static void iterateKwhValues(Map<String, Number> data, TableResult result, String kwhNameParameter, String kwhTimestampNameParameter) {
// A baseline to base all the next values of to get a zero point
int baseline = 0;
for (FieldValueList row : result.iterateAll()) {
// Sets the baseline in order to reset the kWh counter
if (baseline == 0) {
......@@ -136,7 +131,7 @@ public class HelpingFunctions {
}
// kWh value
int variantValue = row.get("" + kwhNameParameter + "").getNumericValue().intValue() - baseline; //-baseline
int variantValue = row.get("" + kwhNameParameter + "").getNumericValue().intValue() - baseline;
// Retrieving the wanted data
long timeStamp = row.get("" + kwhTimestampNameParameter + "").getTimestampValue() / 1000;
......
......@@ -347,6 +347,7 @@ public class LineChartFunctionality {
//XYChart.Series<String, Number> regressionSeries = new XYChart.Series<String, Number>();
getRegressionSeries().getData().clear();
for (int i = 0; i <= getDataPointsXAxis(); i++) {
// Connect the data to a series
......@@ -377,7 +378,7 @@ public class LineChartFunctionality {
*/
getRegressionSeries().getData().clear();
getRegressionSeries().getData().add(new XYChart.Data<String, Number>(
String.valueOf(i),
getNonLinearRegression(
......
......@@ -8,10 +8,10 @@ import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
public class BottomBar {
public class CreateBottomBar {
private final Main main;
public BottomBar(Main main) {
public CreateBottomBar(Main main) {
this.main = main;
}
......
package com.application.GUI.Panes;
import com.application.GUI.PopUpWindows.LoginPopup;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
......@@ -14,7 +13,7 @@ import java.io.FileNotFoundException;
import static com.application.DB.Constants.isIsAdmin;
public class LogoBar {
public class CreateLogoBar {
private static Button login = new Button("Login");
......
......@@ -8,10 +8,10 @@ import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
public class MenuBar {
public class CreateMenuBar {
private final Main main;
public MenuBar(Main main) {
public CreateMenuBar(Main main) {
this.main = main;
}
......
......@@ -20,9 +20,9 @@ import static com.application.GUI.LineChartFunctionality.getDataPointsXAxis;
import static com.application.GUI.LineChartFunctionality.getLiveData;
import static java.util.logging.Level.SEVERE;
public class SideBar {
public class CreateSideBar {
public SideBar(Main main) {
public CreateSideBar(Main main) {
}
public VBox createSideBar() {
......
......@@ -12,7 +12,7 @@ import java.security.MessageDigest;
import static com.application.DB.Account_handler.*;
import static com.application.DB.Constants.*;
import static com.application.GUI.Panes.LogoBar.getLogin;
import static com.application.GUI.Panes.CreateLogoBar.getLogin;
public class LoginPopup {
......
package com.application;
import com.application.GUI.Panes.CreateMenuBar;
import com.application.GUI.PopUpWindows.InputPopup;
import com.application.GUI.Panes.BottomBar;
import com.application.GUI.Panes.LogoBar;
import com.application.GUI.Panes.SideBar;
import com.application.GUI.Panes.CreateBottomBar;
import com.application.GUI.Panes.CreateLogoBar;
import com.application.GUI.Panes.CreateSideBar;
import com.application.GUI.LineChartFunctionality;
import com.application.GUI.PopUpWindows.LoginPopup;
......@@ -25,10 +26,10 @@ import java.io.IOException;
*/
public class Main extends Application {
private final BottomBar bottomBar1 = new BottomBar(this);
private final com.application.GUI.Panes.MenuBar menuBar1 = new com.application.GUI.Panes.MenuBar(this);
private final SideBar sideBar1 = new SideBar(this);
private final LogoBar logoBar1 = new LogoBar();
private final CreateBottomBar createBottomBar1 = new CreateBottomBar(this);
private final CreateMenuBar createMenuBar1 = new CreateMenuBar(this);
private final CreateSideBar createSideBar1 = new CreateSideBar(this);
private final CreateLogoBar createLogoBar1 = new CreateLogoBar();
private BorderPane topBar;
private HBox logoBar;
......@@ -96,9 +97,9 @@ public class Main extends Application {
// Create panes for root
BorderPane root = new BorderPane();
this.menuBar = menuBar1.createMenuBar();
this.sideBar = sideBar1.createSideBar();
this.logoBar = logoBar1.createLogoBar();
this.menuBar = createMenuBar1.createMenuBar();
this.sideBar = createSideBar1.createSideBar();
this.logoBar = createLogoBar1.createLogoBar();
LineChart<String, Number> lineChart = LineChartFunctionality.getLineChart();
......@@ -107,7 +108,7 @@ public class Main extends Application {
this.logoBar.setId("logoBar");
this.menuBar.setId("menuBar");
this.sideBar.setId("sideBar");
this.bottomBar = bottomBar1.createBottomBar();
this.bottomBar = createBottomBar1.createBottomBar();
this.bottomBar.setId("bottomBar");
lineChart.setId("lineChart");
......
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