returning previous results filtered by two different tests

45 views
Skip to first unread message

Suzanne Osgood

unread,
Jan 28, 2025, 12:00:05 PMJan 28
to QATrack+
Hello - hoping someone may be able to help me - I've looked at this tread about filtering previous results

I am trying to get the result from a previous linac output testlist where both a certain dosemeter was used and a certain energy was not skipped - it seems as though even when I try and use two filters either I get an error saying I cannot define two unit test slugs, or I just get the results where one is true (but not both) or it returns no result even when there are test instances which fulfil the criteria. 

I've tried  using both Django Q and multple .filter() but neither seems to work
As some examples:

from qatrack.qa.models import TestInstance, Test
from django.db.models import Q
...

output_testlist = "Outputs - TrueBeam"  #define output testlist series

unit_test_slug = "op_dif_6mv_general"  #define which test you want the value of

 try:
        previous_chamber = TestInstance.objects.filter(
            unit_test_info__unit__number=META["unit_number"],  #go to correct linacs test lists based on current unit
            test_list_instance__test_list__name=output_testlist,  #go to output testlist
            Q(unit_test_info__test__slug="dosemeter",  #filter by dosemeter (value from selection prior in list)
            string_value = dosemeter,
            skipped=False) & Q(unit_test_info__test__slug="op_rdg1_6mv",
            skipped=False)
            ).latest("work_completed")  #look for the last output testlist completed (with filter)
           
       
        last_chamber_tli = previous_chamber.test_list_instance  #define selected testlist (with filter)


However this just give me a syntax error (I think because I am trying to define two different unit_test_info__test__slug)

I have alternatively tried
    try:
        previous_chamber = TestInstance.objects.filter(
            unit_test_info__unit__number=META["unit_number"],  #go to correct linacs test lists based on current unit
            test_list_instance__test_list__name=output_testlist,  #go to output testlist
            work_started__lte=META['work_started'], #define time from when refence recal testlist was started
        ).filter(
            unit_test_info__test__slug="dosemeter",  #filter by dosemeter (value from selection prior in list)
            string_value = dosemeter,
        ).filter(
            unit_test_info__test__slug=unit_test_slug,
            value__isnull=False,
        ).latest("work_completed")  #look for the last output testlist completed (with filter)
       
        last_chamber_tli = previous_chamber.test_list_instance  #define selected testlist (with filter)

Which gives me a results where no test lists are found (even though there are instances which fulfil both criteria)

Any help would be appreciated, thanks

Suzie

Randle Taylor

unread,
Feb 7, 2025, 9:31:41 AMFeb 7
to Suzanne Osgood, QATrack+
Hi Suzie,

Definitely a bit of a tricky query.  This is not super efficient, but conceptually it's a little simpler than doing it in a single query:

# get all test instances where dosemeter was used
test_instances = TestInstance.objects.filter(
    test_list_instance__test_list__name="your test list name",
    work_completed__lt=META['work_started'],
    unit_test_info__test__slug="dosemeter",
    string_value=dosemeter,  # filter for currently selected dosemeter
).order_by("-work_completed")

diff_result = None
for ti in test_instances[:100]:  # Retrieve max of 100 instances to check so you don't retrieve too much data.
    # look at other test instances from the same session to check if your op_rdg1_6mv test was not skipped
    energy_was_not_skipped = ti.test_list_instance.testinstance_set.filter(
        unit_test_info__test__slug="op_rdg1_6mv"
        skipped=False
    ).exists()
    if energy_was_not_skipped:
        # now get the result you're after
        diff_result = ti.test_list_instance.testinstance_set.filter(
            unit_test_info__test__slug="op_dif_6mv_general"
        ).value
        break

if diff_result:
    # do something with your result


Hopefully that sets you on the right path!

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 visit https://groups.google.com/d/msgid/qatrack/0a788dc1-4514-46af-ac49-ac7cafe1274an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages