Imagine you have the following dict.
dictIs = { 'key1' : [50, 'qcCheck'],
'key2' : [80, 'qcCheck'],
'key3' : [20, 'qcCheck'],
'key4' : [10, 'qcCheck'],
'key5' : [90, 'qcCheck'],
'key6' : [30, 'qcCheck'] }
and you are trying to do do a QC
check as follows,
If value of key2 – key1
is < 10 or > 20
, then QC
for value for both key1
and key2
should be set to FAILED
; otherwise, set to PASSED
.
However, if value of key3 – key2
is < 10 or > 20
, then QC
for value for both key2
and key3
should be set to FAILED
; otherwise, set to PASSED
.
and on and on...
The caveat here is that if the QC
is set to FAILED
in one condition check, it should not be set back to PASSED
in a subsequent condition check
i.e., if value of key2
, FAILED
the first condition check but PASSED
the second condition check, it should remain as FAILED
.
Here's what've got,
dictIs = {
'key1' : [50, 'qcCheck'], 'key2' : [80, 'qcCheck'], 'key3' : [20, 'qcCheck'], 'key4' : [10, 'qcCheck'], 'key5' : [90, 'qcCheck'], 'key6' : [30, 'qcCheck']
}
for s in range(1,6) :
t = s + 1
qcIs = 'pass' # default value
diffIs = dictIs['key' + str(t)][0] - dictIs['key' + str(s)][0]
if ( diffIs < 20 ) or ( diffIs > 30 ) :
qcIs = 'fail'
dictIs['key' + str(s)].append(qcIs)
dictIs['key' + str(t)].append(qcIs)
# print dictIs
for u,v in dictIs.items():
if len(v) < 4 : # adding a 'null_value' so we know all value lists are the same length (i.e. 4 list items)
dictIs[u].append('null_value')
if 'fail' in v :
setValue = 'FAILED'
else:
setValue = 'PASSED'
v = v[:-2] # removing last two elements
v.append(setValue) # append w/ setValue
dictIs[u] = v # back into to the dict. replacing original key-value w/ the new key-value
# print dictIs
And now the dictIs
,
{'key3': [20, 'qcCheck', 'FAILED'], 'key2': [80, 'qcCheck', 'FAILED'], 'key1': [50, 'qcCheck', 'PASSED'], 'key6': [30, 'qcCheck', 'FAILED'], 'key5': [90, 'qcCheck', 'FAILED'], 'key4': [10, 'qcCheck',
'FAILED']}
Which now you can easily get the QC
status, simply by passing in the dictIs
key
and the value
position.
I.e.
print dictIs['key3'][2]
will output FAILED
.