Skip to content

Instantly share code, notes, and snippets.

@damiththa
Last active August 22, 2018 14:21
Show Gist options
  • Save damiththa/3806a22f792e0bd3f4f2eb8ce72e39bc to your computer and use it in GitHub Desktop.
Save damiththa/3806a22f792e0bd3f4f2eb8ce72e39bc to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment