class Calculator: """ Get the total benefit @param: INT adults - number of adults @param: INT children - number of children @param: FLOAT income @param: STRING city """ DB = "asumislisa.db" def __init__(self, adults, chilren, income, city, discard_electricity): self.api = DbHandler(Calculator.DB) self.adults = adults self.children = chilren self.income = income self.city_group = self.get_city_group(city) self.discard_electricity def get_city_group(self, city): city = city.strip().upper() return self.api.find_city(city) def discard_electricity(self, rent): """ The constant is estimated from the data of an existing KELA calculator. No official method for discarding the electricity was publicly available. """ return rent - 22.2 def get_excess(self): """ Calculates the excess. Constants are determined by KELA """ return max( 0, 0.42 * (self.income - (597 + 99 * self.adults + 221 * self.children))) def get_acceptable_expenses(self, rent): """ Get the amount of expenses counted as acceptable TODO - count more parameters: heating included/not included water included/not included """ acceptable = self.discard_electricity( rent) if self.discard_electricity else rent return acceptable def get_total_benefit(self, rent): household = self.adults + self.children max_benefit = self.api.get_benefit(household, self.city_group) acceptable_expenses = self.get_acceptable_expenses(rent) acceptable_expenses = min(max_benefit, acceptable_expenses) excess = self.get_excess() return max(0, 0.8 * (acceptable_expenses - excess))