Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong run title shown #188

Merged
merged 4 commits into from
Sep 30, 2024
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
10 changes: 9 additions & 1 deletion src/webmon_app/reporting/dasmon/view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ def get_cached_variables(instrument_id, monitored_only=False):
:param instrument_id: Instrument object
:param monitored_only: if True, only monitored parameters are returned
"""
parameter_values = StatusCache.objects.filter(instrument_id=instrument_id).order_by("key_id__name")
parameter_values = StatusCache.objects.filter(instrument_id=instrument_id).order_by("key_id__name", "-timestamp")
# Variables that are displayed on top
top_variables = ["run_number", "proposal_id", "run_title"]
key_value_pairs = []
keys_used = set()
for kvp in parameter_values:

if kvp.key_id in keys_used:
# only used the first value for each key, will be ordered newest first
continue

keys_used.add(kvp.key_id)

if kvp.key_id.monitored or monitored_only is False:
# Exclude top variables
if monitored_only and str(kvp.key_id) in top_variables:
Expand Down
11 changes: 8 additions & 3 deletions src/webmon_app/reporting/tests/test_dasmon/test_view_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ def setUpClass(cls):
proposal_id.save()
run_title = Parameter.objects.create(name="run_title")
run_title.save()

# we add the run_title twice to check that the newest one is returned
for p, v in zip(
[para, run_number, cnt_rate, proposal_id, run_title],
["testValue", 0, 1, 2, "testRunTitle"],
[para, run_number, cnt_rate, proposal_id, run_title, run_title],
["testValue", 0, 1, 2, "testRunTitle", "testRunTitleNew"],
):
StatusVariable.objects.create(
instrument_id=inst,
Expand Down Expand Up @@ -106,6 +108,9 @@ def test_get_cached_variables(self):
for d in pairs:
if d["key"] == "testParam":
assert d["value"] == ref_val["value"]
if d["key"] == "run_title":
# expect run_title==testRunTitleNew because it's newest
assert d["value"] == "testRunTitleNew"
for d in pairs_monitoredOnly:
if d["key"] == "testParam":
assert d["value"] == ref_val["value"]
Expand Down Expand Up @@ -409,7 +414,7 @@ def test_fill_template_values(
assert template["run_number"] == "0"
assert template["count_rate"] == "-"
assert template["proposal_id"] == "2"
assert template["run_title"] == "testRunTitle"
assert template["run_title"] == "testRunTitleNew"

def test_get_live_variables(self):
from reporting.dasmon.view_util import get_live_variables
Expand Down