From fb4e5da1d4605a341056dc035b9db0695b51c24d Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 27 Aug 2021 23:39:48 +0000 Subject: [PATCH 1/2] added event and time delay options (event delay unimplemented) --- src/cli/superscript.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cli/superscript.py b/src/cli/superscript.py index 91d11b5..c10b09a 100644 --- a/src/cli/superscript.py +++ b/src/cli/superscript.py @@ -14,6 +14,9 @@ __changelog__ = """changelog: - added verbose option to linux superscript to allow for interactive output - moved pymongo import to superscript.py - added profile option to linux superscript to profile runtime of script + - added event and time delay options to config + - event delay pauses loop until even listener recieves an update + - time delay pauses loop until the time specified has elapsed since the BEGINNING of previous loop 0.9.3: - improved data loading performance by removing redundant PyMongo client creation (120s to 14s) - passed singular instance of PyMongo client as standin for apikey parameter in all data.py functions @@ -203,7 +206,9 @@ sample_json = """{ "climb-mechanism":true, "attitude":true } - } + }, + "even-delay":false, + "loop-delay":60 }""" def main(send, verbose = False, profile = False): @@ -378,6 +383,12 @@ def main(send, verbose = False, profile = False): set_current_time(client, current_time) send(stdout, INF, "finished all tests in " + str(time.time() - loop_start) + " seconds, looping") + 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") if "exec_threads" in locals(): From 74bcc116a221a6bc4865f8b19d4e5fd182aa9303 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 21 Sep 2021 05:14:54 +0000 Subject: [PATCH 2/2] added databse config getter/setter to data.py, fixed args for data.py functions --- src/cli/data.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/cli/data.py b/src/cli/data.py index e5bfb5b..56f3054 100644 --- a/src/cli/data.py +++ b/src/cli/data.py @@ -114,13 +114,13 @@ def unkeyify_2l(layered_dict): out[i] = list(map(lambda x: x[1], add)) return out -def get_previous_time(apikey): +def get_previous_time(client): - previous_time = get_analysis_flags(apikey, "latest_update") + previous_time = get_analysis_flags(client, "latest_update") if previous_time == None: - set_analysis_flags(apikey, "latest_update", 0) + set_analysis_flags(client, "latest_update", 0) previous_time = 0 else: @@ -129,21 +129,29 @@ def get_previous_time(apikey): return previous_time -def set_current_time(apikey, current_time): +def set_current_time(client, current_time): - set_analysis_flags(apikey, "latest_update", {"latest_update":current_time}) + set_analysis_flags(client, "latest_update", {"latest_update":current_time}) -def load_match(apikey, competition): +def get_database_config(client): - return get_match_data_formatted(apikey, competition) + return get_analysis_flags(client, "config")["config"] -def load_metric(apikey, competition, match, group_name, metrics): +def set_database_config(client, config): + + set_analysis_flags(client, "config", {"config": config}) + +def load_match(client, competition): + + return get_match_data_formatted(client, competition) + +def load_metric(client, competition, match, group_name, metrics): group = {} for team in match[group_name]: - db_data = get_team_metrics_data(apikey, competition, team) + db_data = get_team_metrics_data(client, competition, team) if db_data == None: @@ -165,24 +173,24 @@ def load_metric(apikey, competition, match, group_name, metrics): return group -def load_pit(apikey, competition): +def load_pit(client, competition): - return get_pit_data_formatted(apikey, competition) + return get_pit_data_formatted(client, competition) -def push_match(apikey, competition, results): +def push_match(client, competition, results): for team in results: - push_team_tests_data(apikey, competition, team, results[team]) + push_team_tests_data(client, competition, team, results[team]) -def push_metric(apikey, competition, metric): +def push_metric(client, competition, metric): for team in metric: - push_team_metrics_data(apikey, competition, team, metric[team]) + push_team_metrics_data(client, competition, team, metric[team]) -def push_pit(apikey, competition, pit): +def push_pit(client, competition, pit): for variable in pit: - push_team_pit_data(apikey, competition, variable, pit[variable]) \ No newline at end of file + push_team_pit_data(client, competition, variable, pit[variable]) \ No newline at end of file