Jump to content

Remove a Specific Transformation via IPython


Mark Pirogowicz

Recommended Posts

I have the following IPython code to add a transformation to replace a specific value, based on user input, running on Spotfire 7.13 HF002:

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Data.Transformations import *

from System.Collections.Generic import List, Dictionary

from Spotfire.Dxp.Data import DataTable

from System.Collections import ArrayList

 

#get a handle on the datatable

table=Document.Data.Tables['WhereOverridesHappen']

tabletmp = Document.Data.Tables['MasterOverride']

 

#set up some cursor to get the keys

cursorKeyColumn = DataValueCursor.CreateFormatted(table.Columns["KeyColumn"])

 

#loop only though a specific marking

markings = Document.Data.Markings["overrideMarking"].GetSelection(tabletmp)

 

#create lists to store values in

markedKeyColumn = []

 

# Iterate through the data table rows to retrieve the marked rows

for row in tabletmp.GetRows(markings.AsIndexSet(),cursorKeyColumn):

value = cursorKeyColumn.CurrentValue

if value str.Empty:

markedKeyColumn.Add(value)

 

# Get only unique values

valKeyColumn = list(set(markedKeyColumn))

 

#Get values from user

overrideValue = Document.Properties['OverrideValue']

 

dataOperation = table.GenerateSourceView().OperationsSupportingTransformations[0];

transformations = dataOperation.GetTransformations();

row_id_cols=[DataColumnSignature("KeyColumn",DataType.String)]

columnForValue = DataColumnSignature("Override Value",DataType.Real);

cursorValue = DataValueCursor.CreateFormatted(table.Columns["Override Value"])

 

#For every month selected

i=0

while i < len(valKeyColumn):

#Get values to establish the key of the table

overrideKey = valKeyColumn

 

#Get existing value based on this key

rowSelection = table.Select('KeyColumn = ' + '"' + overrideKey + '"')

for row in table.GetRows(rowSelection.AsIndexSet(),cursorValue):

rowIndex = row.Index

currentOverrideValue = cursorValue.CurrentValue

break

 

#Replace specific value Transformation for the Value

row_id_col_values = [overrideKey]

transformations.Add(ReplaceSpecificValueTransformation(columnForValue, float(currentOverrideValue), overrideValue, row_id_cols, row_id_col_values, False))

 

i+=1

 

dataOperation.ReplaceTransformations(transformations);That code works fine and creates a ReplaceSpecificValueTransformation. I have the following code to remove all of these transformations which also works fine:

from Spotfire.Dxp.Data import *

from Spotfire.Dxp.Data.Transformations import *

 

table=Document.Data.Tables['MasterOverride']

 

#Replace specific value Transformation

dataOperation = table.GenerateSourceView().OperationsSupportingTransformations[0];

transformations = dataOperation.GetTransformations();

 

#clear all transformations on this dataTable if needed

dataOperation.ReplaceTransformations("")I am looking for code to allow me to remove a single ReplaceSpecificValueTransformation based on some input. I have tried utilizing some code at this link with no success:

https://community.spotfire.com/wiki/how-replace-transformation-datatable-tibco-spotfirer-using-ironpython-scripting

I cannot figure out how to remove a specific transformation in IPython.

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