VisualisationValeur.py 1.4 KB
Newer Older
hichbra's avatar
hichbra committed
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
# UTILISATION

# sans argument = full time 

# avec argument =>
# 	arg1 = date de debut
#	arg2 = date de fin


import matplotlib.pyplot as plt
import csv
import sys
from datetime import datetime

x = []
y = []
moy = []
CONST_MOYENNE = 50
fullTime = False

if len(sys.argv) == 1:
	fullTime = True
elif len(sys.argv) == 3 :
	try:
		date1 = datetime.strptime(sys.argv[1], '%Y-%m-%d %H:%M:%S')
		date2 = datetime.strptime(sys.argv[2], '%Y-%m-%d %H:%M:%S')
	except:
		print("Erreur, arguments incorrect. Les dates doivent etre sous la forme \"AAAA-MM-JJ HH-mm-SS\"")
		exit(1)
else :
	print("Erreur, arguments incorrect. Les dates doivent etre sous la forme \"AAAA-MM-JJ HH-mm-SS\"")
	exit(1)

i = 0 
with open('mytable.csv','r') as csvfile:
	next(csvfile, None)
	plots = csv.reader(csvfile, delimiter=',')
	for row in plots:
		if not fullTime:
			date = datetime.strptime(row[1],'%Y-%m-%d %H:%M:%S')
			if (date1-date).total_seconds() > 0:
				continue

		if fullTime or (date2-date).total_seconds() > 0 :
			x.append(i)
			y.append(int(row[2]))
			
			if i >= CONST_MOYENNE :
				moyenne = 0 
				for j in range(i-CONST_MOYENNE, i, 1) :
					moyenne = moyenne+y[j]
				moy.append(moyenne / CONST_MOYENNE)
				
			else:
				moy.append(int(row[2]))
			i = i+1
		
plt.plot(x,y, label='Donnes brut')
plt.plot(x,moy, label='Moyenne mobile (50)')
plt.xlabel('Gauss')
plt.ylabel('temps (200ms)')
plt.title('Astreos')
plt.legend()
plt.show()