from qatrack.qa.models import TestInstance
try:
previous = TestInstance.objects.filter(
unit_test_info__test__slug="dose",
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).latest("work_completed")
except TestInstance.DoesNotExist:
previous = None
deviation = 100.*(previous.value - dose)/dose if previous else 100
Hi Randle,I am having trouble obtaining the previous value. The value I would like to obtain is stored on the HDR unit (unit 6) with the "baseline_kair" macro name in the "microSelectron Calibration" test list. I'm assuming that there must be more to it then just these few lines of code:
from qatrack.qa.models import TestInstancetry:previous = TestInstance.objects.filter(unit_test_info__test__slug="microselectron-calibration",unit_test_info__unit__number=META['unit_number'],test_list_instance__test_list__name=META['test_list_name'],).latest("work_completed")except TestInstance.DoesNotExist:previous = Noneresult = previous.valueWhat am I missing to make this work?Thanks.Matthew
--
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 post to this group, send email to qat...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Would I still use previous.value even if "previous" retrieved a string result?
Matthew
Hi,
Is it possible to look at say the previous 5 (n) values of a test.
For example, for tracking trends (other than looking at the graphs) it may be useful to do some calculations with the previous few results.
Is there a generic way to get the previous nth value of a test?
Possible uses include giving a weekly average/range of results.
Thanks,
Matt
previous5 = TestInstance.objects.filter(
unit_test_info__test__slug="dose",
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).order_by("-work_completed")[:5]
prev_5_vals = [x.value for x in previous5]
prev_5_vals = TestInstance.objects.filter(
unit_test_info__test__slug="dose",
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).order_by("-work_completed").values_list("value", flat=True)[:5]
--
You received this message because you are subscribed to the Google Groups "QATrack+" group.
from qatrack.qa.models import TestInstance
# first find last test list instance where 20MeV was performed
try:
last_20mev = TestInstance.objects.filter(
unit_test_info__test__slug="nominal_energy",
value = 4 # 4 for 20MeV 0,1,2,3 for 6, 9, 12, 16 MeV respectively
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).latest("work_completed")
last_20mev_tli = last_20mev.test_list_instance
except TestInstance.DoesNotExist:
last_20mev_tli = None
# if test list instance exists
if last_20mev_tli:
# you can get a python DateTime object like this:
datetime_completed = last_20mev.work_completed
# and to get dose to water
last_20mev = last_20mev.testinstance_set.get(
unit_test_info__test__slug="dose_to_water"
).value
Good catch! That was just a typo on my part. RT
--
from qatrack.qa.models import TestInstance, Test
test = Test.objects.get(name="Ion Chamber")
choices = test.choices.split(",")
chosen_idx = choices.index(dosemeter)
try:
test_instance = TestInstance.objects.filter(
unit_test_info__test__slug="dosemeter",
value = chosen_idx,
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).latest("work_completed")
last_tli = test_instance.test_list_instance
except TestInstance.DoesNotExist:
last_tli = None
if last_tli:
last_output = last_tli.testinstance_set.get(
unit_test_info__test__slug="dose"
).value
else:
last_output = -1
from qatrack.qa.models import TestInstance
try:
test_instance = TestInstance.objects.filter(
unit_test_info__test__slug="dosemeter",
string_value = dosemeter,
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name=META['test_list_name'],
).latest("work_completed")
last_tli = test_instance.test_list_instance
except TestInstance.DoesNotExist:
last_tli = None
if last_tli:
last_output = last_tli.testinstance_set.get(
unit_test_info__test__slug="dose"
).value
else:
last_output = -1
--
from qatrack.qa.models import TestInstance
try:
previous = TestInstance.objects.filter(
unit_test_info__test__slug="dose", #this is the test slug
unit_test_info__unit__number=META["unit_number"],#this is the unit number.
test_list_instance__test_list__name=META['test_list_name'],#test list name.
).latest("work_completed")
except TestInstance.DoesNotExist:
previous = None
default_value = 0 # can change to whatever value you want in
if previous is not None:
result = previous.value
else:
result = default_value
from qatrack.qa.models import TestInstance
values = TestInstance.objects.filter(
unit_test_info__test__slug="dose", #this is the test slug
unit_test_info__unit__number=META["unit_number"],#this is the unit number.
test_list_instance__test_list__name=META['test_list_name'],#test list name.
).values_list("value", flat=True)
if len(values) > 0:
mean = sum(values)/len(values)
else:
mean = -1 # or something else
# now do your other calculations/comparison
from qatrack.qa.models import TestInstance, Test
test = Test.objects.get(name="Dosemeter")
choices = test.choices.split(",")
chamber_idx = choices.index(dosemeter)
unit_test_slug = "op_dif_6mv"
## gets the test instance containing the last dosemeter
try:
previous_chamber = TestInstance.objects.filter(
unit_test_info__test__slug="dosemeter",
value = chamber_idx,
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name="Outputs",
work_started__lt=META['work_started'],
).latest("work_completed")
last_chamber_tli = previous_chamber.test_list_instance
except TestInstance.DoesNotExist:
last_chamber_tli = None
if last_chamber_tli:
last_chamber = last_chamber_tli.testinstance_set.get(
unit_test_info__test__slug=unit_test_slug
).value
result=(last_chamber/100)+1
from qatrack.qa.models import TestInstance, Test
test = Test.objects.get(name="Dosemeter")
choices = test.choices.split(",")
chamber_idx = choices.index(dosemeter)
unit_test_slug = "op_dif_6mv"
## gets the test instance containing the last dosemeter
try:
previous_chamber = TestInstance.objects.filter(
unit_test_info__test__slug="dosemeter",
value = chamber_idx,
unit_test_info__unit__number=META["unit_number"],
test_list_instance__test_list__name="Outputs",
work_started__lt=META['work_started'],
).exclude(skipped=True).latest("work_completed")
.exclude(value='N/A')
from qatrack.qa.models import TestInstance, Test
test = Test.objects.get(name="Dosemeter")
choices = test.choices.split(",")
chamber_idx = choices.index(dosemeter)
unit_test_slug = "op_dif_6mv"
try:
last_chamber_tli = TestListInstance.objects.filter(
unittestcollection__unit__number=META["unit_number"],
test_list__name="Outputs",
work_started__lt=META['work_started'
],
).filter(
testinstance__unit_test_info__test__slug="dosemeter",
value=chamber_idx,
).filter(
testinstance__unit_test_info__test__slug="output",
value__isnull=False,
).latest("work_completed")
except TestListInstance.DoesNotExist:
last_chamber_tli = None
if last_chamber_tli:
last_chamber = last_chamber_tli.testinstance_set.get(
unit_test_info__test__slug=unit_test_slug
).value
result=(last_chamber/100)+1
Hi Randle,I have been trying to get a previous reading from a different testlist. The testlist could have different energies in it and I want to get the last 6MV energy reading from it.I've got the following, but it doesn't seem to be working. Any ideas why not?
from django.utils import timezonefrom qatrack.qa.models import TestInstancefrom datetime import date# get the latest average reading recorded for this linac on the same day.try:last6MVinstance = TestInstance.objects.filter(unit_test_info__test__slug="energyModality",string_value="6MV"unit_test_info__unit__number=META["unit_number"],test_list_instance__test_list__slug="weeklyPhotonEnergy6mv",).latest("work_completed")last6MV = last6MVinstance.test_list_instanceexcept TestInstance.DoesNotExist:last6MV = Noneif last6MV is None:previousReadingAverage = 0else:if exists.work_completed.date() <> date.today():previousReadingAverage = 0 # default valueelse:previousReadingAverage = last6MV.testinstance_set.get(unit_test_info__test__slug="ReadingAverage").value
--
test = Test.objects.get(name="Dosemeter")
choices = test.choices.split(",")
chamber_idx = choices.index(dosemeter)
test = Test.objects.get(slug="energyModality")
choices = test.choices.split(",")
energy_idx = choices.index("6MV")
--
In that case are you sure it's hitting the DoesntExist exception and it's not the date comparison test that is failing?
RT
--
test_list_instance__test_list__name=META['test_list_name'],
test_list_instance__test_list__slug='some_slug_value',
To unsubscribe from this group and stop receiving emails from it, send an email to qatrack+unsubscribe@googlegroups.com.
from qatrack.qa.models import TestInstance
previous = TestInstance.objects.filter(
unit_test_info__test__slug="op", #this is the test slug
unit_test_info__unit__number=META["unit_number"],#this is the unit number.
test_list_instance__test_list__name="Photon Output Check 6X",#test list name.
).latest("work_started")
I've tried unit_test_info__unit__number = 23, but it doesn't seem to be working. Any ideas?
I seem to be having some difficulty, does unit_test_info__unit__number always have to use the META method? We've started recording ion chamber strontium checks using QATrack+ where each chamber is a different unit. I'd really like to be able to look up the result of a strontium check on a specific ion chamber while performing a linac output measurement. In this case, META['unit_number'] would return the linac's number (6) rather than the ion chamber's number (23).
I've tried unit_test_info__unit__number = 23, but it doesn't seem to be working. Any ideas?
Hi,I think possibly my original question wasn't very clear.From what I can see the work_completed field is not changing, this remains as it was. (The modified/edited are changing as this the results are being edited by the user through adding of a comment during our review process).I'll try and explain my original problem better:On the test list, one of the tests looks up the value of the previous result to perform a comparison to this (using the methods outlines previously in this thread).This works fine on a day to day basis as simply looking up the most recently performed tests result is the one of interest.If however a user goes back to edit (or add a comment) form a few days ago, then this test now pulls the most recent result which won't be the one immediately before the test being edited.I think I just need to work out how to filter to lookup form only results before the work_started date. That way the result being looked up will always be before the test being performed/edited.An example of what I think is happening in my situation:5 days tests are performed in order: Mon, Tue, Wed, Thur, FriThe lookup of the previous value works when initially performing these (e.g. when performing Thur, the value form Wed is looked up correctly).If however on Fri (after all 5 tests have been performed) the user goes back to edit the Wed test, the value looked up as the 'previous' result would be Fridays result, whereas it should still lookup the Tue result.So I assume I need to go and have a look through the Django docs to work out how to filter to only return results prior to the work_started of the test list being performed/edited? That way, if editing the Wed test, only tests before this date would be returned with the filter.Thanks,Matt
from qatrack.qa.models import TestInstance, Test
unit_test_slug = "gulmay_field_size_to_do"
## gets the test instance containing the last set of resultstry: previous_result = TestInstance.objects.filter( unit_test_info__unit__number=META["unit_number"], test_list_instance__test_list__name=META['test_list_name'], work_started__lte=META['work_started'] ##### note this line ).latest("work_completed") last_result_tli = previous_result.test_list_instanceexcept TestInstance.DoesNotExist: last_result_tli = None
if last_result_tli: ## get the value of the last result last_result = last_result_tli.testinstance_set.get( unit_test_info__test__slug=unit_test_slug ).string_valueelse: last_result = 'None'
result = last_result
Hi Randle,
As a reminder I'm doing the following:
from qatrack.qa.models import TestInstance
try:
previous = TestInstance.objects.filter(
unit_test_info__test__slug='slug name',
unit_test_info__unit__number=unit number,
test_list_instance__test_list__name='testlist name',
).latest("work_completed")
except TestInstance.DoesNotExist:
previous = None
result = previous.value
try:
previous = TestInstance.objects.filter(
unit_test_info__test__slug='slug name',
unit_test_info__unit__number=META['unit_number'],
test_list_instance__test_list__name=META['testlist_name'],
work_started__lt=META['work_started']
).latest("work_completed")
result = previous.value
except TestInstance.DoesNotExist:
result = None
previous = UTILS.previous_test_instance("slug name")
result = previous.value if previous else None
--
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.
That works perfectly. Thanks!
Lauren
--
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 unsubscribe from this group and stop receiving emails from it, send an email to qat...@googlegroups.com.
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/d9cdc723-fd8f-4bf5-908b-6ad6ee696b0fn%40googlegroups.com.