Auto-populate a string but still allow manual entry

24 views
Skip to first unread message

daniel...@hotmail.com

unread,
Jun 13, 2024, 11:33:33 AM (13 days ago) Jun 13
to QATrack+
Hi all
I'm very much a newbie to QAtrack+ and Python coding.

I'm beginning to think what i want to do might not be feasible! 

I'd like to have a test that in some circumstances the user simply types in a string, but that in some specific circumstances will auto-populate with a string already used in a different test list. 

Specifically this relates to some linac QC test lists (lets call them B & C) that will sometimes follow an initial test list (lets call it A) but sometimes would be done as stand alone test lists. 

So if test list A has not been done in that QA session i want the user to type in the dosemeter serial number.  But if test list A has already been done i want the dosemeter serial number for subsequent test lists B & C to be auto-populated with the dosemeter serial number already typed in for test list A.

I have code to find the dosemeter serial number test from most recent instance of test list A and check it was within the last hour but to use this to auto populate the string it needs to be a composite type.  So then i can't leave the string "empty" and allow user input where required. 

Am i missing something? 

Would a way round this be to have all my dosemeters in a dictionary in QAtrack? I was hoping to avoid that if possible as i'm not sure how it would fit with our QART system.

My (probably not very elegant) code is below.

Thanks for any ideas! 

Dan (Sheffield, UK)

# Finds last instance of 6X output readings
elec_serial_recent = UTILS.previous_test_instance(
    "elec_serial",
    # variable can be in different test list to the current one
    same_list_only=False,
    # test list instance with valid variable can be in progress
    include_in_progress=True,
    # does not include instances where the varibale has been skipped
    exclude_skipped=True,
)

# if there is a previous instance returns the date and time the ouput was completed
elec_serial_time = elec_serial_recent.work_completed if elec_serial_recent else None
# set timezone to that returned by the datetime object above
tz = elec_serial_time.tzinfo

# import datetime module
from datetime import datetime

# return the date and time at the point the testlist is started and add a timezone to be same as the elec_serial_time above so they can be operated on together.
# AKA turn a naive datetime into an aware datetime
now_in_tz = datetime.now(tz)

# calculate a timedelta object returning the time between last completed 6X ouput for that machine and the current date and time
time_diff = now_in_tz - elec_serial_time
# convert the timedelate above into seconds
time_diff_in_secs = time_diff.total_seconds()

# if loop to return last instance of electrometer serial number for current machine if within time limit specified.
# or else return zero
if time_diff_in_secs > 3600:
    use_output = "o/p rdgs > 1hr"
else:
    use_output = elec_serial_recent.value

# set current test result to the value set in if loop above (using elec_serial_auto directly in if loop doesn't seem to work?)
if session_op_rdgs_query_6x == "Yes":
    elec_serial_auto = use_output
elif session_op_rdgs_query_6x == "No":
    elec_serial_auto = "Enter #"
else:
    elec_serial_auto = "Answer dropdown"



.  

tbe...@gmail.com

unread,
Jun 17, 2024, 3:13:09 AM (9 days ago) Jun 17
to QATrack+
Hi,

I think what you want should be possible with the "calculation procedure" inside a string test. This evaluates to the default value when a test list is started and can be overridden by user input (or you can just evaluate to None).

For example, we use these two lines to get the current calibration factors which then can be updated from the user if a new calibration has been done (this is a simple numerical test):

previous = UTILS.previous_test_instance("kq100f")
kq100f = previous.value if previous else None

regards
Thomas
Reply all
Reply to author
Forward
0 new messages