Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 658744f
Showing
6 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.cache | ||
.coverage |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import math | ||
import json | ||
|
||
|
||
class DataStats: | ||
|
||
def stats(self, data, iage, isalary): | ||
# iage and isalary are the starting age and salary used to | ||
# compute the average yearly increase of salary. | ||
|
||
# Compute average yearly increase | ||
average_age_increase = math.floor( | ||
sum([e['age'] for e in data])/len(data)) - iage | ||
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) | ||
|
||
# Compute max salary | ||
salaries = [int(e['salary'][1:]) for e in data] | ||
threshold = '£' + str(max(salaries)) | ||
|
||
max_salary = [e for e in data if e['salary'] == threshold] | ||
|
||
# Compute min salary | ||
salaries = [int(d['salary'][1:]) for d in data] | ||
min_salary = [e for e in data if e['salary'] == | ||
'£{}'.format(str(min(salaries)))] | ||
|
||
return json.dumps({ | ||
'avg_age': math.floor(sum([e['age'] for e in data])/len(data)), | ||
'avg_salary': math.floor(sum( | ||
[int(e['salary'][1:]) for e in data])/len(data)), | ||
'avg_yearly_increase': yearly_avg_increase, | ||
'max_salary': max_salary, | ||
'min_salary': min_salary | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[pytest] | ||
minversion = 2.0 | ||
norecursedirs= .git .tox venv* requirements* | ||
python_files = test*.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
coverage==4.4.1 | ||
py==1.4.34 | ||
pytest==3.1.2 | ||
pytest-cov==2.5.1 |
Empty file.