Class StatService
java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.service.stat.StatService
- All Implemented Interfaces:
IStatService
Service for handling statistics. This service is used to get statistics for a user, fridge or item. Can both generate
and get statistics.
- Author:
- Brage H. Kvamme
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAverageThrownPerDayFridge
(long fridgeId) Gets the average thrown food per day for a fridge as JSON.Gets the average thrown food per day for a user as JSON.getAverageThrownTotalFridge
(long fridgeId) Gets the total average thrown in the fridge as JSON.Gets the total average thrown by the user as JSON.getFridgeStats
(Long fridgeId) Gets the statistics for a fridge as JSON.getMoneyUsedPerDayFridge
(Long fridgeId) Gets the total money spent by fridge per day.Gets the total money spent by user per day.getMoneyWastedPerDayFridge
(Long fridgeId) Gets the total money wasted by throwing food by fridge.Gets the total money wasted by throwing food by user.Gets the statistics for a user as JSON.void
statAddItemToFridge
(StatAddItemToFridgeDTO statAddItemToFridgeDTO) Adds a new statistic to the database.void
statDeleteItemFromFridge
(StatDeleteFromFridgeDTO statDeleteFromFridgeDTO) Adds a new statistic to the database.
-
Constructor Details
-
StatService
public StatService()
-
-
Method Details
-
statDeleteItemFromFridge
Adds a new statistic to the database. This method is used when an item is deleted from a fridge.- Specified by:
statDeleteItemFromFridge
in interfaceIStatService
- Parameters:
statDeleteFromFridgeDTO
- The DTO containing the information needed to create the statistic
-
statAddItemToFridge
Adds a new statistic to the database. This method is used when an item is added to a fridge.- Specified by:
statAddItemToFridge
in interfaceIStatService
- Parameters:
statAddItemToFridgeDTO
- The DTO containing the information needed to create the statistic
-
getUserStats
Gets the statistics for a user as JSON.- Specified by:
getUserStats
in interfaceIStatService
- Returns:
- A JSON string of the statistics
-
getFridgeStats
Gets the statistics for a fridge as JSON.- Specified by:
getFridgeStats
in interfaceIStatService
- Parameters:
fridgeId
- ID of the fridge- Returns:
- A JSON string of the statistics
-
getAverageThrownPerDayUser
public String getAverageThrownPerDayUser() throws com.fasterxml.jackson.core.JsonProcessingExceptionGets the average thrown food per day for a user as JSON.- Specified by:
getAverageThrownPerDayUser
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-
getAverageThrownPerDayFridge
public String getAverageThrownPerDayFridge(long fridgeId) throws com.fasterxml.jackson.core.JsonProcessingException Gets the average thrown food per day for a fridge as JSON.- Specified by:
getAverageThrownPerDayFridge
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-
getAverageThrownTotalUser
Gets the total average thrown by the user as JSON. User has to be authenticated.- Specified by:
getAverageThrownTotalUser
in interfaceIStatService
- Returns:
- A JSON string of the statistics
-
getAverageThrownTotalFridge
Gets the total average thrown in the fridge as JSON. User has to be authenticated and be a part of the fridge.- Specified by:
getAverageThrownTotalFridge
in interfaceIStatService
- Parameters:
fridgeId
- ID of the fridge- Returns:
- A JSON string of the statistics
-
getMoneyWastedPerDayUser
Gets the total money wasted by throwing food by user. User has to be authenticated.- Specified by:
getMoneyWastedPerDayUser
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-
getMoneyWastedPerDayFridge
public String getMoneyWastedPerDayFridge(Long fridgeId) throws com.fasterxml.jackson.core.JsonProcessingException Gets the total money wasted by throwing food by fridge. User has to be authenticated and be a part of the fridge.- Specified by:
getMoneyWastedPerDayFridge
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-
getMoneyUsedPerDayUser
Gets the total money spent by user per day. User has to be authenticated.- Specified by:
getMoneyUsedPerDayUser
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-
getMoneyUsedPerDayFridge
public String getMoneyUsedPerDayFridge(Long fridgeId) throws com.fasterxml.jackson.core.JsonProcessingException Gets the total money spent by fridge per day. User has to be authenticated and be a part of the fridge to use this method.- Specified by:
getMoneyUsedPerDayFridge
in interfaceIStatService
- Returns:
- A JSON string of the statistics
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
- If the statistics could not be parsed to JSON
-