2020-05-20 13:52:38 +00:00
import json
import superscript as su
import threading
__author__ = (
" Arthur Lu <learthurgo@gmail.com> " ,
)
2020-06-10 18:19:58 +00:00
class Tasker ( ) :
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
match_ = False
metric_ = False
pit_ = False
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
match_enable = True
metric_enable = True
pit_enable = True
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
config = { }
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
def __init__ ( self ) :
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . config = su . load_config ( " config.json " )
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
def match ( self ) :
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . match_ = True
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
apikey = self . config [ " key " ] [ " database " ]
competition = self . config [ " competition " ]
tests = self . config [ " statistics " ] [ " match " ]
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
data = su . load_match ( apikey , competition )
su . matchloop ( apikey , competition , data , tests )
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . match_ = False
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
if self . match_enable == True and self . match_ == False :
2020-06-10 18:19:58 +00:00
task = threading . Thread ( name = " match " , target = match )
task . start ( )
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
def metric ( ) :
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . metric_ = True
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
apikey = self . config [ " key " ] [ " database " ]
tbakey = self . config [ " key " ] [ " tba " ]
competition = self . config [ " competition " ]
metric = self . config [ " statistics " ] [ " metric " ]
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
timestamp = su . get_previous_time ( apikey )
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
su . metricloop ( tbakey , apikey , competition , timestamp , metric )
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . metric_ = False
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
if self . metric_enable == True and self . metric_ == False :
2020-06-10 18:19:58 +00:00
task = threading . Thread ( name = " match " , target = metric )
task . start ( )
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
def pit ( ) :
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . pit_ = True
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
apikey = self . config [ " key " ] [ " database " ]
competition = self . config [ " competition " ]
tests = self . config [ " statistics " ] [ " pit " ]
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
data = su . load_pit ( apikey , competition )
su . pitloop ( apikey , competition , data , tests )
2020-05-20 13:52:38 +00:00
2020-06-10 20:23:53 +00:00
self . pit_ = False
2020-05-24 00:43:59 +00:00
2020-06-10 20:23:53 +00:00
if self . pit_enable == True and self . pit_ == False :
2020-06-10 18:19:58 +00:00
task = threading . Thread ( name = " pit " , target = pit )
task . start ( )
2020-05-24 00:43:59 +00:00
2020-06-10 18:19:58 +00:00
def start_match ( ) :
task = threading . Thread ( name = " match " , target = match )
task . start ( )
def start_metric ( ) :
task = threading . Thread ( name = " match " , target = metric )
task . start ( )
def start_pit ( ) :
2020-05-24 00:43:59 +00:00
task = threading . Thread ( name = " pit " , target = pit )
task . start ( )
2020-05-20 13:52:38 +00:00
2020-06-10 18:19:58 +00:00
def stop_match ( ) :
2020-06-10 20:23:53 +00:00
self . match_enable = False
2020-06-10 18:19:58 +00:00
def stop_metric ( ) :
2020-06-10 20:23:53 +00:00
self . metric_enable = False
2020-06-10 18:19:58 +00:00
def stop_pit ( ) :
2020-06-10 20:23:53 +00:00
self . pit_enable = False
2020-06-10 18:19:58 +00:00
def get_match ( ) :
2020-06-10 20:23:53 +00:00
return self . match_
2020-05-25 22:17:08 +00:00
2020-06-10 18:19:58 +00:00
def get_metric ( ) :
2020-06-10 20:23:53 +00:00
return self . metric_
2020-05-25 22:17:08 +00:00
2020-06-10 18:19:58 +00:00
def get_pit ( ) :
2020-06-10 20:23:53 +00:00
return self . pit_
2020-05-25 22:17:08 +00:00
2020-06-10 18:19:58 +00:00
def get_match_enable ( ) :
2020-06-10 20:23:53 +00:00
return self . match_enable
2020-05-25 22:17:08 +00:00
2020-06-10 18:19:58 +00:00
def get_metric_enable ( ) :
2020-06-10 20:23:53 +00:00
return self . metric_enable
2020-05-25 22:17:08 +00:00
2020-06-10 18:19:58 +00:00
def get_pit_enable ( ) :
2020-06-10 20:23:53 +00:00
return self . pit_enable
2020-06-10 17:46:40 +00:00
"""
2020-05-25 22:17:08 +00:00
def main ( ) :
init ( )
start_match ( )
start_metric ( )
start_pit ( )
exit = False
while ( not exit ) :
i = input ( " > " )
cmds = i . split ( " " )
cmds = [ x for x in cmds if x != " " ]
l = len ( cmds )
if ( l == 0 ) :
pass
else :
if ( cmds [ 0 ] == " exit " ) :
if ( l == 1 ) :
exit = True
else :
print ( " exit command expected no arguments but encountered " + str ( l - 1 ) )
if ( cmds [ 0 ] == " status " ) :
if ( l == 1 ) :
print ( " status command expected 1 argument but encountered none \n type status help for usage " )
elif ( l > 2 ) :
print ( " status command expected 1 argument but encountered " + str ( l - 1 ) )
elif ( cmds [ 1 ] == " threads " ) :
threads = threading . enumerate ( )
threads = [ x . getName ( ) for x in threads ]
print ( " running threads: " )
for thread in threads :
print ( " " + thread )
elif ( cmds [ 1 ] == " flags " ) :
print ( " current flags: " )
print ( " match running: " + match_ )
print ( " metric running: " + metric_ )
print ( " pit running: " + pit_ )
print ( " match enable: " + match_enable )
print ( " metric enable: " + metric_enable )
print ( " pit enable: " + pit_enable )
elif ( cmds [ 1 ] == " config " ) :
print ( " current config: " )
print ( json . dumps ( config ) )
elif ( cmds [ 1 ] == " all " ) :
threads = threading . enumerate ( )
threads = [ x . getName ( ) for x in threads ]
print ( " running threads: " )
for thread in threads :
print ( " " + thread )
print ( " current flags: " )
print ( " match running: " + match_ )
print ( " metric running: " + metric_ )
print ( " pit running: " + pit_ )
print ( " match enable: " + match_enable )
print ( " metric enable: " + metric_enable )
print ( " pit enable: " + pit_enable )
elif ( cmds [ 1 ] == " help " ) :
2020-05-26 01:34:47 +00:00
print ( " usage: status [arg] \n Displays the status of the tra data analysis threads. \n Arguments: \n threads - prints the stuatus ofcurrently running threads \n flags - prints the status of control and indicator flags \n config - prints the current configuration information \n all - prints all statuses \n <name_of_thread> - prints the status of a specific thread " )
2020-05-25 22:17:08 +00:00
else :
threads = threading . enumerate ( )
threads = [ x . getName ( ) for x in threads ]
if ( cmds [ 1 ] in threads ) :
print ( cmds [ 1 ] + " is running " )
if ( __name__ == " __main__ " ) :
2020-06-10 17:46:40 +00:00
main ( )
"""