Permalink
Browse files

Step 6 - Isolate the average yearly increase algorithm

  • Loading branch information...
lgiordani committed Jul 15, 2017
1 parent 4122201 commit 4005145f39d36fda0519127d57e1b4099d24e72b
Showing with 12 additions and 4 deletions.
  1. +5 −4 datastats/datastats.py
  2. +7 −0 tests/test_datastats.py
View
@@ -10,7 +10,7 @@ def _avg_salary(self, data):
def _avg_age(self, data):
return math.floor(sum([e['age'] for e in data])/len(data))
def _stats(self, data, iage, isalary):
def _avg_yearly_increase(self, data, iage, isalary):
# iage and isalary are the starting age and salary used to
# compute the average yearly increase of salary.
@@ -20,9 +20,9 @@ def _stats(self, data, iage, isalary):
average_salary_increase = math.floor(
sum([int(e['salary'][1:]) for e in data])/len(data)) - isalary
yearly_avg_increase = math.floor(
average_salary_increase/average_age_increase)
return math.floor(average_salary_increase/average_age_increase)
def _stats(self, data, iage, isalary):
# Compute max salary
salaries = [int(e['salary'][1:]) for e in data]
threshold = '£' + str(max(salaries))
@@ -37,7 +37,8 @@ def _stats(self, data, iage, isalary):
return {
'avg_age': self._avg_age(data),
'avg_salary': self._avg_salary(data),
'avg_yearly_increase': yearly_avg_increase,
'avg_yearly_increase': self._avg_yearly_increase(
data, iage, isalary),
'max_salary': max_salary,
'min_salary': min_salary
}
View
@@ -92,3 +92,10 @@ def test__avg_salary():
ds = DataStats()
assert ds._avg_salary(test_data) == 55165
def test__avg_yearly_increase():
ds = DataStats()
assert ds._avg_yearly_increase(test_data, 20, 20000) == 837

0 comments on commit 4005145

Please sign in to comment.