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

View File

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

View File

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

View File

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

View File

@@ -1,21 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?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">
<children>
@@ -84,7 +73,7 @@
<Font size="20.0" />
</font>
</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>
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
<image>
@@ -112,7 +101,7 @@
<Font size="18.0" />
</font>
</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 name="System Bold Italic" size="18.0" />
</font>
@@ -158,7 +147,7 @@
</Label>
</children>
</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 name="System Bold Italic" size="18.0" />
</font>
@@ -195,7 +184,7 @@
</children>
</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" />
<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 name="System Bold Italic" size="18.0" />
</font>
@@ -217,7 +206,7 @@
<Font size="20.0" />
</font>
</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 name="System Bold Italic" size="18.0" />
</font>
@@ -245,7 +234,7 @@
<Font size="18.0" />
</font>
</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 name="System Bold Italic" size="18.0" />
</font>

View File

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

View File

@@ -91,16 +91,21 @@ public class CalculatorService {
Map<String, String> inputs = user.getFootPrintInputs();
Float netPublic = Float.parseFloat(user.getFootPrintInputs()
.get("input_footprint_transportation_publictrans"))
- Float.parseFloat(user.getExtraInputs().get("bike"));
+ Float.parseFloat(user.getExtraInputs().get("public_transport"));
Float netCar = Float.parseFloat(user.getFootPrintInputs()
.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()
.get("input_footprint_shopping_food_fruitvegetables"))
+ 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_miles1", netCar + "");
inputs.put("input_footprint_shopping_food_fruitvegetables", netVegan + "");
inputs.put("input_footprint_shopping_goods_total", netShopping + "");
user.setFootPrintInputs(inputs);
}
}