1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#!/usr/bin/env python
from __future__ import print_function
from vtk import *
import os.path
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir):
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
if not os.path.exists(data_dir):
data_dir = VTK_DATA_ROOT + "/Data/Infovis/SQLite/"
sqlite_file = data_dir + "temperatures.db"
# I'm sure there's a better way then these global vars
currentRow = 0;
numberOfRows = 1;
done = False;
psuedoStreamingData = vtkProgrammableFilter()
def streamData():
global done
global currentRow
input = psuedoStreamingData.GetInput()
output = psuedoStreamingData.GetOutput()
# Copy just the columns names/types
output.GetRowData().CopyStructure(input.GetRowData())
# Loop through all the input data and grab the next bunch of rows
startRow = currentRow
endRow = startRow + numberOfRows
if (endRow >= input.GetNumberOfRows()):
endRow = input.GetNumberOfRows()
done = True;
print("streaming: ", startRow, "-", endRow)
for i in range(startRow, endRow):
output.InsertNextRow(input.GetRow(i))
currentRow = endRow;
psuedoStreamingData.SetExecuteMethod(streamData)
class Timer(QObject):
def __init__(self, parent=None):
super(Timer, self).__init__(parent)
# Setup the data streaming timer
self.timer = QTimer()
QObject.connect(self.timer, SIGNAL("timeout()"), self.update)
self.timer.start(100)
def update(self):
if (done):
quit();
psuedoStreamingData.Modified() # Is there a way to avoid this?
psuedoStreamingData.GetExecutive().Push()
printStats()
def printStats():
sStats = ss.GetOutputDataObject( 1 )
sPrimary = sStats.GetBlock( 0 )
sDerived = sStats.GetBlock( 1 )
sPrimary.Dump( 15 )
sDerived.Dump( 15 )
if __name__ == "__main__":
""" Main entry point of this python script """
# Set up streaming executive
streamingExec = vtkThreadedStreamingPipeline()
vtkAlgorithm.SetDefaultExecutivePrototype(streamingExec)
streamingExec.FastDelete()
vtkThreadedStreamingPipeline.SetAutoPropagatePush(True)
# Pull the table from the database
databaseToTable = vtkSQLDatabaseTableSource()
databaseToTable.SetURL("sqlite://" + sqlite_file)
databaseToTable.SetQuery("select * from main_tbl")
# Hook up the database to the streaming data filter
psuedoStreamingData.SetInputConnection(databaseToTable.GetOutputPort())
# Calculate offline(non-streaming) descriptive statistics
print("# Calculate offline descriptive statistics:")
ds = vtkDescriptiveStatistics()
ds.SetInputConnection(databaseToTable.GetOutputPort())
ds.AddColumn("Temp1")
ds.AddColumn("Temp2")
ds.Update()
dStats = ds.GetOutputDataObject( 1 )
dPrimary = dStats.GetBlock( 0 )
dDerived = dStats.GetBlock( 1 )
dPrimary.Dump( 15 )
dDerived.Dump( 15 )
# Stats filter to place 'into' the streaming filter
inter = vtkDescriptiveStatistics()
inter.AddColumn("Temp1")
inter.AddColumn("Temp2")
# Calculate online(streaming) descriptive statistics
print("# Calculate online descriptive statistics:")
ss = vtkStreamingStatistics()
ss.SetStatisticsAlgorithm(inter)
ss.SetInputConnection(psuedoStreamingData.GetOutputPort())
# Spin up the timer
app = QApplication(sys.argv)
stream = Timer()
sys.exit(app.exec_())
|