David nixon2 Posted August 29, 2023 Posted August 29, 2023 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 Kin How Posted August 29, 2023 Seeq Team Posted August 29, 2023 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: 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
David nixon2 Posted August 29, 2023 Author Posted August 29, 2023 (edited) Works Great! Thanks so much!!! Edited August 29, 2023 by David nixon2
David nixon2 Posted October 19, 2023 Author Posted October 19, 2023 Any way to speed it up, over 2000 assets it is very slow?
Seeq Team Sharlinda Salim Posted October 20, 2023 Seeq Team Posted October 20, 2023 Hi David, Can you clarify which part you are experiencing slowness, is it when pushing the script or when you are doing the analysis in Workbench? If its the analysis, can you please elaborate on the analysis you are doing. You can also book a slot in our Office Hour, https://info.seeq.com/office-hours to discuss further on this issue.
David nixon2 Posted October 20, 2023 Author Posted October 20, 2023 When Running the Script. Each loop takes about 1 Second.
Seeq Team Solution John Brezovec Posted October 20, 2023 Seeq Team Solution Posted October 20, 2023 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: 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. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now