Revise and Correct
In this section, we will make a change to the Receiving Inspection check sheet so a check that nobody starts is set to Missed 60 minutes after it's added.
We will then correct an already approved check sheet to change one of the check item values.
A manually added check is due as soon as it's added. It should be marked Over Due if nobody starts it within 30 minutes, and Missed 30 minutes after that. You'll change the trigger timers on Receiving Inspection, which means creating a new revision.
- Navigate to Configuration → Quality → Check Sheets
- Change the status of the
Receiving Inspectioncheck sheet fromReleasedtoIn Revision, and open it. - On the Triggers tab, add or edit the
Manualtrigger: Delay0, Coming Due0, Over Due30, Grace30. - Save, close the editor, and set the status back to
Released.
A check you add by hand is Due as soon as it's added: Delay and Coming Due only apply to checks a trigger schedules. With these timers it's Over Due after 30 minutes and Missed after 60.
Revisions apply to any change, including triggers, not only to check items. While a sheet is In Revision, every user, Gateway Admins included, can only start its released version. Checks added after you release the revision use the new version.
Approved Checks can't be edited by accident. To correct a check, it must be rejected first.
- Navigate to Quality → Schedule → Check Table and open the Cleanliness Check you submitted with a failure.
- Use the toggle at the upper right to switch from view to edit mode, then click Reject.
- Change the failed answer, for example from
Over-ClutteredtoPassable. - Resubmit the check and confirm the Check Table now shows it as OK.
A resubmitted check goes back to Approved if its sheet doesn't need a sign-off; otherwise it waits in Submitted for approval. Rejecting and approving needs the Approve Checks security function.
Copy this script into the Ignition Designer Script Console (Tools → Script Console) and run it. It checks that Receiving Inspection is released as a new revision with no revision left open, that its Manual trigger is enabled with Delay 0, Coming Due 0, Over Due 30 and Grace 30, and that an approved Cleanliness Check now has no failures. Each check prints PASS or FAIL with what to fix. It doesn't change anything.
Show the check script
# Kanoa Quality Training - check "Revise and Correct" (Receiving Inspection, lesson 4)
#
# Run in the Ignition Designer Script Console (Tools > Script Console), in the
# project that inherits KANOA_SCRIPTS. It only reads; it changes nothing.
# Every check prints PASS or FAIL with what to fix, then a summary.
SHEET = 'Receiving Inspection'
TIMERS = [('delayMins', 'Delay', 0), ('comingDueMins', 'Coming Due', 0), ('overDueMins', 'Over Due', 30), ('graceMins', 'Grace', 30)]
CLEANLINESS = 'Cleanliness Check'
results = []
def check(ok, what, fix=None):
results.append(bool(ok))
if ok:
print 'PASS %s' % what
else:
print 'FAIL %s' % what
if fix:
print ' -> %s' % fix
def note(what):
print 'NOTE %s' % what
def field(row, *names):
for n in names:
if n in row and row[n] is not None:
return row[n]
return None
def text(v):
return '' if v is None else unicode(v).strip()
def key(v):
return ' '.join(text(v).lower().split())
def truthy(v):
return str(v).lower() in ('true', '1', 'yes')
def num(v):
try:
return float(v)
except:
return None
def rows(data):
# Kanoa returns a dataset, a list of dictionaries, or None
if data is None:
return []
if hasattr(data, 'getRowCount'):
cols = list(data.getColumnNames())
return [dict((c, data.getValueAt(i, c)) for c in cols) for i in range(data.getRowCount())]
return [dict(r) for r in data]
def findSheet(name):
"""All versions of a check sheet, and the one to check: the Released version, or else the newest.
A revision renames the archived version '<name> - N' and the open one '<name> - In Revision',
so the other versions are found by their master sheet, not by name."""
sheets = rows(system.kanoa.quality.sheet.getSheets({}))
named = [s for s in sheets if text(field(s, 'chkShtName')) == name] or \
[s for s in sheets if key(field(s, 'chkShtName')) == key(name)]
if not named:
return None, []
masters = set(text(field(s, 'masterChkShtId', 'chkShtId')) for s in named)
versions = [s for s in sheets if text(field(s, 'masterChkShtId', 'chkShtId')) in masters]
versions.sort(key=lambda s: num(field(s, 'chkShtVersionNumber')) or 0)
released = [s for s in versions if text(field(s, 'chkShtVersionStateName')) == 'Released']
return (released or versions)[-1], versions
def millis(v):
return v.getTime() if hasattr(v, 'getTime') else 0
def sheetEvents(versions):
"""Every check event of any version of the sheet, newest first."""
out = []
for s in versions:
out += rows(system.kanoa.quality.event.getChkShtEvents({'chkShtId': field(s, 'chkShtId')}))
out.sort(key=lambda e: millis(field(e, 'scheduledDate', 'takenDate')), reverse=True)
return out
print '=' * 70
print 'Kanoa Quality Training - Revise and Correct check'
print '=' * 70
# 1. The revision
print '\n-- Revision of %s' % SHEET
sheet, versions = findSheet(SHEET)
if sheet is None:
check(False, 'Check sheet %s exists' % SHEET, 'Build it earlier in this chapter first.')
else:
state = text(field(sheet, 'chkShtVersionStateName'))
version = int(num(field(sheet, 'chkShtVersionNumber')) or 1)
check(state == 'Released', 'It is Released', "It's %s. Set its status back to Released." % (state or 'not set'))
check(version > 1, 'The released sheet is a new revision (version %d)' % version,
'Set the status to In Revision, change the trigger, then set it back to Released.')
open_ = [v for v in versions if text(field(v, 'chkShtVersionStateName')) == 'In Revision']
if open_ and state == 'Released':
check(False, 'No revision is still open',
'A copy is still In Revision. Release it so your trigger change takes effect.')
# 2. The Manual trigger timers
print '\n-- Manual trigger'
triggers = rows(system.kanoa.quality.config.getChkShtTriggers({'chkShtId': field(sheet, 'chkShtId')}))
manual = [t for t in triggers if text(field(t, 'triggerTypeName')) == 'Manual']
if not manual:
check(False, 'It has a Manual trigger', 'On the Triggers tab, add a trigger of type Manual.')
else:
t = manual[0]
check(truthy(field(t, 'enabled')), 'The Manual trigger is enabled', 'Edit the trigger and select Enabled.')
for col, label, expected in TIMERS:
actual = num(field(t, col))
check(actual == expected, '%s is %d minutes' % (label, expected),
"It's %s. Edit the Manual trigger and set %s to %d." % (text(field(t, col)) or 'blank', label, expected))
# 3. The corrected Cleanliness Check
print '\n-- Corrected %s' % CLEANLINESS
cSheet, cVersions = findSheet(CLEANLINESS)
if cSheet is None:
check(False, 'Check sheet %s exists' % CLEANLINESS, 'Build it in the Cleanliness Check chapter first.')
else:
events = sheetEvents(cVersions)
approved = [e for e in events if text(field(e, 'chkShtStateName')) == 'Approved']
clean = [e for e in approved if (num(field(e, 'failedChecks')) or 0) == 0]
check(clean, 'An approved Cleanliness Check now has no failures',
'In Quality > Schedule > Check Table, open the Cleanliness Check with a failure, switch to edit mode, click Reject, '
'change the failed answer to Clean or Passable, and resubmit it.')
stillFailed = [e for e in approved if (num(field(e, 'failedChecks')) or 0) > 0]
if stillFailed:
note('%d approved Cleanliness Check(s) still have a failure. That is fine if you corrected another one.' % len(stillFailed))
waiting = [e for e in events if text(field(e, 'chkShtStateName')) in ('Rejected', 'In Progress')]
if waiting:
note('%d Cleanliness Check(s) are %s. Resubmit a rejected check to finish the correction.'
% (len(waiting), ' or '.join(sorted(set(text(field(e, 'chkShtStateName')) for e in waiting)))))
passed = results.count(True)
print '\n' + '=' * 70
print 'Result: %d of %d checks passed' % (passed, len(results))
if passed == len(results):
print 'All good. The revision is released and the check is corrected.'
else:
print 'Fix the FAIL items above, then run this again.'
print '=' * 70


