""" Calculate percentage level of index for regions inside the Verenigde Nederlanden. """ import math import re from datetime import timedelta import dateutil.parser # Config PLAYER = True DATE = True PLAYERS = {} 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: date += timedelta(days=1) line = re.sub(r'\s\d\d.*', '', line) line = re.sub(r'\[.*\]', '', line) line = line.strip() 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] += count else: PLAYERS[player] = count if DATE: date_format = date.strftime("%Y-%m-%d") if date_format in DAYS: 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): 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()