Jump to content

Recommended Posts

  • Seeq Team
Posted

The SPy Documentation for spy.assets includes an example of specifying metrics as attributes in asset classes. It is also possible to push scorecard metrics using the spy.push functionality by defining the appropriate metadata. An example of this process is given in the code snippets below:

#import relevant libraries
import pandas as pd
from seeq import spy

Log in to the SPY module if running locally using spy.login, or skip this step if running Seeq Data Lab.

#Search for data that will be used to create the scorecard. This example will search the Example asset tree to find tags in Area A.
search_result = spy.search({'Path': 'Example >> Cooling Tower 1 >> Area A'})

The next code segment creates and pushes a signal that will be used as a threshold limit in the scorecard metric. This can be skipped if threshold signals will not be used in the final metric.

#Define data frame for low limit threshold signal.
my_lo_signal = {
    'Type': 'Signal',
    'Name': 'Lo Signal',
    'Formula': '$signal * 50',
    'Formula Parameters': {'$signal': search_result[search_result['Name'] == 'Optimizer']['ID'].iloc[0]}
}

#Push data frame for low limit threshold signal.
lo_push_result = spy.push(metadata=pd.DataFrame([my_lo_signal]), workbook='Example Scorecard')

Finally, create the and push the scorecard metric. This example metric measures the average temperature and apply a static high limit threshold of 90 and a moving low limit threshold using the signal defined above.

#Define data frame for scorecard metric.
my_metric_input = {
    'Type': 'Metric',
    'Name': 'My Metric',
    'Measured Item': {'ID': search_result[search_result['Name'] == 'Temperature']['ID'].iloc[0]},
    'Statistic': 'Average',
    'Thresholds': {
        'Lo': {'ID': lo_push_result['ID'].iloc[0]},
        'Hi': 90
    }
}

#Push data frame for scorecard metric.
spy.push(metadata = pd.DataFrame([my_metric_input]), workbook='Example Scorecard')

The final result can be seen in the created workbook.

image.png

  • Like 3
  • Thanks 2
  • 7 months later...
Posted

As an add on to this topic, there can be times when one wants to push a different scorecard type. The previous example shows how to create a Simple Scorecard but similar logic can be applied to make a Condition and Continuous Scorecard. 

Condition Scorecard

Since the Condition Scorecard is also based on a condition, we need to retrieve the condition to be used. This can be done using spy.search again

search_result_condition = spy.search({"Name":"Stage 2 Operation", "Scoped To":"C43E5ADB-ABED-48DC-A769-F3A97961A829"})

From there we can tweak the scorecard code to include the bounding condition. This is the condition over which this calculation is performed in scorecard. Note scorecard requires conditions with maximum capsule duration, so an additional parameter is required if the condition does not have a maximum capsule duration. Below is the code as well as the result

my_metric_input_condition = {
    'Type': 'Metric',
    'Name': 'My Metric Condition',
    'Measured Item': {'ID': search_result[search_result['Name'] == 'Temperature']['ID'].iloc[0]},
    'Statistic': 'Average',
    'Bounding Condition': {'ID': search_result_condition[search_result_condition['Name'] == 'Stage 2 Operation']['ID'].iloc[0]},
    'Bounding Condition Maximum Duration': '30h' # Required for conditions without a maximum capsule duration
}

spy.push(metadata = pd.DataFrame([my_metric_input_condition]), workbook='Example Scorecard')

image.png

Continuous Scorecard

For Continuous Scorecards, users need to specify the rolling window over which to perform the calculations. To do this, a Duration and Period need to be provided. The Duration tells how long is the rolling window and the Period tells the frequency at which the rolling window is performed.

my_metric_input_continuous = {
    'Type': 'Metric',
    'Name': 'My Metric Continuous',
    'Measured Item': {'ID': search_result[search_result['Name'] == 'Temperature']['ID'].iloc[0]},
    'Statistic': 'Average',
    'Duration': '1d', # Length of time the calculation is done for
    'Period': '3d', # How often is the calculation being performed
}

spy.push(metadata = pd.DataFrame([my_metric_input_continuous]), workbook='Example Scorecard')

image.png

 

  • Like 1
  • 1 year later...
Posted

Is there a detailed documentation for the available key words arguments to pick for the Metric attribute properties. For example, it was not straight forward to know which keyword to pick for getting the Statistic =  Value at End (the AggregationFunction was called differently 'endValue'

In other words, Can we assume all the attribute properties will have the same name as the GUI drop down menu list items ?

Please see some screenshots attached to illustrate the quesiton: 

image.png.020cfae01866e7d21f0074eda774a0c6.pngimage.png.054a1c4f7c75664da014b416819b7949.png

Posted

Correct the statistic will mirror what's seen in the GUI. To find out which ones are available, I ran the code mentioned above with an incorrect statistic and SPy returned an error with the possible options. Note that just like in the GUI only certain stats can be used for signals and condition Measured Items. 

image.png

  • 1 year later...
Posted

I've successfully created a scorecard metric in DataLab and pushed it to my workbook.  Now, I'd like to set custom colors for the zones between the thresholds and cannot figure out how to do so.  Can you provide information on how to do this? 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...