0

I'm working on a spotfire script to build up a data table row by row from a data table each time I press a button. At the same time I'm replacing values in the data table. The newly generated table is used as an input for some visualizations. The users should be able to play around with different settings, so they might want to revert some of the transformations done earlier.

I add single rows from a stream like described here: spotfire ironpython : Append new row to a data-table

And I'm replacing specific values in the original data table using: Spotfire ironpython replacing data table values

Is there an ironpythonic way to undo or delete those transformations? Of course I can just add further transformations to delete rows or replace values back to the original value, but In the end I'm getting a long list of "Added rows" and "Deleted rows" transformations in the generated table and a lot of "Replace specific value" transformations in the original data table.

1 Answer 1

0

A while ago I answered a similar question on the Spotfire community. I cannot find the original question, but here's some Iron Python that should help.

Remove replacement operations:

from Spotfire.Dxp.Data.DataOperations import DataSourceOperation
from Spotfire.Dxp.Data.DataOperations import DataOperation
from Spotfire.Dxp.Data.Transformations import *

#tbl is an input parameter of type Data Table.

###---------------------------------------------

sourceView = tbl.GenerateSourceView()
dataOpSupportingTransformations = 
sourceView.OperationsSupportingTransformations;

# Remove entire operation 
# if it only contains ReplaceValuesTransformation or 
# ReplaceSpecificValueTransformation items
replaceValueTransformations= 
  ['ReplaceValuesTransformation','ReplaceSpecificValueTransformation']
for op in dataOpSupportingTransformations:
    op0 = op.DataOperation
    op1 = op0.GetTransformations()
    are_they_replacements = [type(ttt).__name__ in replaceValueTransformations for ttt in op1]
    if all(are_they_replacements)==True and \
            sourceView.CanRemoveOperation(op0):
                sourceView = sourceView.RemoveOperation(op0)

Remove 'remove rows' operations:

from Spotfire.Dxp.Data.DataOperations import DataSourceOperation
from Spotfire.Dxp.Data.DataOperations import DataOperation

#tbl is an input parameter of type Data Table.

## functions
def find_remaining_operations(sv):
    allOps = sv.GetAllOperations[DataOperation]()
    numOps=0
    for op in allOps:
        if type(op).__name__ == "RemoveRowsOperation":
            numOps=numOps+1
    return numOps

###---------------------------------------------
#Remove last RemoweRows operation
sourceView = tbl.GenerateSourceView()

#remove operation is destructive and sourceView is updated after every remove
while find_remaining_operations(sourceView)>0:
    op=sourceView.LastOperation
    if type(op).__name__ == "RemoveRowsOperation" and \
        sourceView.CanRemoveOperation(op):
            sourceView = sourceView.RemoveOperation(op)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply! Regarding replacements: Is it also possible to access the "Identify row by" information so that I can remove only specific replacements?
Regarding deletion of rows: I'd actually like to remove "Added rows" transformations where I added a single row from stream. Therefore I'd have to check which line was written to the stream first and then delete the corresponding "Added rows" transformation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.