Skip to main content

Automatic Checks on a Timer

An Auto check sheet completes itself. Kanoa creates the check, reads every item's value from its attribute's data source, and submits it, with nobody involved. That only works if every required item has an attribute with an enabled data source for the check's asset, so the sheet must also require an asset.

Create the auto check sheet
  1. In Configuration → Quality → Check Sheets, add Coating SPC Checks in the CoreForge\Operations folder.

  2. On the Settings tab, select Auto and Asset Required, and choose CoreForge\Philadelphia\Coating\Spray Line 1.

  3. On the Checks tab, add three items, each Type Check, Data Type Float, Enabled and Required:

    Check itemAttributeUnits
    Coating ThicknessCoreForge\Coating\Thicknessµm
    Flow RateCoreForge\Coating\Flow Rategpm
    Line SpeedCoreForge\Coating\Line Speedfpm

    If a unit isn't in the list, type it into the Units field to create it.

  4. On the Triggers tab, add a Timed Interval trigger with an interval of 5 minutes. Leave the other timers at 0; an automatic check completes immediately, so it never becomes due or late.

  5. Save, release, and let it run for at least an hour so there's data to analyze.

Reference Materials: Trigger Types

Trigger Types​

  • Manual: A check sheet can be manually created without this trigger, however if manual trigger is created, it will specify how much time a user has to take the checks once it has been scheduled.

  • Mode Change: When the mode changes on an asset i.e. from Changeover to Production, this trigger will schedule a check sheet if it meets the specified mode/shift, other options. An optional From Mode limits it to a change from that mode, so a check sheet can run on Changeover to Production but not on Maintenance to Production.

  • Product Change: When the product changes on an asset, this check sheet will be scheduled if the currently running product is specified by the check sheet.

    • Every Product: Quality check is required every time the product changes
    • Unique Products Per Shift: Quality check is required only once per product per shift
    • Once Per Shift: Only one quality check will be performed per shift
  • Re-Test: Set the delay, coming due etc. when a check sheet is scheduled due to a re-test being required.

  • Shift Change: Check sheet will be scheduled if the current shift meets the shift settings of this trigger.

  • Timed Interval: This check sheet will be triggered periodically based on the mode and shift settings.

  • Recurring: The check sheet is scheduled on a repeating calendar rule (every weekday at 6:00, the first Monday of the month, ...). Times are in the asset's site time zone, so 6:00 stays 6:00 at the plant across daylight-saving changes, whatever time zone the gateway runs in.

  • State Change: The check sheet is scheduled when an asset has been in one of the chosen states for at least the minimum time (For at least n mins), for example a check after a line has been Blocked for 10 minutes. It's scheduled once each time the asset goes into the state, so a short stop that clears before the minimum time doesn't trigger a check.

  • Infeed Count, Outfeed Count, Waste Count: The check sheet is scheduled every n counts of the asset's infeed, outfeed or waste counter.

  • General Count: The same, for one of the asset's general counters, by its name.

    For the count triggers, the count starts when the trigger is added and never resets: it carries on across product and shift changes, and what's left over after each n counts toward the next. When n counts are reached while a check sheet is still open, that check is skipped. Counts made while the check sheet doesn't apply (another shift, product, mode or tool than its settings) aren't counted.

State Change and the count triggers are checked by the quality timer, so a check sheet is scheduled within one timer interval of the state's minimum time or the count being reached.

Note If a trigger causes a new check sheet to be scheduled when there is already an existing check sheet scheduled, it will set the current check sheet to aborted if it has not already been started and create the new check sheet.

Timed checks not appearing?

Timed interval triggers are fired by the Quality Schedule gateway timer, which calls intervalTimerEvent every minute by default. Check that its status is Running on the Timers tab of the Kanoa gateway config page (Kanoa > Settings), then check that the sheet is released, the trigger is enabled, and the attribute data sources are enabled for Spray Line 1.

Check your work

Copy this script into the Ignition Designer Script Console (Tools → Script Console) and run it. It checks that Coating SPC Checks is a released Auto sheet on Spray Line 1, that its items read the Coating attributes, and that its Timed Interval trigger is enabled at 5 minutes. It also checks that a check was taken in the last 10 minutes, that the Quality Schedule timer is running, that there's an hour of approved checks to analyze, and that the latest one has all three values. Each check prints PASS or FAIL with what to fix. It doesn't change anything.

Show the check script
checkLesson-coatingAutoChecks.py
# Kanoa Quality Training - check "Automatic Checks on a Timer" (Coating Line SPC, lesson 2)
#
# 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 = 'Coating SPC Checks'
FOLDER = 'CoreForge\\Operations'
ASSET = 'CoreForge\\Philadelphia\\Coating\\Spray Line 1'
ITEMS = [
# name, attribute, units
# micro sign, Greek mu, or plain um; escaped so the script is plain ASCII and pastes cleanly anywhere
('Coating Thickness', 'CoreForge\\Coating\\Thickness', [u'\u00b5m', u'\u03bcm', 'um']),
('Flow Rate', 'CoreForge\\Coating\\Flow Rate', ['gpm']),
('Line Speed', 'CoreForge\\Coating\\Line Speed', ['fpm']),
]
INTERVAL = 5
TIMER = 'qualitySchedule' # the Quality Schedule gateway timer, which fires Timed Interval triggers
HOUR_OF_CHECKS = 60 / INTERVAL

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 findItem(items, name):
exact = [i for i in items if text(field(i, 'chkItemName')) == name]
close = [i for i in items if key(field(i, 'chkItemName')) == key(name)]
return (exact or close or [None])[0]

def millis(v):
return v.getTime() if hasattr(v, 'getTime') else 0

def sheetEvents(versions, start, end):
"""The sheet's check events between two dates, newest first."""
out = []
for s in versions:
out += rows(system.kanoa.quality.event.getChkShtEvents({'chkShtId': field(s, 'chkShtId'), 'startDate': start, 'endDate': end}))
out.sort(key=lambda e: millis(field(e, 'scheduledDate', 'takenDate')), reverse=True)
return out

def eventItems(event):
"""The recorded values of a check event, by check item name."""
byName = {}
for r in rows(system.kanoa.quality.event.getChkShtEventItems({'chkShtEventId': field(event, 'chkShtEventId')})):
byName.setdefault(text(field(r, 'chkItemName')), []).append(r)
return byName

print '=' * 70
print 'Kanoa Quality Training - Automatic Checks on a Timer check'
print '=' * 70

sheet, versions = findSheet(SHEET)
if sheet is None:
check(False, 'Check sheet %s exists' % SHEET,
'In Configuration > Quality > Check Sheets, add %s in the %s folder.' % (SHEET, FOLDER))
else:
# 1. The check sheet and its settings
print '\n-- Check sheet'
actual = text(field(sheet, 'chkShtName'))
check(actual == SHEET, 'Check sheet %s exists' % SHEET, "Found '%s'. Rename it to %s." % (actual, SHEET))
folder = text(field(sheet, 'chkShtTypePath'))
check(folder == FOLDER, 'It is in the %s folder' % FOLDER,
"It's in '%s'. On the Settings tab, set the folder to %s." % (folder or 'no folder', FOLDER))
check(truthy(field(sheet, 'auto')), 'Auto is selected', 'On the Settings tab, select Auto.')
check(truthy(field(sheet, 'assetReqd')), 'Asset Required is selected', 'On the Settings tab, select Asset Required.')
assets = [text(field(r, 'assetPath')) for r in rows(system.kanoa.quality.sheet.getAssets(field(sheet, 'chkShtId')))]
check(ASSET in assets, 'Its asset is Spray Line 1',
'Under Asset Required, choose %s.%s' % (ASSET, (' Now: %s.' % ', '.join(assets)) if assets else ''))
state = text(field(sheet, 'chkShtVersionStateName'))
check(state == 'Released', 'It is Released', "It's %s. Close the editor and change its status to Released." % (state or 'not set'))

# 2. Check items
print '\n-- Check items'
items = rows(system.kanoa.quality.config.getChecks({'chkShtId': field(sheet, 'chkShtId')}))
for name, attribute, units in ITEMS:
item = findItem(items, name)
if item is None:
check(False, '%s exists' % name, 'On the Checks tab, add a check item named %s.' % name)
continue
problems = []
actual = text(field(item, 'chkItemName'))
if actual != name:
problems.append("rename '%s' to %s" % (actual, name))
if text(field(item, 'chkItemTypeName')) != 'Check':
problems.append('set Type to Check')
if text(field(item, 'dataTypeName')) != 'Float':
problems.append("set Data Type to Float (it's %s)" % (text(field(item, 'dataTypeName')) or 'blank'))
if not truthy(field(item, 'enabled')):
problems.append('select Enabled')
if not truthy(field(item, 'required')):
problems.append('select Required')
if text(field(item, 'attributePath')) != attribute:
problems.append("assign the attribute %s (it's %s)" % (attribute, text(field(item, 'attributePath')) or 'none'))
if text(field(item, 'engUnitName')).lower() not in [u.lower() for u in units]:
problems.append("set Units to %s (it's %s)" % (units[0], text(field(item, 'engUnitName')) or 'blank'))
check(not problems, '%s reads %s' % (name, attribute), '; '.join(problems).capitalize() + '.')

# 3. The timed trigger
print '\n-- Timed Interval trigger'
triggers = [t for t in rows(system.kanoa.quality.config.getChkShtTriggers({'chkShtId': field(sheet, 'chkShtId')}))
if text(field(t, 'triggerTypeName')) == 'Timed Interval']
if not triggers:
check(False, 'It has a Timed Interval trigger', 'On the Triggers tab, add a Timed Interval trigger with an interval of %d minutes.' % INTERVAL)
else:
t = triggers[0]
check(num(field(t, 'intervalMins')) == INTERVAL, 'The interval is %d minutes' % INTERVAL,
"It's %s. Edit the trigger and set the interval to %d." % (text(field(t, 'intervalMins')) or 'blank', INTERVAL))
check(truthy(field(t, 'enabled')), 'The trigger is enabled', 'Edit the trigger and select Enabled.')

# 4. Checks taken automatically
print '\n-- Automatic checks'
now = system.date.now()
events = sheetEvents(versions, system.date.addHours(now, -24), now)
recent = [e for e in events if millis(field(e, 'scheduledDate', 'takenDate')) >= millis(system.date.addMinutes(now, -2 * INTERVAL))]
check(recent, 'A check was taken in the last %d minutes' % (2 * INTERVAL),
'No recent checks. Check the sheet is released, the trigger and the data sources are enabled, '
'and that the Quality Schedule timer is Running on the Timers tab of the Kanoa gateway config page (Kanoa > Settings).')
try:
jobs = [j for j in rows(system.kanoa.config.getJobs()) if text(field(j, 'jobName')) == TIMER]
except:
jobs = None
if jobs is None:
note("Couldn't read the gateway timers (system.kanoa.config.getJobs). Check the Timers tab of the Kanoa gateway config page.")
else:
status = text(field(jobs[0], 'status')) if jobs else 'not found'
check(jobs and truthy(field(jobs[0], 'enabled')) and not status, 'The Quality Schedule gateway timer is running',
"It's %s. On the Timers tab of the Kanoa gateway config page (Kanoa > Settings), switch Quality Schedule on; "
'Kanoa Quality must be licensed (or in trial) and turned on in the app settings.' % status)
done = [e for e in events if text(field(e, 'chkShtStateName')) == 'Approved']
check(len(done) >= HOUR_OF_CHECKS, 'At least an hour of checks to analyze (%d approved in the last 24 hours)' % len(done),
'Let it run for at least an hour (%d checks) before the next lesson.' % HOUR_OF_CHECKS)
if done:
byName = eventItems(done[0])
empty = [n for n, a, u in ITEMS if not [r for r in byName.get(n, []) if text(field(r, 'chkItemValue'))]]
check(not empty, 'The latest check has a value for all three items',
'No value for %s. Check that attribute has an enabled data source on Spray Line 1.' % ', '.join(empty))
stuck = [e for e in events if text(field(e, 'chkShtStateName')) not in ('Approved', 'Submitted')]
if stuck:
note('%d check(s) in the last 24 hours were not completed automatically (%s). An auto check needs a value for every required item.'
% (len(stuck), ', '.join(sorted(set(text(field(e, 'chkShtStateName')) for e in stuck)))))

passed = results.count(True)
print '\n' + '=' * 70
print 'Result: %d of %d checks passed' % (passed, len(results))
if passed == len(results):
print 'All good. Coating SPC Checks is collecting data.'
else:
print 'Fix the FAIL items above, then run this again.'
print '=' * 70
Finished check sheet

check-sheet-coating-spc-checks.json: the finished Coating SPC Checks, including its attributes and data sources, to compare with your build.