|
@@ -5,30 +5,56 @@ inside the Verenigde Nederlanden.
|
|
|
"""
|
|
|
|
|
|
import re
|
|
|
+from datetime import timedelta
|
|
|
+import dateutil.parser
|
|
|
|
|
|
-PLAYERS = {}
|
|
|
+# Config
|
|
|
+PLAYER = False
|
|
|
+DATE = True
|
|
|
|
|
|
+PLAYERS = {}
|
|
|
+DAYS = {}
|
|
|
|
|
|
def calculate_buildings():
|
|
|
"""Count working in departments"""
|
|
|
with open('department.txt', 'r') as file:
|
|
|
for line in file:
|
|
|
- line = re.sub(r'\s\d\d.*', '', line)
|
|
|
- line = re.sub(r'\[.*\]', '', line)
|
|
|
- line = line.strip()
|
|
|
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('+', '')
|
|
|
- player = re.sub(r'\s\(.*', '', line)
|
|
|
- if player in PLAYERS:
|
|
|
- PLAYERS[player] += int(count)
|
|
|
- else:
|
|
|
- PLAYERS[player] = 0
|
|
|
+
|
|
|
+ if PLAYER:
|
|
|
+ player = re.sub(r'\s\(.*', '', line)
|
|
|
+ if player in PLAYERS:
|
|
|
+ PLAYERS[player] += int(count)
|
|
|
+ else:
|
|
|
+ PLAYERS[player] = int(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)
|
|
|
except Exception as exception:
|
|
|
print('%s %s' % (line, exception))
|
|
|
|
|
|
- for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
|
|
|
- print('%3s %s' % (PLAYERS[player], player))
|
|
|
+ if PLAYER:
|
|
|
+ for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
|
|
|
+ print('%3s %s' % (PLAYERS[player], player))
|
|
|
+ if DATE:
|
|
|
+ for date in sorted(DAYS, reverse=True):
|
|
|
+ print('%s,%3s' % (date, DAYS[date]))
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|