|  | @@ -4,6 +4,7 @@ Calculate percentage level of index for regions
 | 
	
		
			
				|  |  |  inside the Verenigde Nederlanden.
 | 
	
		
			
				|  |  |  """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import sys
 | 
	
		
			
				|  |  |  import math
 | 
	
		
			
				|  |  |  import re
 | 
	
		
			
				|  |  |  from datetime import timedelta
 | 
	
	
		
			
				|  | @@ -13,14 +14,13 @@ import dateutil.parser
 | 
	
		
			
				|  |  |  PLAYER = True
 | 
	
		
			
				|  |  |  DATE = True
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -PLAYERS = {}
 | 
	
		
			
				|  |  | -DAYS = {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -def calculate_buildings():
 | 
	
		
			
				|  |  | +def calculate_buildings(filename='department.txt'):
 | 
	
		
			
				|  |  |      """Count working in departments"""
 | 
	
		
			
				|  |  |      total = 0
 | 
	
		
			
				|  |  | -    total_reward = 0
 | 
	
		
			
				|  |  | -    with open('department.txt', 'r') as file:
 | 
	
		
			
				|  |  | +    players = {}
 | 
	
		
			
				|  |  | +    days = {}
 | 
	
		
			
				|  |  | +    with open(filename, 'r') as file:
 | 
	
		
			
				|  |  |          for line in file:
 | 
	
		
			
				|  |  |              try:
 | 
	
		
			
				|  |  |                  date_str = re.search(r'\s\d\d.*', line).group(0)
 | 
	
	
		
			
				|  | @@ -40,37 +40,49 @@ def calculate_buildings():
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  if PLAYER:
 | 
	
		
			
				|  |  |                      player = re.sub(r'\s\(.*', '', line)
 | 
	
		
			
				|  |  | -                    if player in PLAYERS:
 | 
	
		
			
				|  |  | -                        PLAYERS[player] += count
 | 
	
		
			
				|  |  | +                    if player in players:
 | 
	
		
			
				|  |  | +                        players[player] += count
 | 
	
		
			
				|  |  |                      else:
 | 
	
		
			
				|  |  | -                        PLAYERS[player] = count
 | 
	
		
			
				|  |  | +                        players[player] = count
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  if DATE:
 | 
	
		
			
				|  |  |                      date_format = date.strftime("%Y-%m-%d")
 | 
	
		
			
				|  |  | -                    if date_format in DAYS:
 | 
	
		
			
				|  |  | -                        DAYS[date_format] += count
 | 
	
		
			
				|  |  | +                    if date_format in days:
 | 
	
		
			
				|  |  | +                        days[date_format] += count
 | 
	
		
			
				|  |  |                      else:
 | 
	
		
			
				|  |  | -                        DAYS[date_format] = count
 | 
	
		
			
				|  |  | +                        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))
 | 
	
		
			
				|  |  | +        print_players(players)
 | 
	
		
			
				|  |  |      if DATE:
 | 
	
		
			
				|  |  | -        for date in sorted(DAYS, reverse=True):
 | 
	
		
			
				|  |  | -            print('%s,%3s' % (date, DAYS[date]))
 | 
	
		
			
				|  |  | +        print_days(days)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      print(total)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +def print_players(players):
 | 
	
		
			
				|  |  | +    """Print players and reward"""
 | 
	
		
			
				|  |  | +    total_reward = 0
 | 
	
		
			
				|  |  | +    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))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      print(total_reward)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +def print_days(days):
 | 
	
		
			
				|  |  | +    """Print date and points"""
 | 
	
		
			
				|  |  | +    for date in sorted(days, reverse=True):
 | 
	
		
			
				|  |  | +        print('%s,%3s' % (date, days[date]))
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  def bucks(money):
 | 
	
		
			
				|  |  |      """Format money"""
 | 
	
		
			
				|  |  |      str_format = '{:,}'.format(money)
 | 
	
	
		
			
				|  | @@ -88,4 +100,7 @@ def bucks(money):
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  if __name__ == '__main__':
 | 
	
		
			
				|  |  | -    calculate_buildings()
 | 
	
		
			
				|  |  | +    if len(sys.argv) < 2:
 | 
	
		
			
				|  |  | +        calculate_buildings()
 | 
	
		
			
				|  |  | +    else:
 | 
	
		
			
				|  |  | +        calculate_buildings(sys.argv[1])
 |