Weakly Miles Calculation
by in CodeSOD on 2023-06-05Emma found a function called get_mileage_per_year
. The purpose of the function is to apply some business rules around travel expenses, and while I'm sure it does that… it also makes some choices.
def get_mileage_per_year(self):
# Mileage not set yet
if not self.mileage_per_day:
return 0
weekly_miles = self.mileage_per_day
extra_miles = 60 - self.mileage_per_day if self.purposes == ["special"] else 25
# Add in extra miles for 'special' purpose is selected
weekly_miles += extra_miles if "special" in self.purposes else 0
# where average daily miles are given by the weekly miles variable
annual_miles = (weekly_miles * 365) + 2000
if "special" in self.purposes:
annual_miles = max(annual_miles, 24000)
# Return annual miles bound to range 4,000 < mileage < 50,000
mileage = int(min(max(annual_miles, 4000), 50000))
return mileage