Seeq Team John Brezovec Posted June 27 Seeq Team Share Posted June 27 Data Lab and SPy allows the quick generation of Asset Trees within Seeq. Once you get proficient in building trees with SPy, the next question is: how do I get rid of these things? Deleting an Entire Tree The easiest way to do this is to use spy.search() to find all the items contained within your tree, set the Archived column to True, and then push that change as metadata using spy.push(). If I want to delete my asset tree whose root asset has the ID 0EF34B5A-D265-6470-8957-AE797AD00EF5, I can do the following: tree_root_id = '0EF34B5A-D265-6470-8957-AE797AD00EF5' # can be found in the item properties for the root asset items_in_tree = spy.search( [{'Asset': tree_root_id}, {'ID': tree_root_id}], workbook=spy.GLOBALS_AND_ALL_WORKBOOKS, # so I don't have to specify workbook all_properties=True, ) items_in_tree['Archived'] = True # set the items to archived spy.push(metadata=items_in_tree) # push the change back into Seeq Deleting a Section of a Tree Option 1: spy.assets.Tree If you are already using spy.assets.Tree() to create and push your asset trees, you can also use it to remove sections of your trees. If you pull an existing tree, you can then use tree.remove() to remove items by Name, path, wildcard, and spy.search() results (Refer to the documentation for more details). Once your tree is in the state you're happy with, re-push the tree with tree.push() and SPy will archive the removed items: tree = spy.assets.Tree('Cooling Tower 2', workbook='delete example') # pull in an existing tree called 'Cooling Tower 1' from workbook 'delete example' tree.remove('Area F') # remove Area F and its children tree.push() # push the change back to Seeq Option 2: spy.search & spy.push Just like with entire trees, you can search for a collection of items to remove from a tree, set the Archived column to True, and then push the metadata into Seeq. To perform the equivalent removal as Option 1: items_to_archive = spy.search( {"Path": "Cooling Tower 2", "Asset": "Area F"}, workbook="delete section", all_properties=True ) # search for the items we want to remove from our tree items_to_archive['Archived'] = True # set items to archived spy.push(metadata=items_to_archive) # push the change back into Seeq Considerations When using spy.search() and spy.push() to archive items in a tree, make sure to archive both the assets and child items. For instance, in the following tree, if you want to remove Area F from the tree, make sure to also archive the child Compressor Power item. Cooling Tower 2 |-- Area E | |-- Compressor Power | |-- Compressor Stage | |-- Irregular Data | |-- Optimizer | |-- Relative Humidity | |-- Temperature | |-- Wet Bulb |-- Area F <---- if I want to archive this branch... |-- Compressor Power <------ ALSO ARCHIVE THIS ITEM Not following this can leave your trees in inconsistent states and will lead to errors when working with this tree in SPy in the future, such as: - Item's position in tree does not match its path. 1 Link to comment Share on other sites More sharing options...
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