簡體   English   中英

如何使用IronPython從Spotfire中的臨時文件讀取大數據

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

我需要使用IronPython從Spotfire的臨時文件中讀取大數據。

首先,我已使用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)

之后,使用open()方法打開臨時文件。

f = open(tempFilename)

現在,當我開始從打開的文件中讀取數據並寫回String變量時,這將花費太多時間。 並且我的Spotfire屏幕停止工作。

有人對此有想法嗎?

我的數據表大小為8MB。

代碼是:

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

該代碼適用於短數據。

如果我理解正確,則代碼的目的是將Table Plot可視化數據讀取為字符串,以供在HTML文本區域中進一步使用。 有另一種方法可以執行此操作,而無需將數據寫入臨時文件。 我們可以使用內存流來導出數據,並將導出的文本轉換為字符串以供進一步重用。 示例代碼可以從這里參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM