Spotfire IronPython脚本:获取交叉表数据

flu*_*lux 2 ironpython spotfire

如何将数据对象输出为文本。

crossTable = markMe.As[CrossTablePlot]()
print crossTable.Data
Run Code Online (Sandbox Code Playgroud)

返回值:

位于0x000000000000002C的Spotfire.Dxp.Application.Visuals.VisualizationData对象[Spotfire.Dxp.Application.Visuals.VisualizationData]

我也尝试过:

for text in crossTable.Data:
    print text
Run Code Online (Sandbox Code Playgroud)

返回错误:

Microsoft.Scripting.ArgumentTypeException:对类型的非序列进行迭代

如何获得绘图数据,以便最终标记其中的项目?

https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/?topic=html/P_Spotfire_Dxp_Application_Visuals_Visualization_Data.htm

cle*_*mo3 5

您的问题是您正在从可视化中获取数据表本身,它不是记录的集合,而是包含行值集合的列的集合。

以下内容将带您到达那里。我使用了一个数据集,其中“ test1”列包含6行,其值包括1到6。

以下代码的总体流程如下:

  1. 从Visual获取数据表
  2. 设置变量
  3. 遍历感兴趣的列以获得行值
  4. 使用一些比较来确定是否应标记该项目。
  5. 标记所有通过我们测试的项目。

码:

from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection

##Get our Data Table from our graph. Data Tables hold marking relations. 
##Visuals just point to a marking set you specify 
##and interact with it in the UI based on their DataTable.
crossTable = markMe.As[CrossTablePlot]()
crossSource = crossTable.Data.DataTableReference

##Get a Row Count
rowCount = crossSource.RowCount

##Index Set of all our rows
allRows = IndexSet(rowCount,True)

##Empty Index Set to fill with our desired markings
rowsToMark = IndexSet(rowCount,False)

##Pick the column we're interested in examining for values.
##You can create multiple cursors to look at multiple columns.
##Specify the name of your column. Mine is called test1.
colCurs = DataValueCursor.CreateFormatted(crossSource.Columns["test1"])

##Optional: Loop through to determine average value
colTotal = 0
for row in crossSource.GetRows(allRows, colCurs):
    colTotal += int(colCurs.CurrentValue)
colAvg = colTotal/rowCount

##loop through our rows and add what we want to our index.
for row in crossSource.GetRows(allRows, colCurs):
    ##Get the index of our current row in the loop
    rowIndex = row.Index

    ##Compare values and if TRUE then we add this row to our index
    ##Instead of hard coding you can refer to a document property
    ##or any other source of data like the average of your column.
    ##Optional: Print our current value to debug
    #if int(colCurs.CurrentValue) > (2.5):
    if int(colCurs.CurrentValue) > colAvg:
        print colCurs.CurrentValue + " was added to the index! =]"
        rowsToMark.AddIndex(rowIndex)
    else:
        print colCurs.CurrentValue + " was not added to the index... =["

##Set our marking equal to our rowsToMark index
Document.ActiveMarkingSelectionReference.SetSelection(RowSelection(rowsToMark),crossSource)
Run Code Online (Sandbox Code Playgroud)

资料来源:

我自己的Spotfire客户端和API知识

http://www.bearonspotfire.com/mark-rows-and-unmark-rows-using-scripts-in-spotfire

bearonspotfire也是编写脚本的好资源。我接受了他所做的工作,并在您的应用程序上做了一些改动。他使用下拉菜单标记项目。

编辑diablo8226的问题:

flux(OP)和我在相同的假设下运行,即markMe作为相关可视化的输入参数包含在内。您也可以通过单击“脚本输入”窗口下方的“添加...”按钮来包括此内容。您可以使用markMe或任何名称。只需确保选择“可视化”作为“类型”,然后选择您的可视化。

或者,您可以输入数据表本身,而跳过获取数据表源的我的代码,或在如下代码中显式调用该表:

coll = Application.GetService[DataManager]().Tables   
crossSource = coll.Item["TABLE_NAME"]
Run Code Online (Sandbox Code Playgroud)

  • @ diablo8226:您要替换数据表以进行初始可视化,对吗?如果是这样,下面的方法应该起作用。可视内容是一种实现可视化类(即,所有可视化的模板),其具有DataTableReference值,您可以使用新数据表设置该值。从Spotfire.Dxp.Application.Visuals导入VisualContent myViz = markMe.As [VisualContent]()myViz.Data.DataTableReference = newTable myViz.AutoConfigure()自动配置将自动填充您拥有的所有列。您可以使用以下API手动设置表格:https://ideone.com/lEy4DI (2认同)