department.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """
  2. Calculate percentage level of index for regions
  3. inside the Verenigde Nederlanden.
  4. """
  5. import math
  6. import re
  7. from datetime import timedelta
  8. import dateutil.parser
  9. # Config
  10. PLAYER = True
  11. DATE = True
  12. PLAYERS = {}
  13. DAYS = {}
  14. def calculate_buildings():
  15. """Count working in departments"""
  16. total = 0
  17. total_reward = 0
  18. with open('department.txt', 'r') as file:
  19. for line in file:
  20. try:
  21. date_str = re.search(r'\s\d\d.*', line).group(0)
  22. date_str = re.sub(r'\s\d\d\s', '', date_str)
  23. date = dateutil.parser.parse(date_str)
  24. if date.hour >= 20:
  25. date += timedelta(days=1)
  26. line = re.sub(r'\s\d\d.*', '', line)
  27. line = re.sub(r'\[.*\]', '', line)
  28. line = line.strip()
  29. count = re.search(r'\+\d+', line).group(0)
  30. count = count.replace('+', '')
  31. count = int(count)
  32. total += count
  33. if PLAYER:
  34. player = re.sub(r'\s\(.*', '', line)
  35. if player in PLAYERS:
  36. PLAYERS[player] += count
  37. else:
  38. PLAYERS[player] = count
  39. if DATE:
  40. date_format = date.strftime("%Y-%m-%d")
  41. if date_format in DAYS:
  42. DAYS[date_format] += count
  43. else:
  44. DAYS[date_format] = count
  45. except Exception as exception:
  46. print('%s %s' % (line, exception))
  47. if PLAYER:
  48. print('punten,beloning,naam')
  49. for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
  50. worked_times = math.floor(PLAYERS[player] / 10)
  51. reward = worked_times * 2000000000
  52. if worked_times >= 6:
  53. reward += 10000000000
  54. total_reward += reward
  55. print('%3s,$ %5s,%s' % (PLAYERS[player], bucks(reward), player))
  56. if DATE:
  57. for date in sorted(DAYS, reverse=True):
  58. print('%s,%3s' % (date, DAYS[date]))
  59. print(total)
  60. print(total_reward)
  61. def bucks(money):
  62. """Format money"""
  63. str_format = '{:,}'.format(money)
  64. new_str = ''
  65. for i in range(len(str_format), 0, -4):
  66. if str_format[i-4:i] == ',000':
  67. new_str = 'k' + new_str
  68. else:
  69. new_str = str_format[:i] + new_str
  70. break
  71. new_str = new_str.replace('kkkk', 't')
  72. new_str = new_str.replace(',', '.')
  73. return new_str
  74. if __name__ == '__main__':
  75. calculate_buildings()