Jump to content

Create a Scalar on an Asset Tree Upload


Go to solution Solved by John Brezovec,

Recommended Posts

Posted

Hello Guys,

Is there any way to create a scalar during an upload of Asset Tree. Looking at Tanks Levels and would like to Create PvHi and PvLo at the same time

Level 6 Name Friendly Name Datasource Name ID Type
A EXP.LI42CPW.P Process Variable     Stored Signal
  Scalar here PVHIHI     LiteralScalar
B EXP.LI44SUMP.P Process Variable     Stored Signal
  Scalar here PVHIHI     LiteralScalar
C DGP.LI30BNK1.P Process Variable     Stored Signal
  Scalar here PVHIHI     LiteralScalar

 

  • Seeq Team
Posted

Hi David, 

You can use the iterrows() function to loop over your DataFrame and add the scalars. 

Let's say I have a DataFrame with all PVHI and PVLO limits: 

image.png

I can apply iterrows() function to add these limits to my asset:

for index, row in csv.iterrows():
    #add Hi/HiHi Limits
    my_csv_tree.insert(name = row['Limits 1 Name'], 
                       formula = str(row['Limits 1']), 
                       parent = row['Level 3'])
    
    #add Lo/LoLo Limits
    my_csv_tree.insert(name = row['Limits 2 Name'], 
                       formula = str(row['Limits 2']), 
                       parent = row['Level 3'])
    
my_csv_tree.visualize()

The asset tree will look like this:

My CSV Tree
|-- Cooling Tower 1
|   |-- Area A
|   |   |-- PVHIHI
|   |   |-- PVLO
|   |   |-- Temperature
|   |-- Area B
|       |-- PVHIHI
|       |-- PVLO
|       |-- Temperature
|-- Cooling Tower 2
    |-- Area D
    |   |-- PVHI
    |   |-- PVLO
    |   |-- Temperature
    |-- Area E
        |-- PVHI
        |-- PVLO
        |-- Temperature

 

  • 1 month later...
  • Seeq Team
  • Solution
Posted

Doing individual insert calls can get pretty slow when working with larger trees. In these cases I'd suggest doing a single insert of all of your limits with a DataFrame.

For this we'll have to reshape the DataFrame Kin How suggested into something that looks like:

image.png

I did that with a little pandas manipulation:

csv["Path"] = csv[["Level 1", "Level 2", "Level 3"]].apply(
    lambda x: ">>".join(x), axis=1
)

df = pd.concat(
    [
        csv[["Path", "Limits 1", "Limits 1 Name"]].rename(
            columns={"Limits 1": "Formula", "Limits 1 Name": "Name"}
        ),
        csv[["Path", "Limits 2", "Limits 2 Name"]].rename(
            columns={"Limits 2": "Formula", "Limits 2 Name": "Name"}
        ),
    ]
)

df["Formula"] = df["Formula"].astype(str)

Note that the Formula column has to be a string so I called astype(str) on it in the last line.

 

At this point I can now do a single call to insert to add all my limits at once:

tree.insert(children=df)

This should give the same results as Kin How's method, but should be more performant when working with larger trees.

  • Thanks 1

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...