Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mesji/bacheloroppgave_2022
1 result
Show changes
Commits on Source (8)
Showing
with 87 additions and 61 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;
......@@ -19,7 +19,7 @@ public class AccountHandler {
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());
......@@ -379,7 +378,7 @@ public class DB {
extraInputParameter +
"AND LOWER(" +nameParameter+ ") NOT LIKE LOWER("+'"'+"%"+ "test" +"%"+'"'+") " +
"Group by "+ startDryingTime + " " +
"Order by "+ startDryingTime + " ASC " +
"Order by "+ startDryingTime + " DESC " +
"LIMIT " + limit;
System.out.println(sqlStatement);
......@@ -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);
}
......
......@@ -35,7 +35,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
......@@ -43,9 +43,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);
......@@ -54,16 +51,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)
......@@ -81,9 +75,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) {
......@@ -111,7 +105,6 @@ public class HelpingFunctions {
// Retrieves the results from the queryjob
return queryJob.getQueryResults();
}
/**
......@@ -124,15 +117,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) {
......@@ -140,7 +135,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;
......
......@@ -318,6 +318,7 @@ public class LineChartFunctionality {
}
}
getRegressionSeriesConfidenceInterval().getData().clear();
Map<Integer, ArrayList<Double>> confidenceIntervalShadow = statistics(multiMap,true);
for ( Map.Entry<Integer, ArrayList<Double>> entry : confidenceIntervalShadow.entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
......@@ -347,6 +348,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 +379,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() {
......
......@@ -20,6 +20,7 @@ import static com.application.DB.DB.getCurrentDrying;
import static com.application.DB.Constants.MAX_USER_INPUT_CHARACTERS;
import static com.application.DB.HelpingFunctions.setLoadedData;
import static com.application.GUI.LineChartFunctionality.*;
import static com.application.GUI.Panes.CreateLogoBar.getLogin;
import static com.application.Main.*;
import static com.application.DB.DB.setInputParameters;
......@@ -32,7 +33,6 @@ import static com.application.DB.DB.setInputParameters;
*/
public class InputPopup {
public static void display() {
Stage window = new Stage();
......@@ -132,6 +132,10 @@ public class InputPopup {
boolean err = false;
if(getLogin().getText().equals("Login")){
err = true;
}
// If the input is null, sets the value to be empty
if (treeSpeciesList.getValue() == null) {
Constants.TREE_SPECIES = "";
......@@ -244,7 +248,9 @@ public class InputPopup {
ex.printStackTrace();
}
}
} else {
NotificationPopUp.displayNotificationWindow("Please login!");
}
}
);
......
package com.application.GUI.PopUpWindows;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
......@@ -12,11 +15,32 @@ import java.security.MessageDigest;
import static com.application.DB.AccountHandler.*;
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 {
public static PasswordField PASSWORD_TEXT_FIELD = new PasswordField();
private static PasswordField PASSWORD_TEXT_FIELD = new PasswordField();
private static TextField USERNAME_TEXT_FIELD = new TextField();
/**
* Tries to login
*
* @return a boolean if an error should be thrown or not. True gives no error, false throws an error.
*/
private static boolean loginButtonPressed(){
try {
getAccountInformation(getUsernameTextField().getText(), hashPassword(getPasswordTextField().getText()));
if(getLogin().getText().equals("Admin")) {
LoginPopup.adminPopup();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return !getLogin().getText().equals("Login");
}
public static void login(){
......@@ -27,36 +51,33 @@ public class LoginPopup {
Label userNameLabel = new Label("Username:");
Label passwordLabel = new Label("Password:");
TextField userNameTextField = new TextField();
getPasswordTextField().clear();
Button closeButton = new Button("Close");
Button loginButton = new Button("Login");
getPasswordTextField().clear();
closeButton.setOnAction(event -> window.close());
loginButton.setOnAction(event -> {
try {
getAccountInformation(userNameTextField.getText(), hashPassword(getPasswordTextField().getText()));
if(getLogin().getText().equals("Admin")) {
LoginPopup.adminPopup();
window.close();
}
} catch (Exception e) {
e.printStackTrace();
getPasswordTextField().setOnKeyPressed( event -> {
if( event.getCode() == KeyCode.ENTER ) {
if(loginButtonPressed()){
window.close();
}
}
});
if(!getLogin().getText().equals("Login")){
loginButton.setOnAction(event -> {
if(loginButtonPressed()){
window.close();
}
});
VBox layout = new VBox(10);
layout.setAlignment(Pos.CENTER);
layout.getChildren().addAll(userNameLabel, userNameTextField, passwordLabel, getPasswordTextField(), loginButton, closeButton);
layout.getChildren().addAll(userNameLabel, getUsernameTextField(), passwordLabel, getPasswordTextField(), loginButton, closeButton);
Scene scene = new Scene(layout, 500, 300);
scene.getStylesheets().add(InputPopup.class.getResource("/com.application/CSS/styleSheet.css").toExternalForm());
......@@ -281,4 +302,8 @@ public class LoginPopup {
public static PasswordField getPasswordTextField() {
return PASSWORD_TEXT_FIELD;
}
public static TextField getUsernameTextField() {
return USERNAME_TEXT_FIELD;
}
}
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
No preview for this file type
No preview for this file type
No preview for this file type
File deleted
File deleted
File deleted
File deleted
File deleted