【问题标题】:Spotfire IronPython script: get Cross Table dataSpotfire IronPython 脚本:获取交叉表数据
【发布时间】:2015-04-22 23:20:27
【问题描述】:

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

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

返回:

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

我也试过了:

for text in crossTable.Data:
    print text

返回错误:

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

【问题讨论】:

    标签: ironpython spotfire


    【解决方案1】:

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

    下面的内容应该可以帮助您到达那里。我使用了一个数据集,其中“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)
    

    来源:

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

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

    bearonspotfire 也是一个很好的脚本资源。我接受了他所做的,并为你的申请做了一些改动。他使用下拉菜单来标记项目。

    编辑 diablo8226 的问题:

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

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

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

    【讨论】:

    • 谢谢。您帮助我了解了可视化、其基础数据表和标记之间的动态。我想我会保留大部分代码。除了代替平均计算,我正在重新创建交叉表单元格值自定义表达式,它基于 2 列计算百分比。恭喜,很高兴在 StackOverflow 上为您提供第一个被接受的答案;)
    • @clesiemo3:谢谢你的回答。当我尝试实现您的代码时,我面临以下错误Microsoft.Scripting.Runtime.UnboundNameException: name 'markMe' is not defined at IronPython.Runtime.PythonContext.MissingName(SymbolId name) 我是 Ironpython 的新手。你能帮帮我吗?谢谢
    • @diablo8226:flux 和我运行的假设相同,即 markMe 包含在相关可视化的输入参数中。我猜你没有这个输入参数集。您也可以通过单击脚本输入窗口下方的“添加...”按钮来包含它。您可以使用 markMe 或任何名称。只需确保选择 Visualization 作为 Type 并选择您的可视化。或者,您可以输入您的数据表本身并跳过我获取数据表源的代码或在代码中显式调用该表(请参阅下一条评论)
    • @diablo8226 :使用下面你可以明确地抓住你的桌子。它消除了您使用输入参数的需要,但是如果您的表名发生更改,您的代码将中断,而上述参数仍将指向该表。 coll = Application.GetService[DataManager]().TablescrossSource = coll.Item["TABLE_NAME"]
    • @diablo8226 :您正在寻找替换初始可视化的数据表,对吗?如果是这样,以下应该工作。 Visual Content 是一个实现可视化类(即所有视觉对象的模板),它具有可以使用新数据表设置的 DataTableReference 值。 from Spotfire.Dxp.Application.Visuals import VisualContent myViz = markMe.As[VisualContent]() myViz.Data.DataTableReference = newTable myViz.AutoConfigure() Autoconfigure 将自动填充您拥有的所有列。您可以使用 API 手动设置表:ideone.com/lEy4DI
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多