2017-02-14 3 views
2

IronPythonを使用してSpotfireの一時ファイルから大きなデータを読み取る必要があります。IronPythonを使用してSpotfireの一時ファイルから大きなデータを読み取る方法

まず私は、エクスポートされたテキスト()メソッドを使用して一時ファイルに私の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) 

オープンされたファイルからデータを読み込み、文字列変数に書き戻し始めたとき、時間がかかりすぎています。そして私の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 

コードは、短いデータで正常に動作します。

答えて

0

私が正しければ、コードの意図は、HTMLテキストエリアでさらに使用するために、表プロットの視覚化データを文字列に読み込むことです。 一時ファイルにデータを書き込まずに、これを行う代わりの方法があります。メモリストリームを使用してデータをエクスポートし、エクスポートされたテキストを文字列に変換してさらに再利用することができます。サンプルコードはhereから参照できます。

+0

ありがとうVivek。確かに私はこれを試し、あなたに結果を知らせる:) – Aashi

関連する問題