From c01a301014b8458d75f9fba1449340dd2ac30440 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 24 Jan 2021 14:25:33 -0600 Subject: [PATCH] plot task data with line plot and stacked plot --- stat_analysis.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 stat_analysis.py diff --git a/stat_analysis.py b/stat_analysis.py new file mode 100644 index 0000000..6b560f3 --- /dev/null +++ b/stat_analysis.py @@ -0,0 +1,41 @@ +import re + +import matplotlib.pyplot as plt + +i = 0 +with open('raw_ash.txt', 'r', encoding='utf-8') as file: + working = {'work': 0, 'slut': 0, 'crime': 0, 'total': 0} + changes = {'work': [0], 'slut': [0], 'crime': [0], 'total': [0]} + matches = re.finditer( + r'\[[0-9-:, ]+\] \[\w+\] \[\w+\] Executing \$(work|crime|slut) task.\n\[[0-9-:, ]+\] \[\w+\] \[\w+\] (Gained|Lost) \$(\d+)', + file.read()) + + for match in matches: + task, sign, change = match.group(1), match.group(2) == 'Lost', int(match.group(3)) + if sign: + change *= -1 + print(task, sign, change) + + working[task] += int(change) + working['total'] += int(change) + for key in changes.keys(): + changes[key].append(working[key]) + # changes[key].append(max(0, working[key])) + +print('Finished processing datafile.') + +for k, v in working.items(): + print(f'{k} earned {v}.') +print(f'{sum(working.values())} earned total.') + +fig, ax = plt.subplots() +xaxis = list(range(len(changes['work']))) +for k, v in changes.items(): + ax.plot(xaxis, v, label=k) +# ax.stackplot(, changes.values(), labels=changes.keys()) +ax.legend(loc='upper left') +ax.set_title('Earnings by Task over time') +ax.set_xlabel('Tasks') +ax.set_ylabel('Earnings ($)') + +plt.show()