Using the Custom Statistics Editor

The Custom Statistics Editor is used to create and edit custom SPC or DMS statistics you can use in GainSeeker. These are created using Python scripts in GainSeeker.

Creating custom statistics with Python script

 

Contents  [Hide]

 

Accessing the Custom Statistics Editor

The Custom Statistics Editor opens from the New and Edit buttons on the Custom Statistics List window.

Using the Custom Statistics Editor window

Label

Enter a name for the statistic. In the GainSeeker Charts module, this will be the statistic name displayed to the user.

Internal statistics number

GainSeeker automatically assigns a unique ID number to each statistic you create.

Value type

Choose how GainSeeker should format the value of this statistic: String, Number, Percent, Cost, Count, or Other.

If you choose Other, you also need to enter a Custom Format for this statistic. See Numeric Formats and Date/Time Formats.

IronPython Script

Enter a Python script that sets the value of the newstat variable to the desired value.

An easy way to reference the value of another GainSeeker statistic is to place your cursor at the desired location and then double-click that statistic in the Existing statistics list. (To search for a statistic, type any part of its name or ID number in the Search existing box.) This will insert the Python command to get that statistic's value at the current location of your cursor. More GainSeeker Python commands are also available.

To undo your most recent change, click the Undo button.

Script Testing

Click Test to view the result of your IronPython Script and Value Type. Your new statistic will be displayed in the newstat= box as it would appear in the GainSeeker Charts module.

Click Launch Debugger to launch the Python Script debugging tool.

Note: The Test and Launch Debugger buttons use a sample data set to calculate your custom statistic. If you prefer to debug and edit your custom statistic using your own real-world data, follow these steps:

    1. In the GainSeeker Inspections module, use the Manage Python button to create a new Python script (for standalone use).

    2. Add a Retrieval Action to your new script and customize it to retrieve the desired data.

    3. Copy the IronPython Script from your custom statistic (in the System Administration module) and paste it below the Retrieval Action script (in the GainSeeker Inspections module).

    4. Use the tools in the Python Script Editor to debug and/or edit your script until the newstat variable returns the desired value.

    5. Copy the custom statistic code from the new script (in the GainSeeker Inspections module) and paste it into the IronPython Script for your custom statistic (in the System Administration module).

Python Reference, Python Tutorial, and Hertzler Library

Helpful links that open appropriate topics in a web browser or in the GainSeeker Online User Guide.

Script Versions

This grid displays all previously saved versions of the current statistic.

When you double-click a previous version of the statistic listed in the grid, it replaces the current statistic after you hit Save. If you replaced the current version with an earlier version in error, click the Undo button to revert back to the current version.

The number of versions that are saved is determined by the Custom Statistics - Previous script version to retain = setting in the System Administration module.

Example - Custom DMS statistic "Thousands of Defects"

In this example, set the Label, Value Type, and the IronPython Script field as shown. The output shown in this example is 0.733, based on an example "Total Defects" statistic of 733.

Explanation of the script:

This acquires the Total Defects statistic and assigns it to the variable totaldefects:

totaldefects = statdms.getstat(18)

This sets the special variable newStat to the value of totaldefects divided by 1000:

newstat = totaldefects / 1000

Note: newstat must be set to the final desired value of the custom statistic.

Example - Custom SPC statistic "Minutes to failure for 30 minute check"

This example multiplies the Trend Crosses in statistic (the number of subgroups until your process crosses a specification limit) by your cycle time between quality checks to predict the amount of time until failure is detected.

For this example:

#Predict when you will detect your first spec failure at your current frequency of data collection

 

#set how much time between points on control chart, e.g., 30 minutes

time_unit = "minutes"

cycletime = 30 

 

crosses_in_str = statspc.getstat(319) #get the "Trend crosses in" stat

 

if not crosses_in_str[:7] == "Crosses":  #begins with...

    newstat = statspc.getstat(319)  #don't calc - NA or Slope = 0 or already crossed.

 

else:  #statistic returns a string like "Crosses L Specification Limit in 20"

    pos_lastSpace = crosses_in_str.rfind(" ")  #position of last space before the number

    failure_str = crosses_in_str[8:pos_lastSpace - 2]  #extract text for which spec limit gets crossed

    crosses_in_subgroups = int(crosses_in_str[pos_lastSpace + 1:])  #extract the number

 

    minutes_to_detection = crosses_in_subgroups * cycletime  #calculate the amount of time

 

    newstat = "Detect " + failure_str + "Failure in " + str(minutes_to_detection) + " " + time_unit

 

The custom statistic output shown in this example is  Detect U Spec Failure in 840 minutes , based on an example "Trend Crosses in" statistic of  Crosses U Spec in 28 .

If the trend for your data has not yet crossed either specification limit, the Trend Crosses in statistic will return a string like "Crosses U Spec in 28". This script will multiply that number of subgroups (28) by your cycletime (30) and construct a new string that the describes the result ("Detect U Spec Failure in 840 minutes").

If the trend for your data has already crossed a specification limit, or if trend is flat (slope = 0) or otherwise cannot be calculated, the "Trend Crosses in" statistic will not begin with "Crosses..." and so this custom statistic will simply return same value as the "Trend Crosses in" statistic.

Note: newstat must be set to the final desired value of the custom statistic.