-
Notifications
You must be signed in to change notification settings - Fork 3
/
pp_statsrecorder.py
60 lines (46 loc) · 2.2 KB
/
pp_statsrecorder.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
import os
"""
Statsrecorder class interfaces to the device that is to save the the statistics records
It has been seperated from the remainder of Pi Presents so developers can use an alternative
statistice recording device e.g. Influxdb
"""
class Statsrecorder(object):
stats_file=None
delimiter=';'
def __init__(self):
# leave this empty, its called by every class that is monitored
return
def init(self,log_path):
# called once when Pi Presents starts
# statistics file, open for appending so its not deleted
bufsize=-1
if Statsrecorder.stats_file is None:
Statsrecorder.stats_file=open(log_path+ os.sep+'pp_logs' + os.sep + 'pp_stats.txt','a',bufsize)
sep='"'+Statsrecorder.delimiter+'"'
# write header if file is empty
if Statsrecorder.stats_file.tell()==0:
Statsrecorder.stats_file.write('"'+'Date'+sep+'Time'+sep+'Show Type'+sep+'Show Ref'+ sep +'Show Title'+sep
+'Command'+sep+'Track Type'+sep+'Track Ref'+sep+'Track Title'+sep+'Location'+sep+'Profile"\n')
def write_stats(self,current_datetime,profile,*args):
# called to write a statistics record
# * args = this type, this ref, this name, action, type, ref, name, location
arg_string=''
for arg in args:
arg_string+= Statsrecorder.delimiter+'"'+arg + '"'
Statsrecorder.stats_file.write ('"'+current_datetime.strftime('%Y-%m-%d') + '"' + Statsrecorder.delimiter+'"'+ current_datetime.strftime('%H:%M:%S') + '"' + arg_string + Statsrecorder.delimiter+'"'+ profile +'"'+"\n")
"""
show_type = args[0]
show_ref = args[1]
show_title = args[2]
command = args[3]
track_type = args[4]
track_ref = args[5]
track_title = args[6]
location = args[7]
print current_datetime,show_type,show_ref,show_title,command,track_type,track_ref,track_title,location,profile
"""
def close(self):
# called when Pi Presents exits for any reason.
Statsrecorder.stats_file.close()
# krt
Statsrecorder.stats_file = None