Auto Reference values

86 views
Skip to first unread message

Andrew Alexander

unread,
Dec 11, 2023, 11:43:33 AM12/11/23
to QATrack+
Hi Randy,

The reference value for a test we have changes from year to year as it is the running average of prior results. Currently, we update this reference value manually each year. Is there a path to have this reference value updated automatically each time the test-list is launched? It is easy enough to calculate the running average of the test. 

A workaround might look like this. Calculate the percent difference between the new value and the running average. Set a reference of 0 and appropriate tolerance for the difference. This is not as elegant, but perhaps it is the only way forward. 

Thanks
Andrew

Randle Taylor

unread,
Dec 13, 2023, 9:47:23 PM12/13/23
to Andrew Alexander, QATrack+
Hey Andrew,

In theory it's possible to update the reference when you open a test list, but the problem is that the reference wouldn't take effect until you reload the page. I think it'd be a pretty clunky and potentially confusing process.

Your second option is probably a better way to go about it.  Let me know if you need help setting up the query to fetch the results you would need to calculate the average.

Randy

--
You received this message because you are subscribed to the Google Groups "QATrack+" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/qatrack/3637a2b2-b1f5-4d77-aa52-b4fa14137a18n%40googlegroups.com.

Jonathan Dysart

unread,
Dec 14, 2023, 7:52:28 AM12/14/23
to QATrack+
I'm not sure if this really answers your question because it doesn't update the reference value directly. One solution I use is to have another test that calculates the historical average, then determine the difference from that test value. For this example, I am using a test to determine the PDD(10x) for a photon beam (a sub test that populates into another TG51 testlist). In the testlist I calculate what what the average value was over the last x number of years as a reference value, and compare my current value against that. Doing this is a sanity check, the user can determine pretty easily if there is a setup error for example. 

img1.JPG

Here is the code I use:
import numpy as np
from qatrack.qa.models import TestInstance, TestListInstance
from datetime import datetime

# Get the Test List Instances for this current Unit
tlis = TestListInstance.objects.filter(
    unit_test_collection__unit__number=META["unit_number"],
    test_list__name="TG51 PDD worksheet (Photons)",
    work_completed__lt=META[
        "work_started"
    ],  # only include test list instances performed before the current work_started variable,
)

vals = []
dates = []
for tli in tlis:
    # Check each test list to see it the energy matches
    if (
        tli.testinstance_set.get(unit_test_info__test__name="Beam Energy").get_value()
        == pick_energy
    ):
        vals.append(
            tli.testinstance_set.get(unit_test_info__test__name="PDD(10)x").get_value()
        )
        dates.append(tli.work_started)

UTILS.set_comment(", ".join(f"{v:.2f} ({d:%Y-%m-%d})" for v, d in zip(vals, dates)))

if vals:
    avg_values_historical_photons = np.mean(vals)
else:
    avg_values_historical_photons = None

# Plot the data
fig = UTILS.get_figure()
axes = fig.gca()
axes.plot(dates, vals, "o", label="Historical Values")

axes.plot(
    dates,
    [avg_values_historical_photons for d in dates],
    "--",
    color="b",
    label="Mean",
)
axes.plot(
    dates,
    [1.01 * avg_values_historical_photons for d in dates],
    "--",
    color="r",
    label="+/- 1%",
)
axes.plot(dates, [0.99 * avg_values_historical_photons for d in dates], "--", color="r")

if pdd_10x != None:
    axes.plot(
        META["work_started"],
        pdd_10x,
        marker="o",
        mec="r",
        label=f"Today's Value: {pdd_10x:.3f}%",
    )

axes.set_ylabel("PDD(10)x")
axes.set_xlabel("Date Work Started")
axes.set_title(f"Historical PDD(10)x Values for this Unit and Energy")
axes.legend()
UTILS.write_file("Historical Results.png", fig)


Finally, the figure that gets populated when doing the testlist:
img2.JPG

Hope this help or gives you some ideas!
Jonathan.
Reply all
Reply to author
Forward
0 new messages