In [154]:
#%matplotlib inline
import sqlite3
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import pandas as pd
In [155]:
in_db = 'in.db'
data_db = 'data.db'
view_db = 'view.db'
input table
In [156]:
conn = sqlite3.connect(in_db)
c = conn.cursor()
for row in c.execute('SELECT * FROM iPrice'):
print row
conn.close()
dPrice
In [157]:
conn = sqlite3.connect(data_db)
c = conn.cursor()
for row in c.execute('SELECT * FROM dPrice'):
print row
conn.close()
pPrice
In [167]:
conn = sqlite3.connect(data_db)
c = conn.cursor()
for row in c.execute('SELECT * FROM pPrice'):
print row
conn.close()
vViewpoint
In [168]:
conn = sqlite3.connect(view_db)
c = conn.cursor()
for row in c.execute('SELECT * FROM vViewpoint'):
print row
conn.close()
view
In [169]:
conn = sqlite3.connect(view_db)
c = conn.cursor()
for row in c.execute('SELECT * FROM vPrice'):
print row
conn.close()
In [170]:
def get_iPrice_details():
conn = sqlite3.connect(in_db)
c = conn.cursor()
#df = pd.read_sql("SELECT count(*), status from iPrice group by status",conn) #,conn,parse_dates={'date':'%Y-%m-%d'})
results = c.execute("SELECT count(*), status from iPrice group by status") #,conn,parse_dates={'date':'%Y-%m-%d'})
rtn = {}
for row in results:
#print row
rtn[str(row[1])] = row[0]
conn.close()
return rtn
In [171]:
print get_iPrice_details()
Show chart of iPrice processing
In [172]:
def get_vPrice_details():
conn = sqlite3.connect(view_db)
c = conn.cursor()
#df = pd.read_sql("SELECT count(*), status from iPrice group by status",conn) #,conn,parse_dates={'date':'%Y-%m-%d'})
results = c.execute("SELECT * from vViewpoint where dtable = 'dPrice' ")
#print results
for row in results:
#print row
vpoint = row[2]
conn.close()
conn = sqlite3.connect(data_db)
c = conn.cursor()
#df = pd.read_sql("SELECT count(*), status from iPrice group by status",conn) #,conn,parse_dates={'date':'%Y-%m-%d'})
results = c.execute("SELECT max(dPriceId) from dPrice ")
#print results
for row in results:
#print row
max_dPrice = row[0]
conn.close()
return vpoint, max_dPrice
In [ ]:
Show plot of delays
In [174]:
fig1 = plt.figure()
ax1 = fig1.add_subplot(2,1,1)
ax2 = fig1.add_subplot(2,1,2)
#global d
count_wait = [0,]
count_process = [0,]
count_done =[0,]
count_total = [0,]
count_vpoint = [0,]
count_max_dPrice = [0,]
count_vbehind = [0,]
#yahoo = Share('YHOO')
def animate1(i):
iPrice_details = get_iPrice_details()
wait = iPrice_details.get('wait',0)
process = iPrice_details.get('process',0)
done = iPrice_details.get('done',0)
total = wait + process + done
count_wait.append(wait)
count_process.append(process)
count_done.append(done)
count_total.append(total)
ax1.clear()
ax1.plot(range(len(count_wait)),count_wait, label = 'wait')
ax1.plot(range(len(count_process)),count_process, label = 'processing')
ax1.plot(range(len(count_done)),count_done, label = 'done')
ax1.plot(range(len(count_total)),count_total, label = 'total')
ax1.legend(loc='upper left')
vpoint, max_dPrice = get_vPrice_details()
vbehind = max_dPrice - vpoint
count_vpoint.append(vpoint)
count_max_dPrice.append(max_dPrice)
count_vbehind.append(vbehind)
ax2.clear()
ax2.plot(range(len(count_vpoint)),count_vpoint,label = 'vpoint' )
ax2.plot(range(len(count_max_dPrice)),count_max_dPrice, label = 'max')
ax2.plot(range(len(count_vbehind)),count_vbehind, label = 'behind')
ax2.legend(loc='upper left')
ani1 = animation.FuncAnimation(fig1,animate1, interval=1000)
plt.show()
show chart for vPrice monitoring
In [165]:
print get_vPrice_details()
In [166]:
fig1 = plt.figure()
ax1 = fig1.add_subplot(1,1,1)
#global d
count_vpoint = [0,]
count_max_dPrice = [0,]
count_vbehind = [0,]
#yahoo = Share('YHOO')
def animate1(i):
vpoint, max_dPrice = get_vPrice_details()
vbehind = max_dPrice - vpoint
count_vpoint.append(vpoint)
count_max_dPrice.append(max_dPrice)
count_vbehind.append(vbehind)
ax1.clear()
ax1.plot(range(len(count_vpoint)),count_vpoint)
ax1.plot(range(len(count_max_dPrice)),count_max_dPrice)
ax1.plot(range(len(count_vbehind)),count_vbehind)
ani1 = animation.FuncAnimation(fig1,animate1, interval=1000)
plt.show()
In [ ]:
In [ ]:
In [ ]: