예제 #1
0
from eventD import eventDetection
import pylab as pl
import numpy as num

if __name__=='__main__':
	a=num.random.normal(10,3,100)
	b=num.random.normal(7,3,33)
	c=num.random.normal(10.2,3,67)
	d=list(a)+list(b)+list(c)
	f,ax=pl.subplots(2,sharex=True)
	ax[0].plot(d)
	out=eventDetection(d,sigma=9,l=30,p=0.05)
	for xx in out:
		if xx[1]>0:
			ax[1].plot([xx[0],xx[0]],[0,xx[1]],'b-',lw=3)
		if xx[1]<0:
			ax[1].plot([xx[0],xx[0]],[0,xx[1]],'r-',lw=3)
	ax[1].axhline(0,lw=2,color='black')
	pl.show()
예제 #2
0
def tsA(fName):
	dF='CSV/'+fName+'.db'
	if not os.path.exists(dF):
		print 'Error: Database does not exist'
		return
	D=sq.connect(dF)
	cur=D.cursor()
	qq="""select cP,Community,SPD,lt,download_rate,cAS
	from meta
	where 
	SPD not null and Community not null and SPD!=-1 and cP not null"""
	cur.execute(qq)
	A=cur.fetchall()
	D={}
	SP={}
	for w in A:
		try:
			D[(w[0],w[1],w[2],w[-1])]=D[(w[0],w[1],w[2],w[-1])]+[(w[3],w[4])]
		except KeyError:
			D[(w[0],w[1],w[2],w[-1])]=[(w[3],w[4])]
	for w in D.keys():
		temp=D[w]
		if len(temp)<700:
			del D[w]
	#~ pref,com,sp=zip(*D.keys())
	#~ d={}
	#~ for k,p in enumerate(pref):
		#~ try:
			#~ d[p].append((com[k],sp[k]))
		#~ except KeyError:
			#~ d[p]=[(com[k],sp[k])]
	#~ for ww in d.items():
		#~ print ww
		#~ raw_input('=================>')	
	p=[]
	l=str(len(D.keys()))
	for j,w in enumerate(D.keys()):
		print str(j)+' '+l
		temp=D[w]
		cP='"'+w[0]+'"'
		C=str(w[1])
		qq="select lt,download_rate\n\
		from meta\n\
		where\n \
		SPD=-1 and Community="+C+" and cP="+cP+";"
		cur.execute(qq)
		A=cur.fetchall()
		lt2,r2=zip(*A)
		lt,r=zip(*temp)
		ts=lt+lt2
		at=min(ts)
		y=r+r2
		tsd,zd=diurnalPDF(ts,y,2*60*60)
		ew=KL(zd)
		p.append(ew)
		if ew<.3:
			continue
		
	#~ y,x=CDF(p)
	#~ pl.plot(x,y)
	#~ pl.show()
		print tsd
		print zd
		pl.plot(tsd,zd)
		pl.show()
		raw_input('============>')
		ts,y=order(ts,y)
		tsp=[float(xx-at)/(3600) for xx in ts]
		out=eventDetection(y,sigma=num.var(r),l=30,p=0.01)
		#~ if len(out)>0:
		if True:
			f,ax=pl.subplots(3,sharex=True)
			ax[0].plot(tsp,y)
			ax[0].set_ylabel('Download(Mbps)')
			for xx in out:
				if xx[1]>0:
					ax[1].plot([tsp[xx[0]],tsp[xx[0]]],[0,xx[1]],'b-',lw=3)
				if xx[1]<0:
					ax[1].plot([tsp[xx[0]],tsp[xx[0]]],[0,xx[1]],'r-',lw=3)
			ax[1].axhline(0,lw=2,color='black')
			xax,Z=bina(ts,y,4*60*60)
			ax[2].plot(xax,Z,'c--')
			ax[2].set_xlabel('Time in hour')
			pl.suptitle('AS'+str(w[-1]),fontsize=20)
			pl.show()
			recPlot(Z,2)
			pl.show()