Skip to content

Commit

Permalink
Initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lgiordani committed Jul 15, 2017
0 parents commit 658744f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.cache
.coverage
Empty file added datastats/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions datastats/datastats.py
@@ -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
})
4 changes: 4 additions & 0 deletions pytest.ini
@@ -0,0 +1,4 @@
[pytest]
minversion = 2.0
norecursedirs= .git .tox venv* requirements*
python_files = test*.py
4 changes: 4 additions & 0 deletions requirements.txt
@@ -0,0 +1,4 @@
coverage==4.4.1
py==1.4.34
pytest==3.1.2
pytest-cov==2.5.1
Empty file added tests/__init__.py
Empty file.

0 comments on commit 658744f

Please sign in to comment.