-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeople.py
50 lines (42 loc) · 1.67 KB
/
people.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys, json
class people():
def __init__(self, people_filename):
try:
data = json.loads(open(people_filename).read())
except Exception as e:
print('Error with people file: %s' % str(e))
return
# how much they cost as a multipe of their salary -- assumed constant
self.cost_per_salary = data['cost_per_salary']
people = {}
dp = data['people']
for person in dp.keys():
d = {}
if 'salary' in dp[person]:
d['fulltimeCost'] = dp[person]['salary'] * self.cost_per_salary / 12
else:
print('ERROR: %s has no fulltimeCost (salary)' % person)
continue
if 'spine' in dp[person]:
d['spine'] = dp[person]['spine']
if 'staffNumber' in dp[person]:
d['staffNumber'] = dp[person]['staffNumber']
people[person] = d
self.people = people
self.people_name_set = people.keys()
def print(self):
print('Monthly cost per full-time person\nwith cost/salary ratio %6.3f\n' % self.cost_per_salary)
print('Each line is: Name (spine) Cost')
for person in self.people_name_set:
print('%12s (%7s) £%5.0f' % \
(person, self.people[person]['spine'], self.people[person]['fulltimeCost']))
def all_names(self):
return list(self.people.keys())
def set_names(self, person_set):
self.people_name_set = person_set
print('Restricting attention to ', self.people_name_set)
##########
if __name__ == '__main__':
import settings
pe = people(settings.PEOPLE)
pe.print()