java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.service.stat.StatService
All Implemented Interfaces:
IStatService

@Service public class StatService extends Object implements 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 Details

    • StatService

      public StatService()
  • Method Details

    • statDeleteItemFromFridge

      public void statDeleteItemFromFridge(StatDeleteFromFridgeDTO statDeleteFromFridgeDTO)
      Adds a new statistic to the database. This method is used when an item is deleted from a fridge.
      Specified by:
      statDeleteItemFromFridge in interface IStatService
      Parameters:
      statDeleteFromFridgeDTO - The DTO containing the information needed to create the statistic
    • statAddItemToFridge

      public void statAddItemToFridge(StatAddItemToFridgeDTO statAddItemToFridgeDTO)
      Adds a new statistic to the database. This method is used when an item is added to a fridge.
      Specified by:
      statAddItemToFridge in interface IStatService
      Parameters:
      statAddItemToFridgeDTO - The DTO containing the information needed to create the statistic
    • getUserStats

      public String getUserStats()
      Gets the statistics for a user as JSON.
      Specified by:
      getUserStats in interface IStatService
      Returns:
      A JSON string of the statistics
    • getFridgeStats

      public String getFridgeStats(Long fridgeId)
      Gets the statistics for a fridge as JSON.
      Specified by:
      getFridgeStats in interface IStatService
      Parameters:
      fridgeId - ID of the fridge
      Returns:
      A JSON string of the statistics
    • getAverageThrownPerDayUser

      public String getAverageThrownPerDayUser() throws com.fasterxml.jackson.core.JsonProcessingException
      Gets the average thrown food per day for a user as JSON.
      Specified by:
      getAverageThrownPerDayUser in interface IStatService
      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 interface IStatService
      Returns:
      A JSON string of the statistics
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If the statistics could not be parsed to JSON
    • getAverageThrownTotalUser

      public Double getAverageThrownTotalUser()
      Gets the total average thrown by the user as JSON. User has to be authenticated.
      Specified by:
      getAverageThrownTotalUser in interface IStatService
      Returns:
      A JSON string of the statistics
    • getAverageThrownTotalFridge

      public Double getAverageThrownTotalFridge(long fridgeId)
      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 interface IStatService
      Parameters:
      fridgeId - ID of the fridge
      Returns:
      A JSON string of the statistics
    • getMoneyWastedPerDayUser

      public String getMoneyWastedPerDayUser() throws com.fasterxml.jackson.core.JsonProcessingException
      Gets the total money wasted by throwing food by user. User has to be authenticated.
      Specified by:
      getMoneyWastedPerDayUser in interface IStatService
      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 interface IStatService
      Returns:
      A JSON string of the statistics
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If the statistics could not be parsed to JSON
    • getMoneyUsedPerDayUser

      public String getMoneyUsedPerDayUser() throws com.fasterxml.jackson.core.JsonProcessingException
      Gets the total money spent by user per day. User has to be authenticated.
      Specified by:
      getMoneyUsedPerDayUser in interface IStatService
      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 interface IStatService
      Returns:
      A JSON string of the statistics
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - If the statistics could not be parsed to JSON