Merge pull request #17 from titanscouting/event-listener

Pull changes from event-listener to superscript-v1
This commit is contained in:
Arthur Lu 2021-10-10 19:52:53 -07:00 committed by GitHub
commit 82b62924f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View File

@ -193,5 +193,9 @@ def push_metric(client, competition, metric):
def push_pit(client, competition, pit):
for variable in pit:
push_team_pit_data(apikey, competition, variable, pit[variable])
push_team_pit_data(client, competition, variable, pit[variable])
def check_new_database_matches(client, competition):
return True

View File

@ -164,7 +164,7 @@ import warnings
import websockets
from interface import splash, log, ERR, INF, stdout, stderr
from data import get_previous_time, pull_new_tba_matches, set_current_time, load_match, push_match, load_pit, push_pit, get_database_config, set_database_config
from data import get_previous_time, pull_new_tba_matches, set_current_time, load_match, push_match, load_pit, push_pit, get_database_config, set_database_config, check_new_database_matches
from processing import matchloop, metricloop, pitloop
config_path = "config.json"
@ -216,11 +216,10 @@ sample_json = """{
"strategic-focus":true,
"climb-mechanism":true,
"attitude":true
}
},
"even-delay":false,
"loop-delay":60
}
},
"event-delay":false,
"loop-delay":60
}
}"""
def main(send, verbose = False, profile = False, debug = False):
@ -315,11 +314,20 @@ def main(send, verbose = False, profile = False, debug = False):
if profile:
return # return instead of break to avoid sys.exit
loop_delay = float(config["variable"]["loop-delay"])
remaining_time = loop_delay - (time.time() - loop_start)
if remaining_time > 0:
send(stdout, INF, "loop delayed by " + str(remaining_time) + " seconds")
time.sleep(remaining_time)
event_delay = config["event-delay"]
if event_delay:
send(stdout, INF, "loop delayed until database returns new matches")
new_match = False
while not new_match:
time.sleep(1)
new_match = check_new_database_matches(client, competition)
send(stdout, INF, "database returned new matches")
else:
loop_delay = float(config["loop-delay"])
remaining_time = loop_delay - (time.time() - loop_start)
if remaining_time > 0:
send(stdout, INF, "loop delayed by " + str(remaining_time) + " seconds")
time.sleep(remaining_time)
except KeyboardInterrupt:
send(stdout, INF, "detected KeyboardInterrupt, killing threads")