Merge branch 'master' into 'add/activity_tooltips'

# Conflicts:
#   src/Client/src/main/java/greenify/client/controller/DashBoardController.java
#   src/Client/src/main/java/greenify/client/controller/ExtraActivityController.java
This commit is contained in:
Sem van der Hoeven
2019-04-08 12:13:44 +00:00
15 changed files with 105 additions and 65 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 KiB

View File

@@ -1,5 +0,0 @@
# Checkstyle folder
At the end of the week, please commit a readable screenshot that shows the Checkstyle results.
Make sure that the file follows the naming convention; `20190213_checkstyle.xyz` for February 13th.
`.xyz` can be either `.jpg` or `.png`.

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@@ -0,0 +1,14 @@
# Sprint Review
## Main problems Encountered
### Problem 1:
## Adjustments from previous sprints
There were no big problems this week. We made some last minute changes and added some extra features. Next week we're going to focus on our other exams, so we're
not really working on the project anymore.
## Adjustments for next sprint

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

View File

Binary file not shown.

View File

@@ -39,6 +39,9 @@ public class CalculatorController {
@Autowired @Autowired
DashBoardController controller; DashBoardController controller;
@Autowired
ExtraActivityController extraActivityController;
//navigation panes //navigation panes
@FXML @FXML
private AnchorPane getStartedPane; private AnchorPane getStartedPane;
@@ -395,10 +398,12 @@ public class CalculatorController {
"input_footprint_shopping_services_total", "input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", "")); servicesLabel.getText().replace("€ / month", ""));
} }
extraActivityController.updateExtras();
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow(); Window owner = saveButton.getScene().getWindow();
controller.updateLeaderboard(); controller.updateLeaderboard();
controller.updateAchievements(); controller.updateAchievements();
Stage current = (Stage) owner;
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!"); owner, "Footprint saved!", "Your footprint is saved!");
Stage current = (Stage) owner; Stage current = (Stage) owner;

View File

@@ -263,7 +263,6 @@ public class DashBoardController {
addFriendButton.setSkin(new ClickButtonSkin(addFriendButton)); addFriendButton.setSkin(new ClickButtonSkin(addFriendButton));
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton)); addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2)); addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
addRandomHints(); addRandomHints();
Tooltip tooltip = new Tooltip("tip"); Tooltip tooltip = new Tooltip("tip");
@@ -317,30 +316,31 @@ public class DashBoardController {
* Sorts the scores of users. * Sorts the scores of users.
* @param users the list of users * @param users the list of users
*/ */
public void sortScores(List<String> users) throws InterruptedException { public List<String> sortScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) { for (int j = 0; j < users.size(); j++) {
Double firstScore = userService.getFootprint(users.get(i)); Double first = userService.getFootprint(users.get(i));
Double secondScore = userService.getFootprint(users.get(j)); Double second = userService.getFootprint(users.get(j));
if (i > j && firstScore < secondScore) { if (i < j && first > second) {
String temp = users.get(i); String temp = users.get(i);
users.set(i, users.get(j)); users.set(i, users.get(j));
users.set(j, temp); users.set(j, temp);
} }
if (i < j && firstScore > secondScore) { if (i > j && first < second) {
String temp = users.get(i); String temp = users.get(i);
users.set(i, users.get(j)); users.set(i, users.get(j));
users.set(j, temp); users.set(j, temp);
} }
} }
} }
return users;
} }
/** /**
* Sorts the scores of users. * Sorts the scores of users.
* @param users the list of users * @param users the list of users
*/ */
public void sortDiffScores(List<String> users) throws InterruptedException { public List<String> sortDiffScores(List<String> users) throws InterruptedException {
for (int i = 0; i < users.size(); i++) { for (int i = 0; i < users.size(); i++) {
for (int j = 0; j < users.size(); j++) { for (int j = 0; j < users.size(); j++) {
Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService Double firstDiff = userService.getFirstFootprint(users.get(i)) - userService
@@ -359,6 +359,7 @@ public class DashBoardController {
} }
} }
} }
return users;
} }
/** /**
@@ -427,8 +428,8 @@ public class DashBoardController {
dairy.setText(inputMap.get("input_footprint_shopping_food_dairy")); dairy.setText(inputMap.get("input_footprint_shopping_food_dairy"));
fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables")); fruits.setText(inputMap.get("input_footprint_shopping_food_fruitvegetables"));
snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood")); snacks.setText(inputMap.get("input_footprint_shopping_food_otherfood"));
Map<String, String> extraMap = userService.getExtraInputs(userService.currentUser Map<String, String> extraMap = userService
.getName()); .getExtraInputs(userService.currentUser.getName());
localProduce.setText(extraMap.get("local_produce")); localProduce.setText(extraMap.get("local_produce"));
bike.setText(extraMap.get("bike")); bike.setText(extraMap.get("bike"));
solarPanels.setText(extraMap.get("solar_panels")); solarPanels.setText(extraMap.get("solar_panels"));
@@ -579,21 +580,23 @@ public class DashBoardController {
* @throws InterruptedException throws exception * @throws InterruptedException throws exception
*/ */
public void updateLeaderboard() throws InterruptedException { public void updateLeaderboard() throws InterruptedException {
List<String> userList = userService.getAllUsers();
//global leaderboard //global leaderboard
globalLeaderboard.getItems().clear(); globalLeaderboard.getItems().clear();
globalLeaderData.removeAll(); globalLeaderData.removeAll();
sortScores(userList); List<String> userList = userService.getAllUsers();
List<String> firstList = sortScores(userList);
//development leaderboard //development leaderboard
developmentLeaderboard.getItems().clear(); developmentLeaderboard.getItems().clear();
developmentData.removeAll(); developmentData.removeAll();
sortDiffScores(userList); List<String> secondList = sortDiffScores(userList);
for (int j = 0; j < userList.size(); j++) { for (int i = userList.size() - 1; i >= 0; i--) {
Friend user = new Friend(userList.get(j), userService.getFootprint(userList.get(j))); Friend user = new Friend(firstList.get(i), userService.getFootprint(firstList.get(i)));
double diff = Math.round((userService.getFirstFootprint(userList.get(j))
- userService.getFootprint(userList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(userList.get(j), diff);
globalLeaderData.add(user); globalLeaderData.add(user);
}
for (int j = 0; j < userList.size(); j++) {
double diff = Math.round((userService.getFirstFootprint(secondList.get(j))
- userService.getFootprint(secondList.get(j))) * 10) / 10.0;
Friend diffUser = new Friend(secondList.get(j), diff);
developmentData.add(diffUser); developmentData.add(diffUser);
} }
globalLeaderboard.setItems(globalLeaderData); globalLeaderboard.setItems(globalLeaderData);

View File

@@ -8,13 +8,10 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration; import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@@ -83,8 +80,6 @@ public class ExtraActivityController {
private Label publicTransportLabel; private Label publicTransportLabel;
@FXML @FXML
private Slider publicTransportSlider; private Slider publicTransportSlider;
@FXML
private Button saveButton;
/** /**
@@ -216,30 +211,26 @@ public class ExtraActivityController {
publicTransportPane.setVisible(true); publicTransportPane.setVisible(true);
} }
/** /**
* The method updates the values. * The method updates the values.
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public void save(ActionEvent event) throws InterruptedException { public void save(ActionEvent event) {
Window owner = saveButton.getScene().getWindow(); try {
Float footprint = userService.saveFootprint(userService.currentUser.getName()); updateExtras();
controller.updateLeaderboard(); Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements(); controller.updateLeaderboard();
Stage current = (Stage) owner; controller.updateAchievements();
current.close(); } catch (Exception ex) {
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, System.out.println("continue");
"Activities are added!", }
"Your new activities are added!");
} }
/** /**
* The method updates the values of extras. * The method updates the values of extras.
* @param event user clicks to button
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public void updateExtras(ActionEvent event) throws InterruptedException { public void updateExtras() throws InterruptedException {
if (!bikeLabel.getText().replace(" km", "").equals("0")) { if (!bikeLabel.getText().replace(" km", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(), userService.updateExtraInput(userService.currentUser.getName(),
"bike", "bike",
@@ -252,11 +243,44 @@ public class ExtraActivityController {
} }
if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) { if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) {
userService.updateExtraInput(userService.currentUser.getName(), userService.updateExtraInput(userService.currentUser.getName(),
"bike", "temperature",
temperatureLabel.getText().replace(" Degrees", "")); temperatureLabel.getText().replace(" Degrees", ""));
} }
controller.updateAchievements(); if (!publicTransportLabel.getText().replace(" km", "").equals("0")) {
controller.updateLeaderboard(); userService.updateExtraInput(userService.currentUser.getName(),
"public_transport",
publicTransportLabel.getText().replace(" km", ""));
}
}
/**
* The method updates the values of extras.
*/
@SuppressWarnings("Duplicates")
public void updateExtraVegan() throws InterruptedException {
try {
userService.updateExtraInput(userService.currentUser.getName(), "vegan", "1");
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements();
controller.updateLeaderboard();
} catch (Exception ex) {
System.out.println("continue");
}
}
/**
* The method updates the values of extras.
*/
@SuppressWarnings("Duplicates")
public void updateExtraLocal() throws InterruptedException {
try {
userService.updateExtraInput(userService.currentUser.getName(), "local_produce", "1");
Float footprint = userService.saveFootprint(userService.currentUser.getName());
controller.updateAchievements();
controller.updateLeaderboard();
} catch (Exception ex) {
System.out.println("continue");
}
} }
public class TranslateButtonSkin extends ButtonSkin { public class TranslateButtonSkin extends ButtonSkin {

View File

@@ -221,7 +221,7 @@ public class RegisterWindowController {
//register the user with the provided username and password //register the user with the provided username and password
try { try {
userService.registerUser(userNameText.getText(), passwordField.getText()); userService.registerUser(userNameText.getText(), passwordField.getText());
} catch (RuntimeException ex) { } catch (Exception ex) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"This username has already been taken!"); "This username has already been taken!");
return; return;
@@ -484,6 +484,11 @@ public class RegisterWindowController {
"input_footprint_shopping_services_total", "input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", "")); servicesLabel.getText().replace("€ / month", ""));
} }
try {
extraActivityController.updateExtras();
} catch (Exception ex) {
System.out.println("Continue");
}
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName()); Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
Float footprint = userService.saveFootprint(userService.currentUser.getName()); Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow(); Window owner = saveButton.getScene().getWindow();

View File

@@ -1,21 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import javafx.scene.image.*?> <?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?> <?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController"> <AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
<children> <children>
@@ -84,7 +73,7 @@
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraVegan" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<graphic> <graphic>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
@@ -112,7 +101,7 @@
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -158,7 +147,7 @@
</Label> </Label>
</children> </children>
</HBox> </HBox>
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -195,7 +184,7 @@
</children> </children>
</HBox> </HBox>
<Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" /> <Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" />
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -217,7 +206,7 @@
<Font size="20.0" /> <Font size="20.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addLocalProduceButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addLocalProduceButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtraLocal" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>
@@ -245,7 +234,7 @@
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Text> </Text>
<Button fx:id="addPublicTransportButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b"> <Button fx:id="addPublicTransportButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#save" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
<font> <font>
<Font name="System Bold Italic" size="18.0" /> <Font name="System Bold Italic" size="18.0" />
</font> </font>

View File

@@ -190,7 +190,7 @@ public class InputValidator {
map.put("vegan", "0"); map.put("vegan", "0");
map.put("local_produce", "0"); map.put("local_produce", "0");
map.put("bike", "0"); map.put("bike", "0");
map.put("car", "0"); map.put("public_transport", "0");
map.put("temperature", "0"); map.put("temperature", "0");
map.put("solar_panels", "0"); map.put("solar_panels", "0");
return map; return map;

View File

@@ -91,16 +91,21 @@ public class CalculatorService {
Map<String, String> inputs = user.getFootPrintInputs(); Map<String, String> inputs = user.getFootPrintInputs();
Float netPublic = Float.parseFloat(user.getFootPrintInputs() Float netPublic = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_transportation_publictrans")) .get("input_footprint_transportation_publictrans"))
- Float.parseFloat(user.getExtraInputs().get("bike")); + Float.parseFloat(user.getExtraInputs().get("public_transport"));
Float netCar = Float.parseFloat(user.getFootPrintInputs() Float netCar = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_transportation_miles1")) .get("input_footprint_transportation_miles1"))
- Float.parseFloat(user.getExtraInputs().get("car")); - Float.parseFloat(user.getExtraInputs().get("public_transport"))
- Float.parseFloat(user.getExtraInputs().get("bike"));
Float netVegan = Float.parseFloat(user.getFootPrintInputs() Float netVegan = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_shopping_food_fruitvegetables")) .get("input_footprint_shopping_food_fruitvegetables"))
+ Float.parseFloat(user.getExtraInputs().get("vegan")); + Float.parseFloat(user.getExtraInputs().get("vegan"));
Float netShopping = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_shopping_goods_total"))
- Float.parseFloat(user.getExtraInputs().get("local_produce")) * 100;
inputs.put("input_footprint_transportation_publictrans", netPublic + ""); inputs.put("input_footprint_transportation_publictrans", netPublic + "");
inputs.put("input_footprint_transportation_miles1", netCar + ""); inputs.put("input_footprint_transportation_miles1", netCar + "");
inputs.put("input_footprint_shopping_food_fruitvegetables", netVegan + ""); inputs.put("input_footprint_shopping_food_fruitvegetables", netVegan + "");
inputs.put("input_footprint_shopping_goods_total", netShopping + "");
user.setFootPrintInputs(inputs); user.setFootPrintInputs(inputs);
} }
} }