-
Notifications
You must be signed in to change notification settings - Fork 0
/
usage.py
178 lines (154 loc) · 4.71 KB
/
usage.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import datetime as dt
class Usage():
"The class to save usage data..."
def __init__(self, output_path, errors_path):
self.output_path = output_path
self.errors_path = errors_path
self.reset()
#Resseting data variables...
def reset(self):
self.last_save = dt.datetime.now() #the start up time...
self.start = 0
self.color = [0,0,0,0,0,0] #lines, escape, clock, distribution, attractor, surprise...
self.text = [0,0,0,0] #poem, abstract, microtale, definition...
self.noise = [0,0,0,0] #melody, counterpoint, score, surprise...
self.interaction = [0,0,0,0] #text, image, sound, canceled...
self.genuary = 0 #counting genuary requests...
self.number = 0
self.sequence = 0
self.choice = [0,0] #success, empty...
self.shuffle = [0,0] #success, empty...
self.qatar = [0,0] #success, error...
self.language = [0,0] #spanish, english...
self.help = 0
self.wrong_message = 0
self.reports = 0
self.errors = 0
#Building usage information message...
def build_usage_message(self):
m = "<b>Usage data:</b>" + "\n" + \
"start: " + str(self.start) + "\n" + \
"color: " + str(self.color) + "\n" + \
"text: " + str(self.text) + "\n" + \
"noise: " + str(self.noise) + "\n" + \
"interaction: " + str(self.interaction) + "\n" + \
"genuary: " + str(self.genuary) + "\n" + \
"number: " + str(self.number) + "\n" + \
"sequence: " + str(self.sequence) + "\n" + \
"choice: " + str(self.choice) + "\n" + \
"shuffle: " + str(self.shuffle) + "\n" + \
"qatar: " + str(self.qatar) + "\n" + \
"language: " + str(self.language) + "\n" + \
"help: " + str(self.help) + "\n" + \
"wrong_message: " + str(self.wrong_message) + "\n" \
"error reports: " + str(self.reports) + "\n" + \
"errors: " + str(self.errors) + "\n"
return m
#Saving usage to file...
def save_usage(self):
file = open(self.output_path, "a")
t = dt.datetime.now()
i = t - self.last_save
date = str(t.year) + "-" + str(t.month) + "-" + str(t.day)
interval = str(i).split(".")[0]
line = self.build_usage_line(date, interval)
file.write(line)
file.close()
self.reset()
#Building a data line to save...
def build_usage_line(self, date, interval):
line = date + ";"
line += interval + ";"
line += str(self.start) + ";"
line += str(self.color) + ";"
line += str(self.text) + ";"
line += str(self.noise) + ";"
line += str(self.interaction) + ";"
line += str(self.genuary) + ";"
line += str(self.number) + ";"
line += str(self.sequence) + ";"
line += str(self.choice) + ";"
line += str(self.shuffle) + ";"
line += str(self.qatar) + ";"
line += str(self.language) + ";"
line += str(self.help) + ";"
line += str(self.wrong_message) + ";"
line += str(self.reports) + ";"
line += str(self.errors) + "\n"
return line
#Registering a new start command...
def add_start(self):
self.start += 1
#Registering a new color...
def add_color(self, key):
self.color[key] += 1
#Registering a new text...
def add_text(self, key):
self.text[key] += 1
#Registering a new noise...
def add_noise(self, key):
self.noise[key] += 1
#Registering a new interaction...
def add_interaction(self, key):
self.interaction[key] += 1
#Registering a new genuary...
def add_genuary(self):
self.genuary += 1
#Registering a new number...
def add_number(self):
self.number += 1
#Registering a new sequence...
def add_sequence(self):
self.sequence += 1
#Registering a new choice...
def add_choice(self, success):
if success:
self.choice[0] += 1
else:
self.choice[1] += 1
#Registering a new choice...
def add_shuffle(self, success):
if success:
self.shuffle[0] += 1
else:
self.shuffle[1] += 1
#Registering a new qatar...
def add_qatar(self, success):
if success:
self.qatar[0] += 1
else:
self.qatar[1] += 1
#Registering a new language...
def add_language(self, l):
self.language[l] += 1
#Registering a new help...
def add_help(self):
self.help += 1
#Registering a new wrong_message...
def add_wrong_message(self):
self.wrong_message += 1
#Registering a new wrong_message...
def add_error_report(self):
self.reports += 1
#Registering a new error...
def add_error(self):
self.errors += 1
#Saving en error report...
def save_error_report(self, command, description, user):
file = open(self.errors_path, "a")
t = dt.datetime.now()
date = str(t.year) + "-" + str(t.month) + "-" + str(t.day)
file.write(date)
file.write(";")
file.write(command)
file.write(";")
file.write(description)
file.write(";")
file.write(user + "\n")
file.close()
#Printing Usage()...
def __str__(self):
return "- Azarte Bot\n" + \
" I am the class in charge of saving some usage data...\n" + \
" gitlab.com/azarte/azarte_botn" + \