Jump to content

Adding formula to asset tree in Data Lab


JRan
Go to solution Solved by Dan FR,

Recommended Posts

I am trying to add the following formula via Data Lab into an existing asset tree.

 

Formula:

$deviceComBad = $c ~= "Fault"
$deviceComGood = $c ~= "Normal"
$deviceInOperation = $deviceComBad.union($deviceComGood)
$PIDataUnknown = $deviceInOperation.inverse()


$PIDataUnknownDuration = $PIDataUnknown.setMaximumDuration(40d).aggregate(totalDuration("s"), weeks(Day.Sunday), middleKey(), 0s)

(($PIDataUnknownDuration / 7d) * 100).setUnits('%')

 

Asset tree structure: 

image.png.9914ba7099f1796be8aae561cc4c4245.png

 

This is my data lab entry that keeps failing:

 

my_tree.insert(name='% Availability Weekly',
               formula='$deviceComBad = $c ~= "Fault"',
                        $deviceComGood = $c ~= "Normal"
                        $deviceInOperation = $deviceComBad.union($deviceComGood)
                        $PIDataUnknown = $deviceInOperation.inverse()
                        $PIDataUnknownDuration = $PIDataUnknown.setMaximumDuration(40d).aggregate(totalDuration("s"), weeks(Day.Sunday), middleKey(), 0s)
                        (($PIDataUnknownDuration / 7d) * 100).setUnits('%') 
                    
               formula_parameters={'$c': 'ConnectionStatus'},
               parent='AST-1101')
my_tree.visualize()

 

 

Link to comment
Share on other sites

  • Seeq Team
  • Solution
Posted (edited)

Hi JRan,  

It looks like the issue is with your string quotations in the formula argument, which are only capturing the first line of your formula.  Try using syntax for a multiline formula string with triple quotes:

my_tree.insert(name='% Availability Weekly',
               formula='''$deviceComBad = $c ~= "Fault"
                        $deviceComGood = $c ~= "Normal"
                        $deviceInOperation = $deviceComBad.union($deviceComGood)
                        $PIDataUnknown = $deviceInOperation.inverse()
                        $PIDataUnknownDuration = $PIDataUnknown.setMaximumDuration(40d).aggregate(totalDuration("s"), weeks(Day.Sunday), middleKey(), 0s)
                        (($PIDataUnknownDuration / 7d) * 100).setUnits('%')''',
                    
               formula_parameters={'$c': 'ConnectionStatus'},
               parent='AST-1101')
my_tree.visualize()

Alternatively, it may be cleaner to save your formula string as a variable and then pass this variable into my_tree.insert()

Edited by Dan FR
a comma
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
×
×
  • Create New...