The Retrieval commands in Python can be used for two separate functions:
Some of these commands can retrieve stored data - variable SPC data or attribute DMS data - from the GainSeeker database. You can then use the Python statistics commands to work with individual data values and GainSeeker statistics for the retrieved data.
Some of these commands can build a dataset from external data - such as a database, flat file, etc. - that can be analyzed in GainSeeker charts and dashboards without storing that data in GainSeeker.
Contents [Hide] |
Note: The recommended method of setting options for a basic SPC or DMS retrieval is to use a Set Retrieval SPC or DMS action (rather than writing your own Python code - or using a Custom Code action - with the commands listed below). These recommended Set Retrieval actions are easier to use and help you to avoid coding errors. |
There are 3 basic steps to retrieve data that is stored in GainSeeker:
Specify the DMS or SPC standard - or the DMS process - that you want to analyze:
To retrieve DMS data, use the retrdms commands.
The minimum information needed to retrieve stored data is one DMS process (set by the retrdms.process command) or one DMS part number (set by the retrdms.partno command).
You are limited to one DMS process, one DMS part number, or one combination of DMS process and DMS part number (equivalent to one DMS standard) for the retrieval.
If you specify a DMS process without a DMS part number, data will be retrieved for all part numbers on that process.
If you specify a DMS part number without a DMS process, data will be retrieved for that part number across all processes.
If you specify both a DMS part number and a DMS process, only the data with that combination of part number and process will be retrieved.
To retrieve SPC data, use the retrspc commands.
The minimum information needed to retrieve stored data is an SPC standard, set by the retrspc.partno command. You can only specify one SPC part number for the retrieval.
As with other GainSeeker analysis tools, bypassed data is not included by default.
(optional) Use commands in the table below to set other retrieval settings such as date period, filter, or SPC data count.
Work with the retrieval you have specified above:
(optional) Verify that the retrieval you have specified is valid, using the retrdms.validretrieval or retrspc.validretrieval command.
Retrieve data and statistics for the retrieval, using the Python statistics commands.
(optional) Perform the data retrieval again, using the retrdms.refresh() or retrspc.refresh() command.
Syntax |
Example |
Description/Remarks |
New or changed in GainSeeker version |
||||||||||||||||||||||||||
retrspc.partno = 1000 |
Get/Set the maximum number of data points for retrieving SPC data stored in GainSeeker. Does not apply to external data. |
|
|||||||||||||||||||||||||||
retrspc.filter |
retrdms.filter = "Molding Dept"
retrspc.filter = "UDL3 = 'MOLDING'" retrspc.filter = "UDL3 <> 'MOLDING'" retrspc.filter = "UDL3 Not Like '%MOLDING%' retrspc.filter = "(UDL7 <> 'MOLDING' Or UDL7 Is NULL)" retrspc.filter = "(UDL7 Not Like '%MOLDING%' Or UDL7 Is NULL)" |
Get/Set the filter for retrieving data stored in GainSeeker.:
Does not apply to external data. |
|
||||||||||||||||||||||||||
retrspc.partno |
retrdms.partno = "B-75 INSERT" retrspc.partno = "D-34KW Diameter Z" |
Get/Set the part number for retrieving data stored in GainSeeker. For a DMS retrieval:
Does not apply to external data. |
8.9 |
||||||||||||||||||||||||||
retrdms.process = "M-CUT OFF" |
Get/Set the DMS process for retrieving data stored in GainSeeker. If retrdms.partno is not set, all data for retrdms.process is retrieved. If retrdms.process is not set, all data for retrdms.partno is retrieved. Does not apply to external data. |
8.9 |
|||||||||||||||||||||||||||
retrspc.periodstr |
retrdms.periodstr = '17' Sets the date period for retrieval to 'One month ending today'.
retrspc.periodstr = '36' Sets the date period for retrieval to 'One day ending now'. |
Gets/Sets the date period for retrieving data stored in GainSeeker. The default (None) is the configuration setting for the current user. Other valid options include the numbers below, which must be specified as a string:
To specify a date period not on this list, use the Set Retrieval DMS or SPC actions to set the desired date period. Does not apply to external data. |
|
||||||||||||||||||||||||||
retrspc.refresh() |
retrspc.refresh() |
Force a new retrieval of stored GainSeeker data to get most recent data. Does not apply to external data. |
|
||||||||||||||||||||||||||
retrdms.setretropt(key, value) retrspc.setretropt(key, value) |
retrdms.setretropt("ParetoSort", 6) Sets DMS Pareto analysis to sort Pareto bars by Traceability field #3.
retrdms.setretropt("OEEGroup", "0|-1") Sets DMS OEE analysis to group OEE data by Day with no second level grouping.
retrspc.setretropt("Group", "udl3") Sets SPC control analysis to group data by Traceability field #3. |
Set other Retrieval/Configuration overrides. This is useful for Python dashboard retrievals where you cannot change individual chart settings on the fly. Available options include:
key = "ParetoSort" value is always a number: 0 = Process 1 = Part Number 2 = Defect 3 = Event 4 = Traceability #1 through 51=Traceability #48
key = "DPUGroup" or key = "OEEGroup" value is always a string in the format "#|#" where:
Both numbers (#) can be one of the following: 0 = Day 1 = Week 2 = Month 3 = Quarter 4 = Hour 5 = Day/shift 6 = 5 minutes 7 = 10 minutes 8 = 15 minutes 9 = 20 minutes 10 = 30 minutes 1001 = Traceability #1 through 1048 = Traceability #48 Note: Some combinations do not apply and may cause unexpected results. Use the Chart Settings in the GainSeeker Charts module to verify that a combination will work properly.
key = "Group" value can be either a number or a string: 0 (number) = None 1 (number) = Anchor Point 11 (number) = Year 12 (number) = Month 13 (number) = Day 14 (number) = Hour 20 (number) = Quarter 21 (number) = Week "udl1" through "udl48" (string) = Traceability The equivalent "Group By" setting in the GainSeeker Charts module is this traceability field with the "Sort by traceability field" check box selected. "partno" (string) = SPC standard |
9.1 |
||||||||||||||||||||||||||
retrspc.useexternal |
if retrdms.useexternal == True: print "retrieving external data." |
Gets/Sets whether the retrieval will be loaded with an external dataset or with data stored in GainSeeker. If False (the default), the retrieval is loaded using data stored in GainSeeker. If True, the retrieval is loaded using an external dataset. Executing retrdms.external.addrow() automatically sets retrdms.useexternal = True , and executing retrspc.external.addrow() automatically sets retrspc.useexternal = True |
8.8 |
||||||||||||||||||||||||||
retrspc.validretrieval |
isvalid = retrdms.validretrieval |
If True, the information required for a retrieval is present:
This does not guarantee that data is returned. |
8.9 |
For information on launching scripted external data analysis in the GainSeeker Charts module, see Charting External Data
For information on using a Python script to create a dataset for dashboard analysis, see Retrievals for dashboard controls.
There are a few basic steps to writing a Python script that builds a dataset
for GainSeeker analysis as external data:
In your Python script, use standard Python commands to connect to your external data source and extract the data to analyze in GainSeeker.
While looping through the data in your external data source, use the GainSeeker Python commands below to translate that data into discrete GainSeeker data records. After building each record, add it to the external dataset using the retrdms.external.addrow() or retrspc.external.addrow() command.
When creating the external dataset, there are no separate Python commands to specify a date period, filter, or maximum number of data points. The external dataset created by your Python script should specify only the data you want to analyze.
Example scripts are provided below.
(optional) In your Python script, use the retrdms.setretropt and retrspc.setretropt commands to set data grouping options for the retrieval. This is useful for Python dashboard retrievals where you cannot change individual chart settings on the fly.
(optional) In your Python script, retrieve data and statistics for the external dataset you have built, using the Python statistics commands. This can be especially helpful when testing and debugging your script.
Syntax |
Example |
Description/Remarks |
New or changed in GainSeeker version |
retrdms.external.adddefect("Scratch", 3) |
Adds a defect entry for this record. You can add up to 20 defect entries per record. Each defect entry specifies a brief description of the defect and a count of how many times this defect was found. You can specify a defect description that does not already exist in DMS, unless you are performing cost analysis based on defect cost. (If defect cost is needed, you must specify a defect description that already exists in DMS.) If you save this external dataset in GainSeeker, any defect description that does not already exist in DMS will be added to GainSeeker. |
8.8 |
|
retrdms.external.addrow() |
Stores the fields as a record in the external dataset.
Retrieves information for the first standard and process. Clears the following fields in preparation for the next record to be built:
All other fields and properties for the external dataset are left unchanged (retrdms.external.autosumncu, retrdms.external.datetime, retrdms.external.partno, retrdms.external.process, retrdms.external.samplesize, and retrdms.external.settrace). Sets retrdms.useexternal = True. Resets the statistics for the external dataset to include this record. |
8.8 |
|
retrdms.external.autosumncu |
retrdms.external.autosumncu = True |
If True, executing retrdms.external.adddefect will automatically update the sum of nonconforming units for the record (retrdms.external.ncu) with the count of the new defect being added. The default for this property is determined in configuration settings. |
8.8 |
retrdms.external.clear() |
Clears all records and statistics for the external dataset. |
8.8 |
|
retrdms.external.datetime |
retrdms.external.datetime = "10/30/2017 16:10:32" retrdms.external.datetime = hsidate.dbdatetimestr() |
Gets/Sets
the DateTime field for this record (either in GainSeeker database
format or international format). If not set:
There are three typical strategies for setting DateTimes in the external dataset:
|
8.8 8.9 |
retrdms.external.event |
retrdms.external.event = "Broken" |
Gets/Sets the Event field for this record. Defaults to an empty string. You can specify a DMS Event that does not already exist in GainSeeker. If you save this external dataset in GainSeeker, any DMS Event that does not already exist in GainSeeker will be removed from this data record. Note: The total number of DMS Events - those that already exist in GainSeeker plus new DMS Events in your external dataset - cannot exceed 65. |
8.8, 9.1 |
retrdms.external.ncu |
retrdms.external.ncu = 2 |
Gets/Sets the NCU field (number of NonConforming Units) for this record. Defaults to zero and cannot be greater than the sample size for the record. If retrdms.external.autosumncu is True, do not use this command to manually set the number of nonconforming units. (Manually setting the NCU when autosumncu is True can produce unexpected results.) |
8.8 |
retrdms.external.note |
retrdms.external.note = "Halted 10 minutes for fire drill." |
Gets/Sets the Note field for this record. Defaults to an empty string. |
8.8 |
retrdms.external.partno |
retrdms.external.partno = "Prototype 17" |
Gets/Sets the Part Number field for this record. If left blank, will be set to "External Data". You can specify one or more Part Numbers for the dataset. You can specify a DMS standard (combination of this Part Number and retrdms.external.process) that does not already exist in GainSeeker. If you save this external dataset in GainSeeker and the DMS standard does not exist, GainSeeker will offer to create the standard for you. The first time you use retrdms.external.addrow() to add a record to the external dataset, GainSeeker will retrieve the standard you specify (if it exists). |
8.8 8.9 |
retrdms.external.process |
retrdms.external.process = "Drying" |
Gets/Sets the Process field for this record. If left blank, will be set to "External Data". You can specify one or more Processes for the dataset. You can specify a Process that does not already exist in GainSeeker. If you save this external dataset in GainSeeker and the Process does not exist, GainSeeker will offer to create the DMS standard for you (including the Process). The first time you use retrdms.external.addrow() to add a record to the external dataset, GainSeeker will retrieve the process you specify (if it exists). |
8.8 |
retrdms.external.samplesize |
retrdms.external.samplesize = 25 |
Gets/Sets the Sample Size field for this record. Defaults to zero. There are two typical strategies for setting the Sample Sizes in the external dataset:
|
8.8 |
retrdms.external.settrace(index, value) |
retrdms.external.settrace(4, "Dryer 3") |
Sets a traceability field value for this record. The index specifies which traceability field you are setting and must be an integer from 1 to 48, up to the maximum traceability field defined for the current configuration. (Attempts to set traceability values for indexes higher than the maximum defined for the current configuration will be ignored.) Traceability fields are empty by default. For any one traceability field, there are two typical strategies for setting the traceability values in the external dataset:
|
8.8 9.3 |
#These will be applied
to the entire dataset
retrdms.external.partno = "14861"
retrdms.external.process = "Shipping"
retrdms.external.settrace(1,
"Lot
45173") #Lot
traceability
retrdms.external.samplesize = 10
retrdms.external.autosumncu = False
#Individual records
retrdms.external.datetime = "8/30/2017
07:30:00"
retrdms.external.settrace(2,
"1")
#Shift
traceability, shift 1
retrdms.external.ncu = 2
retrdms.external.adddefect("Wrong
Label", 2)
retrdms.external.adddefect("Postage
Error", 1)
retrdms.external.addrow()
retrdms.external.datetime = "8/30/2017
15:30:00"
retrdms.external.settrace(2,
"2")
#Shift
traceability, shift 2
#no defects or nonconforming units in this
sample
retrdms.external.addrow()
retrdms.external.datetime = "8/30/2017
23:30:00"
retrdms.external.settrace(2,
"3")
#Shift
traceability, shift 3
retrdms.external.ncu = 4
retrdms.external.adddefect("Postage
Error", 4)
retrdms.external.event = "New staff"
retrdms.external.note = "Training new
personnel"
retrdms.external.addrow()
#Debug script to show external dataset
mypartnos = statdms.data.partno()
myprocesses = statdms.data.process()
mylots = statdms.data.trace(1)
mysmplsizes = statdms.data.samplesize()
mydatetimes = statdms.data.datetimedisp()
myshifts = statdms.data.trace(2)
myncus = statdms.data.ncu()
mynumgood = statdms.data.numgood()
mydefect01 = statdms.data.defect(1)
mydefctcount01 = statdms.data.defectcnt(1)
mydefect02 = statdms.data.defect(2)
mydefctcount02 = statdms.data.defectcnt(2)
myevents = statdms.data.eventdms()
Syntax |
Example |
Description/Remarks |
New or changed in GainSeeker version |
retrspc.external.adddata(value) |
retrspc.external.adddata(23.526) |
Sets the measurement value in the next Data field for this record. Also increments the value of the Subgroup Size for this record (see retrspc.external.subgroupsize). Value can be either a number or None (for a measurement that is missing from the subgroup). GainSeeker does not check for real-time failures in external SPC data, but you can perform your own checks and manually flag this record with real-time failure codes. See retrspc.external.rtf . For a different method of setting measurement values for this record, see retrspc.external.setdata . |
8.8 |
retrspc.external.addrow() |
Stores the fields as a record in the external dataset.
Retrieves information for the first standard. Clears the following fields in preparation for the next record to be built:
All other fields and properties for the external dataset are left unchanged (retrspc.external.datetime, retrspc.external.partno, and retrspc.external.settrace). Sets retrspc.useexternal = True. Resets the statistics for the external dataset to include this record. All other fields and properties for the external dataset are left unchanged. |
8.8 |
|
retrspc.external.anchorpoint |
retrspc.external.anchorpoint = True |
Gets/Sets if the record is an anchor point. Defaults to False. Possible values are True or False. |
8.8 |
retrspc.external.clear() |
Clears all records and statistics for the external dataset. |
8.8 |
|
retrspc.external.datetime |
retrspc.external.datetime = "10/30/2017 16:10:32" retrspc.external.datetime = hsidate.dbdatetimestr() |
Gets/Sets
the DateTime field for this record (either in GainSeeker database
format or international format). If not set:
There are three typical strategies for setting DateTimes in the external dataset:
|
8.8 8.9 |
retrspc.external.note |
retrspc.external.note = "Halted 10 minutes for fire drill." |
Gets/Sets the Note field for this record. Defaults to an empty string. |
8.8 |
retrspc.external.partno |
retrspc.external.partno = "Prototype 17" |
Gets/Sets the Part Number field (the name of the SPC standard) for this record. If left blank, will be set to "External Data". You can specify one or more Part Numbers for the dataset. You can specify an SPC standard that does not already exist in GainSeeker. If you save this external dataset in GainSeeker and the SPC standard does not exist, GainSeeker will offer to create the standard for you. The first time you use retrspc.external.addrow() to add a record to the external dataset, GainSeeker will retrieve the standard you specify (if it exists). |
8.8 |
retrspc.external.rtf |
retrspc.external.rtf = 16386 retrspc.external.note = "X-bar below control limit | Range run above mean" Flags this data record with real-time failure codes 2 (X-bar below control limit) and 16384 (Range run above mean), and sets meaningful descriptions of the failures in the note for this record. |
Gets/Sets the real-time failure value for this record. Defaults to zero (no failures). GainSeeker does not check for real-time failures when external data is added, but you can perform your own checks* and manually flag this record with real-time failure codes. For a reference of the failures and their associated code numbers, see Real-time Failure codes. These codes are used when displaying real-time failure colors on the dashboard grid and on the Monitor Table. Please note that flagging a record with real-time failure codes does not automatically set a failure note for the record. If you flag this record with real-time failure codes, you should also add to the failure note using retrspc.external.note :
* As an alternative to programming your own real-time checks, you could use the following strategy to let GainSeeker do this work for you:
|
8.8 |
retrspc.external.setactiontaken(description, shortcode) |
retrspc.external.setactiontaken("Replaced Filter", "RF") |
Sets the Action Taken field for this record. Both arguments default to empty strings. The shortcode is used for display on a Control chart. It must be 1-4 characters long. You can specify an Action Taken that does not already exist in GainSeeker. If you save this external dataset in GainSeeker, any Action Taken that does not already exist in GainSeeker will be removed from this data record. |
8.8 |
retrspc.external.setcause(description, shortcode) |
retrspc.external.setcause("Clogged Filter", "CF") |
Sets the Cause field for this record. Both arguments default to empty strings. The shortcode is used for display on a Control chart. It must be 1-4 characters long. You can specify a Cause that does not already exist in GainSeeker. If you save this external dataset in GainSeeker, any Cause that does not already exist in GainSeeker will be removed from this data record. |
8.8 |
retrspc.external.setdata(index, value) |
retrspc.external.setdata(4, 23.526) Sets the fourth measurement in this subgroup to 23.526 . If Subgroup Size field is less than four, raises it to four. |
Sets the measurement value for the Data field specified by index. Index must be an integer from 1 to 72. It tells GainSeeker which of the Data fields in the subgroup should be filled with the measurement value. If the index is greater than the Subgroup Size for this record (see retrspc.external.subgroupsize), this also raises the Subgroup Size. Data fields are empty by default. Value can be either a number or None (for a measurement that is missing from the subgroup). GainSeeker does not check for real-time failures in external SPC data, but you can perform your own checks and manually flag this record with real-time failure codes. See retrspc.external.rtf . For a different method of setting measurement values for this record, see retrspc.external.adddata . |
8.8 |
retrspc.external.setevent(description, shortcode) |
retrspc.external.setevent("Insufficient Oxygen", "O2") |
Sets the Event field for this record. Both arguments default to empty strings. The shortcode is used for display on a Control chart. It must be 1-4 characters long. You can specify an Event that does not already exist in GainSeeker. If you save this external dataset in GainSeeker, any Event that does not already exist in GainSeeker will be removed from this data record. |
8.8 |
retrspc.external.settrace(index, value) |
retrspc.external.settrace(4, "Dryer 3") |
Sets a traceability field value for this record. The index specifies which traceability field you are setting and must be an integer from 1 to 48, up to the maximum traceability field defined for the current configuration. (Attempts to set traceability values for indexes higher than the maximum defined for the current configuration will be ignored.) Traceability fields are empty by default. For any one traceability field, there are two typical strategies for setting the traceability values in the external dataset:
|
8.8 9.3 |
retrspc.external.subgroupsize |
mysubsize = retrspc.external.subgroupsize |
Gets the Subgroup Size of this record. The Subgroup Size is incremented automatically when adding data values with retrspc.external.adddata or retrspc.external.setdata . |
8.8 |
#These will be applied
to the entire dataset
retrspc.external.partno = "14861
weight"
retrspc.external.settrace(1,
"Lot
45173") #Lot
traceability
#Individual records
retrspc.external.datetime = "8/30/2017
07:30:00"
retrspc.external.settrace(2,
"1")
#Shift
traceability, shift 1
retrspc.external.adddata(13.17)
#use
adddata command
retrspc.external.adddata(13.16)
retrspc.external.adddata(13.21)
retrspc.external.addrow()
retrspc.external.datetime = "8/30/2017
15:30:00"
retrspc.external.settrace(2,
"2")
#Shift
traceability, shift 2
retrspc.external.setdata(1,
13.15)
#use
setdata command
retrspc.external.setdata(2,
13.13)
retrspc.external.setdata(3,
13.22)
retrspc.external.setevent("Power
Outage", "PWR")
retrspc.external.addrow()
retrspc.external.datetime = "8/30/2017
23:30:00"
retrspc.external.settrace(2,
"3")
#Shift
traceability, shift 3
retrspc.external.setdata(1,
13.29)
retrspc.external.setdata(2,
13.75)
retrspc.external.setdata(3,
13.24)
retrspc.external.rtf = 1024
retrspc.external.note = "Sample #2
violates Upper spec limit"
retrspc.external.addrow()
retrspc.external.datetime = "8/31/2017
07:30:00"
retrspc.external.settrace(2,
"1")
#Shift
traceability, shift 1
retrspc.external.setdata(1,
13.27)
retrspc.external.setdata(3,
13.24)
retrspc.external.note = "Sample #2
removed from lab before weight checks could be performed."
retrspc.external.addrow()
#Debug script to show external dataset
mypartnos = statspc.data.partno()
mylots = statspc.data.trace(1)
mydatetimes = statspc.data.datetimedisp()
myshifts = statspc.data.trace(2)
mydata = statspc.data.datapts()
myevents = statspc.data.eventspc()
myrtfs = statspc.data.rtfstr()