spotfire ironpython:撤消添加行/撤消替换值

问题描述 投票:0回答:1

我正在编写一个 Spotfire 脚本,每次按下按钮时都会从数据表中逐行构建数据表。同时我正在替换数据表中的值。新生成的表用作某些可视化的输入。用户应该能够尝试不同的设置,因此他们可能想要恢复之前完成的一些转换。

我从流中添加单行,如下所述:spotfire ironpython:将新行附加到数据表

我正在使用以下方法替换原始数据表中的特定值:Spotfire IronPython 替换数据表值

有没有一种铁蟒式的方法来撤消或删除这些转换?当然,我可以添加进一步的转换来删除行或将值替换回原始值,但最后我得到了一长串“添加的行”生成的表中的“和”已删除的行”转换以及原始数据表中的大量“替换特定值”转换。

ironpython spotfire spotfire-analyst
1个回答
0
投票

不久前我在 Spotfire 社区回答了一个类似的问题。 我找不到原来的问题,但这里有一些 Iron Python 应该有帮助。

删除替换操作:

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)

删除“删除行”操作:

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)
© www.soinside.com 2019 - 2024. All rights reserved.