-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshootingstars.py
57 lines (48 loc) · 1.83 KB
/
shootingstars.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
51
52
53
54
55
56
57
from month import Month
class ShootingStars:
def __init__(self, year_capacity):
self.star_count = dict()
self.year_capacity = year_capacity
for i in range(0, year_capacity):
year = dict()
if i == 0:
year[Month.NOVEMBER.name] = [0] * Month.NOVEMBER.val
year[Month.DECEMBER.name] = [0] * Month.DECEMBER.val
else:
for m in Month:
year[m.name] = [0] * m.val
self.star_count[i] = year
def increase_capacity(self, additional_capacity):
for i in range(self.year_capacity, self.year_capacity + additional_capacity):
year = dict()
for m in Month:
year[m.name] = [0] * m.val
self.star_count[i] = year
self.year_capacity += additional_capacity
# indexing of years and days start from 1 from an outside point of view
def add(self, year, month, day, value):
try:
self.star_count[year - 1][month.name][day - 1] = value
except KeyError:
raise Exception("Invalid month/date/day")
def get_count_for_day(self, day):
count = 0
for year in self.star_count.values():
for days in year.values():
try:
count += days[day - 1]
except IndexError:
count += 0
return count
def get_count_for_month(self, month):
count = 0
for year in self.star_count.values():
count += sum(year.get(month.name, []))
return count
def print(self):
for year in self.star_count.values():
for month, days in year.items():
print('%-10s: ' % month, end="")
for day in days:
print("%-3s" % day, end="")
print()