Jump to content

Push Scorecard from Seeq Data Lab


Emily Johnston
 Share

Recommended Posts

  • Seeq Team

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
Link to comment
Share on other sites

  • 7 months later...
  • Seeq Team

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
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...