Spotfire IronPython 脚本:获取 Cross Table 数据

Spotfire IronPython script: get Cross Table data

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

crossTable = markMe.As[CrossTablePlot]()
print crossTable.Data

Returns:

Spotfire.Dxp.Application.Visuals.VisualizationData object at 0x000000000000002C [Spotfire.Dxp.Application.Visuals.VisualizationData]

我也试过:

for text in crossTable.Data:
    print text

其中returns一个错误:

Microsoft.Scripting.ArgumentTypeException: iteration over non-sequence of type

如何获取绘图数据以便最终在其中标记项目?

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

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

下面应该可以帮助您。我使用了一个数据集,其中列 "test1" 包含 6 行,值从 1 到 6(含)。

下面代码的整体流程如下:

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

代码:

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)

来源:

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

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

bearonspotfire 也是一个不错的脚本资源。我借鉴了他所做的,并为您的申请做了一些改动。他使用下拉菜单来标记项目。

编辑 diablo8226 的问题:

flux (OP) 和我 运行 都基于同样的假设,即 markMe 被包含为相关可视化的输入参数。您也可以通过单击脚本输入 window 下方的 "Add..." 按钮来包含它。您可以使用 markMe 或任何名称。只需确保您 select 可视化作为类型并且 select 您的可视化。

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

coll = Application.GetService[DataManager]().Tables   
crossSource = coll.Item["TABLE_NAME"]