-
Notifications
You must be signed in to change notification settings - Fork 9
/
graph_generator.py
91 lines (68 loc) · 2.63 KB
/
graph_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import database_related as dr
import string_manipulation as sm
# ALL ACTIONS THAT TOOK PLACE DURING THE ENTIRE GAME
def all_game_all_player_actions(csv_file, game_id):
if csv_file is not None:
# using the csv file
df = pd.read_csv(csv_file)
else:
df = pd.DataFrame(dr.return_all_actions(game_id))
name = df.Name
action = df.Action
timestamp = df.Timestamp
plt.title('All actions during the entire game')
plt.xlabel('Action')
plt.ylabel('Timestamp')
plt.plot(timestamp, action, 'o')
plt.xticks(timestamp, rotation=90)
for i, label in enumerate(name):
plt.annotate(label, (timestamp[i], action[i]), rotation=75)
plt.show()
# ALL ACTIONS A SPECIFIC PLAYER DID DURING THE GAME
def all_game_single_player_actions(csv_file, game_id, name):
if csv_file is not None:
# using the csv file
df = pd.read_csv(csv_file)
else:
# using the database
df = pd.DataFrame(list(dr.return_player_actions(game_id, name)))
# creating the plot
df = df[df['Name'] == sm.string_to_int_or_pass(name)]
action_count = df.Action.value_counts()
action_names = df['Action'].drop_duplicates()
plt.title(f'{name} actions during the entire game')
plt.pie(action_count, labels=action_names, autopct=lambda p: f'{p * sum(action_count) / 100 :.0f}')
plt.axis('equal')
plt.show()
# SPECIFIED ACTION AND COUNTER PER PLAYER
def all_game_specific_action(csv_file, game_id, action):
if csv_file is not None:
# using csv file
df = pd.read_csv(csv_file)
else:
# using the database
df = pd.DataFrame(list(dr.return_specific_action(game_id, action)))
df = df[df['Action'] == action]
player_count = df.Name.value_counts()
player_names = df['Name'].drop_duplicates()
plt.title(f'{action} per player')
plt.bar(player_names, player_count)
plt.xticks(np.arange(len(player_count)))
plt.show()
def all_game_action_family(csv_file, game_id, family):
if csv_file is not None:
# using csv file
df = pd.read_csv(csv_file)
else:
# using database
df = pd.DataFrame(list(dr.return_family_action(game_id, family)))
df = df[df['Action Family'] == family]
action_count = df.Action.value_counts()
action_names = df['Action'].drop_duplicates()
plt.title(family)
plt.pie(action_count, labels=action_names, autopct=lambda p: f'{p * sum(action_count) / 100 :.0f}')
plt.axis('equal')
plt.show()