from pylab import *
from pysqlite2 import dbapi2 as sql
def sqlcmp2(x, yfield, first_type, second_type, first_interface, second_interface, period=None, sleep=None, pc=None, feed_count=None, semilog=False, linetype=None):
sql="select t1.period,t1.sleep,t1.pc,t1.feed_count,%s from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='%s' and t2.type='%s' and d1.interface='%s' and d2.interface='%s'"%(yfield,first_type,second_type,first_interface,second_interface)
xfields=0
xfield=""
if(period == None):
xfield += 'period'
xfields+=1
else:
sql += " and t1.period = %s"%period
if(sleep == None):
xfield += 'sleep'
xfields+=1
else:
sql += " and t1.sleep = %s"%sleep
if(pc == None):
xfield += 'pc'
xfields+=1
else:
sql += " and t1.pc = %s"%pc
if(feed_count == None):
xfield += 'feed_count'
xfields+=1
else:
sql += " and t1.feed_count = %s"%feed_count
if xfields<1:
print "No xfields found"
raise(Exception)
if xfields>1:
print "Too many unspecified independent variables (%s) : %s"%(xfields,xfield)
raise(Exception)
sql += " and t1.%s = %s"%(xfield, x)
print sql
r=cur.execute(sql)
for row in r.fetchall():
print "Result"
def sqlplot2(yfield, first_type, second_type, first_interface, second_interface, period=None, sleep=None, pc=None, feed_count=None, semilog=False, linetype=None):
sql="select t1.period,t1.sleep,t1.pc,t1.feed_count,%s from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='%s' and t2.type='%s' and d1.interface='%s' and d2.interface='%s'"%(yfield,first_type,second_type,first_interface,second_interface)
xfields=0
xfield=""
if(period == None):
xfield += 'period'
xfields+=1
else:
sql += " and t1.period = %s"%period
if(sleep == None):
xfield += 'sleep'
xfields+=1
else:
sql += " and t1.sleep = %s"%sleep
if(pc == None):
xfield += 'pc'
xfields+=1
else:
sql += " and t1.pc = %s"%pc
if(feed_count == None):
xfield += 'feed_count'
xfields+=1
else:
sql += " and t1.feed_count = %s"%feed_count
if xfields<1:
print "No xfields found"
raise(Exception)
if xfields>1:
print "Too many unspecified independent variables (%s) : %s"%(xfields,xfield)
raise(Exception)
sql += " order by t1.%s"%xfield
print sql
r=cur.execute(sql)
x=[]
y=[]
for row in r.fetchall():
print row[xfield], row[4]
x.append(row[xfield])
y.append(row[yfield])
if semilog:
semilogy(x,y,linetype)
else:
plot(x,y,linetype)
def sqlplot(xfield, yfield, type='proxy', interface='wireless', period=None, sleep=None, pc=None, feed_count=None, semilog=False,linetype=None):
sql="SELECT %s,%s from tests as t join data as d on t.id=d.test where t.type='%s' and d.interface='%s'"%(xfield, yfield, type, interface)
if(not period == None):
sql += " and t.period = %s"%period
if(not sleep == None):
sql += " and t.sleep = %s"%sleep
if(not pc == None):
sql += " and t.pc = %s"%pc
if(not feed_count == None):
sql += " and t.feed_count = %s"%feed_count
sql += " order by %s"%xfield
print sql
r=cur.execute(sql)
x=[]
y=[]
for row in r.fetchall():
print row[xfield], row[yfield]
x.append(row[xfield])
y.append(row[yfield])
if semilog:
semilogy(x,y,linetype)
else:
plot(x,y,linetype)
if __name__=="__main__":
golden_mean = (sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = 2.5 # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = {'backend': 'ps',
'axes.labelsize': 24,
'text.fontsize': 24,
'legend.fontsize': 24,
'xtick.labelsize': 16,
'ytick.labelsize': 16,
'text.usetex': True,
'figure.figsize': fig_size}
rcParams.update(params)
proxy=[]
proxy_sent=[]
no_proxy=[]
no_proxy_sent=[]
oob=[]
periods=[]
type="eps"
con=sql.connect("ocmp.db")
con.row_factory=sql.Row
cur=con.cursor()
sql="select 100.0*(d1.recv-d2.recv)/d1.recv from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='no_proxy' and t2.type='proxy' and d1.interface='net' and d2.interface='wireless' and t1.period=30 and t1.sleep=0 and t1.pc=1 and t1.feed_count=10"
r=cur.execute(sql)
for row in r.fetchall():
print row[0]
sql="select 100.0*(d1.recv-d2.recv)/d1.recv from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='no_proxy' and t2.type='proxy-diff' and d1.interface='net' and d2.interface='wireless' and t1.period=30 and t1.sleep=0 and t1.pc=1 and t1.feed_count=10"
r=cur.execute(sql)
for row in r.fetchall():
print row[0]
sql="select 100.0*(d1.recv-d2.recv)/d1.recv from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='no_proxy' and t2.type='proxy' and d1.interface='net' and d2.interface='wireless' and t1.period=360 and t1.sleep=0 and t1.pc=1 and t1.feed_count=10"
r=cur.execute(sql)
for row in r.fetchall():
print row[0]
sql="select 100.0*(d1.recv-d2.recv)/d1.recv from tests as t1 join data as d1 join tests as t2 join data as d2 on t1.id=d1.test and t2.id=d2.test where t1.period=t2.period and t1.sleep=t2.sleep and t1.pc=t2.pc and t1.feed_count=t2.feed_count and t1.type='no_proxy' and t2.type='proxy-diff' and d1.interface='net' and d2.interface='wireless' and t1.period=360 and t1.sleep=0 and t1.pc=1 and t1.feed_count=10"
r=cur.execute(sql)
for row in r.fetchall():
print row[0]
#############################
figure(1)
clf()
sqlplot('period', 'recv', interface='net', type='no_proxy', sleep=0, pc=1, feed_count=10, semilog=True,linetype="-")
sqlplot('period', 'recv', type='proxy', sleep=0, pc=1, feed_count=10, semilog=True,linetype="--")
sqlplot('period', 'recv', type='proxy-diff', sleep=0, pc=1, feed_count=10, semilog=True,linetype=":")
legend(("No Proxy", "Proxy", "Proxy with Diff"))
xlabel("$T_{poll}$")
ylabel("Bytes received")
savefig('proxy-vs-ocmp-period.%s'%type)
#############################
figure(1)
clf()
wakeup=1.24*3 + 0.71*2
failure=1.24*10
send=(2.7*5.8)/(1024*1024)
recv=(2.4*5.9)/(1024*1024)
power='recv*%s+sent*%s+wakeups*%s+failures*%s'%(recv,send,wakeup,failure)
sqlplot('period', power, interface='net', type='no_proxy', sleep=0, pc=1, feed_count=10, semilog=True,linetype="-")
sqlplot('period', power, type='proxy', sleep=0, pc=1, feed_count=10, semilog=True,linetype="--")
sqlplot('period', power, type='proxy-diff', sleep=0, pc=1, feed_count=10, semilog=True,linetype=":")
legend(("No Proxy", "Proxy", "Proxy with Diff"))
xlabel("$T_{poll}$")
ylabel("Energy consumed (J)")
savefig('energy-poll.%s'%type)
###############################
clf()
sqlplot('period', 'wakeups', interface='net', type='no_proxy', sleep=1, pc=1, feed_count=10,linetype="-",semilog=True)
sqlplot('period', 'wakeups', type='proxy', sleep=1, pc=1, feed_count=10,linetype="--",semilog=True)
legend(("No Proxy", "Proxy"))
xlabel("$P_{sleep}$")
ylabel("Attempts")
savefig('proxy-vs-ocmp-attempts.%s'%type)
##################################
clf()
sqlplot('pc', 'failures', interface='net', type='no_proxy', period=30, sleep=0, feed_count=10, linetype="-")
sqlplot('pc', 'failures', type='proxy', period=30, sleep=0, feed_count=10, linetype="--")
legend(("No Proxy", "Proxy"))
xlabel("$P_{avail}$")
ylabel("Number of failed connections.")
savefig('proxy-vs-ocmp-failures.%s'%type)
#################################
clf()
sqlplot('feed_count', 'recv', interface='net', type='no_proxy', sleep=0, pc=1, period=30,linetype="-")
sqlplot('feed_count', 'recv', type='proxy', sleep=0, pc=1, period=30,linetype="--")
sqlplot('feed_count', 'recv', type='proxy-diff', sleep=0, pc=1, period=30,linetype=":")
legend(("No Proxy", "Proxy", "Proxy-Diff"))
xlabel("N")
ylabel("Bytes received by mobile")
savefig('proxy-vs-ocmp-feed_count.%s'%type)
#################################
clf()
sqlplot('feed_count', power, interface='net', type='no_proxy', sleep=0, pc=1, period=30,linetype="-")
sqlplot('feed_count', power, type='proxy', sleep=0, pc=1, period=30,linetype="--")
sqlplot('feed_count', power, type='proxy-diff', sleep=0, pc=1, period=30,linetype=":")
legend(("No Proxy", "Proxy", "Proxy-Diff"))
xlabel("N")
ylabel("Energy Consumed (J)")
savefig('energy-feed_count.%s'%type)
#################################
clf()
sqlplot('period', 'sent/160.0', interface='oob', type='proxy', sleep=0, pc=1, feed_count=10,linetype="-")
sqlplot('period', 'sent/160.0', interface='oob', type='proxy-diff', sleep=0, pc=1, feed_count=10,linetype="--")
legend(("Proxy","Proxy-Diff"))
xlabel("$T_{poll}$")
ylabel("Number of OOB notifications")
savefig('proxy-oob-count.%s'%type)
################################
sqlplot('period', 'sent/160.0', interface='oob', type='proxy', sleep=0, pc=1, feed_count=10,linetype="-")
sqlplot('period', 'sent/160.0', interface='oob', type='proxy-diff', sleep=0, pc=1, feed_count=10,linetype="--")
legend(("Proxy","Proxy-Diff"))
xlabel("$T_{poll}$")
ylabel("Number of OOB notifications")
savefig('proxy-oob-count.%s'%type)
clf()
sqlplot2('100*(d1.recv-d2.recv)/cast(d1.recv as real)', 'no_proxy', 'proxy', 'net', 'wireless', sleep=0, pc=1, feed_count=10,linetype="-")
sqlplot2('100*(d1.recv-d2.recv)/cast(d1.recv as real)', 'no_proxy', 'proxy-diff', 'net', 'wireless', sleep=0, pc=1, feed_count=10,linetype="--")
legend(("Proxy", "Proxy-Diff"))
xlabel("$T_{poll}$")
ylabel("Percent reduction in bandwidth");
savefig('proxy-vs-ocmp-period-cmp.%s'%type)