|
@@ -4,12 +4,13 @@ Calculate percentage level of index for regions
|
|
|
inside the Verenigde Nederlanden.
|
|
|
"""
|
|
|
|
|
|
+import math
|
|
|
import re
|
|
|
from datetime import timedelta
|
|
|
import dateutil.parser
|
|
|
|
|
|
|
|
|
-PLAYER = False
|
|
|
+PLAYER = True
|
|
|
DATE = True
|
|
|
|
|
|
PLAYERS = {}
|
|
@@ -17,13 +18,15 @@ DAYS = {}
|
|
|
|
|
|
def calculate_buildings():
|
|
|
"""Count working in departments"""
|
|
|
+ total = 0
|
|
|
+ total_reward = 0
|
|
|
with open('department.txt', 'r') as file:
|
|
|
for line in file:
|
|
|
try:
|
|
|
date_str = re.search(r'\s\d\d.*', line).group(0)
|
|
|
date_str = re.sub(r'\s\d\d\s', '', date_str)
|
|
|
date = dateutil.parser.parse(date_str)
|
|
|
- if date.hour >= 20:
|
|
|
+ if date.hour >= 20:
|
|
|
date += timedelta(days=1)
|
|
|
|
|
|
line = re.sub(r'\s\d\d.*', '', line)
|
|
@@ -32,30 +35,57 @@ def calculate_buildings():
|
|
|
|
|
|
count = re.search(r'\+\d+', line).group(0)
|
|
|
count = count.replace('+', '')
|
|
|
+ count = int(count)
|
|
|
+ total += count
|
|
|
|
|
|
if PLAYER:
|
|
|
player = re.sub(r'\s\(.*', '', line)
|
|
|
if player in PLAYERS:
|
|
|
- PLAYERS[player] += int(count)
|
|
|
+ PLAYERS[player] += count
|
|
|
else:
|
|
|
- PLAYERS[player] = int(count)
|
|
|
+ PLAYERS[player] = count
|
|
|
|
|
|
if DATE:
|
|
|
date_format = date.strftime("%Y-%m-%d")
|
|
|
if date_format in DAYS:
|
|
|
- DAYS[date_format] += int(count)
|
|
|
- else:
|
|
|
- DAYS[date_format] = int(count)
|
|
|
+ DAYS[date_format] += count
|
|
|
+ else:
|
|
|
+ DAYS[date_format] = count
|
|
|
except Exception as exception:
|
|
|
print('%s %s' % (line, exception))
|
|
|
|
|
|
if PLAYER:
|
|
|
+ print('punten,beloning,naam')
|
|
|
for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
|
|
|
- print('%3s %s' % (PLAYERS[player], player))
|
|
|
+ worked_times = math.floor(PLAYERS[player] / 10)
|
|
|
+ reward = worked_times * 2000000000
|
|
|
+ if worked_times >= 6:
|
|
|
+ reward += 10000000000
|
|
|
+ total_reward += reward
|
|
|
+ print('%3s,$ %5s,%s' % (PLAYERS[player], bucks(reward), player))
|
|
|
if DATE:
|
|
|
for date in sorted(DAYS, reverse=True):
|
|
|
print('%s,%3s' % (date, DAYS[date]))
|
|
|
|
|
|
+ print(total)
|
|
|
+ print(total_reward)
|
|
|
+
|
|
|
+
|
|
|
+def bucks(money):
|
|
|
+ """Format money"""
|
|
|
+ str_format = '{:,}'.format(money)
|
|
|
+ new_str = ''
|
|
|
+ for i in range(len(str_format), 0, -4):
|
|
|
+ if str_format[i-4:i] == ',000':
|
|
|
+ new_str = 'k' + new_str
|
|
|
+ else:
|
|
|
+ new_str = str_format[:i] + new_str
|
|
|
+ break
|
|
|
+
|
|
|
+ new_str = new_str.replace('kkkk', 't')
|
|
|
+ new_str = new_str.replace(',', '.')
|
|
|
+ return new_str
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
calculate_buildings()
|