From 4078a319e0fc48f81385a90f3c8d1a2584304774 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Wed, 18 Dec 2024 13:23:44 -0500 Subject: [PATCH 1/3] Update for newer SQLAlchemy execute() API --- python/rcdb/provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/rcdb/provider.py b/python/rcdb/provider.py index e842b2a..c344eb0 100644 --- a/python/rcdb/provider.py +++ b/python/rcdb/provider.py @@ -1001,7 +1001,7 @@ def select_values(self, val_names=None, search_str="", run_min=0, run_max=sys.ma #sql.bindparams(run_max=run_max, run_min=run_min) #result = self.session.connection().execute(sql) - result = self.session.connection().execute(sql, parameters={"run_min": run_min, "run_max":run_max}) + result = self.session.connection().execute(sql, {"run_min": run_min, "run_max":run_max}) query_sw.stop() From 5075c27460d6113fa2ed2a17ef057146875e71dd Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Wed, 18 Dec 2024 13:24:00 -0500 Subject: [PATCH 2/3] select_runs vs select_values benchmark --- python/tests/benchmark_selecting.py | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 python/tests/benchmark_selecting.py diff --git a/python/tests/benchmark_selecting.py b/python/tests/benchmark_selecting.py new file mode 100644 index 0000000..62617a4 --- /dev/null +++ b/python/tests/benchmark_selecting.py @@ -0,0 +1,39 @@ +import time +import rcdb + +selection = "@is_production and not @is_empty_target and cdc_gas_pressure >=99.8 and cdc_gas_pressure<=100.2" +run_min = 0 +run_max = 1000000 + +def run_select_runs(): + db = rcdb.RCDBProvider("mysql://rcdb@hallddb/rcdb2") + runs = db.select_runs(selection,run_min, run_max) + +def run_select_values(): + db = rcdb.RCDBProvider("mysql://rcdb@hallddb/rcdb2") + runs = db.select_values(['polarization_angle','beam_current'], selection, run_min=run_min, run_max=run_max) + print(" preparation {}", runs.performance["preparation"]) + print(" query {}", runs.performance["query"]) + print(" selection {}", runs.performance["selection"]) + print(" total {}", runs.performance["total"]) + + +def benchmark_function(func, n=1): + """ + Run the given function `n` times and measure the total and average time. + """ + total_time = 0.0 + for i in range(n): + start = time.time() + func() + end = time.time() + elapsed = end - start + total_time += elapsed + print(f"Run {i+1}: {func.__name__} took {elapsed:.6f} seconds") + avg_time = total_time / n + print(f"Average time for {func.__name__} over {n} runs: {avg_time:.6f} seconds\n") + +if __name__ == "__main__": + # Adjust the number of runs as needed + # benchmark_function(run_select_runs, n=5) + benchmark_function(run_select_values, n=5) \ No newline at end of file From 5c70559c082b6866532f0c18d29f161b9eb55691 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Tue, 14 Jan 2025 18:14:32 -0500 Subject: [PATCH 3/3] Fix web gui crash in view values, minor changes. --- python/daq/update_coda.py | 2 +- rcdb_web/select_values/veiws.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/python/daq/update_coda.py b/python/daq/update_coda.py index 4e6a5e4..6354980 100644 --- a/python/daq/update_coda.py +++ b/python/daq/update_coda.py @@ -28,7 +28,7 @@ def update_coda_conditions(context, parse_result): # Run! Run Lu.. I mean, run number is the major thing, starting with it if parse_result.run_number is None: - log.warn("parse_result.run_number is None. (!) Run. Number. Is. None!!!") + log.warning("parse_result.run_number is None. (!) Run. Number. Is. None!!!") return if context.reason == UpdateReasons.END and not db.get_run(parse_result.run_number): diff --git a/rcdb_web/select_values/veiws.py b/rcdb_web/select_values/veiws.py index 656518e..308c252 100644 --- a/rcdb_web/select_values/veiws.py +++ b/rcdb_web/select_values/veiws.py @@ -1,5 +1,5 @@ from flask import Blueprint, request, render_template, flash, g, redirect, url_for -from rcdb.model import ConditionType, RunPeriod +from rcdb.model import ConditionType, RunPeriod, RCDB_MAX_RUN from runs.views import _parse_run_range mod = Blueprint('select_values', __name__, url_prefix='/select_values') @@ -27,9 +27,16 @@ def index(): run_from, run_to = _parse_run_range(run_range) + # If run_to is none, this means that it is infinite + if run_to is None: + run_to = RCDB_MAX_RUN + try: - table = g.tdb.select_values(val_names=req_conditions_values, search_str=search_query, run_min=run_from, - run_max=run_to, sort_desc=True) + table = g.tdb.select_values(val_names=req_conditions_values, + search_str=search_query, + run_min=run_from, + run_max=run_to, + sort_desc=True) except Exception as err: flash("Error in performing request: {}".format(err), 'danger') return redirect(url_for('select_values.index'))