简体   繁体   English

如何使用IronPython从Spotfire中的临时文件读取大数据

[英]How to read large data from temp file in Spotfire using IronPython

I need to read large data from temp file in Spotfire using IronPython. 我需要使用IronPython从Spotfire的临时文件中读取大数据。

First I have exported my Tibco data table in a temp file using the Exported text() method: 首先,我已使用Exported text()方法将Tibco数据表导出到临时文件中:

 #Temp file for storing the TablePlot data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

 #Export TablePlot data to the temp file
tp = tablePlotViz.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)

After that, opened the temp file using the open() method. 之后,使用open()方法打开临时文件。

f = open(tempFilename)

Now when I started to read the data from the opened file and write back into a String variable then it is taking too much time. 现在,当我开始从打开的文件中读取数据并写回String变量时,这将花费太多时间。 And my Spotfire screen is stopped working. 并且我的Spotfire屏幕停止工作。

Has anyone idea about this? 有人对此有想法吗?

My data table is of 8MB size. 我的数据表大小为8MB。

Code is: 代码是:

from Spotfire.Dxp.Application.Visuals import TablePlot, HtmlTextArea

import clr
import sys
clr.AddReference('System.Data')
import System
from System.Data import DataSet, DataTable, XmlReadMode
from Spotfire.Dxp.Data import DataType, DataTableSaveSettings
from System.IO import StringReader, StreamReader, StreamWriter, MemoryStream, SeekOrigin, FileStream, FileMode,Path, File
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
from System.Threading import Thread
from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import RowSelection
from Spotfire.Dxp.Data import DataValueCursor
from Spotfire.Dxp.Data import DataSelection
from Spotfire.Dxp.Data import DataPropertyClass
from Spotfire.Dxp.Data import Import

from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings
from System import Array
from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Application.Visuals import TablePlot
from System.IO import Path, StreamWriter
from System.Text import StringBuilder


 #Temp file for storing the TablePlot data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

 #Export TablePlot data to the temp file
tp = tablePlotViz.As[TablePlot]()
writer = StreamWriter(tempFilename)
tp.ExportText(writer)

#Build the table
sb = StringBuilder()

 #Open the temp file for reading
f = open(tempFilename)

#build the html table
html = " <TABLE id='table' style='display:none;'>\n"
html += "<THEAD>"
html += " <TR><TH>"
html += " </TH><TH>".join(f.readline().split("\t")).strip()
html += " </TH></TR>"
html += "</THEAD>\n"
html += "<TBODY>\n"

for line in f:
   html += "<TR><TD>"
   html += "</TD><TD>".join(line.split("\t")).strip()
   html += "</TD></TR>\n"


#Assigned the all HTML data in the text area
print html

The code works fine with short data. 该代码适用于短数据。

If I am getting correctly, the intention behind the code is reading Table Plot visualization data into a string, for further using in a HTML Text Area. 如果我理解正确,则代码的目的是将Table Plot可视化数据读取为字符串,以供在HTML文本区域中进一步使用。 There is an alternative way for doing this, without writing data into temporary file. 有另一种方法可以执行此操作,而无需将数据写入临时文件。 We can use memory stream to export data and convert exported text to string for further reuse. 我们可以使用内存流来导出数据,并将导出的文本转换为字符串以供进一步重用。 The sample code can be referred from here . 示例代码可以从这里参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM