Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/daq/update_coda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/rcdb/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
39 changes: 39 additions & 0 deletions python/tests/benchmark_selecting.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 10 additions & 3 deletions rcdb_web/select_values/veiws.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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'))
Expand Down
Loading