Commit 659e9ac8 authored by {}'s avatar {}
Browse files

Fonction 2 en cours

parent 5fb58114
"""File to execute to show results""" """File to execute to show results"""
from parameters import SESSION
import re
from datetime import datetime, timedelta
import matplotlib.dates as mdates
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from datetime import datetime, timedelta from pandas.plotting import register_matplotlib_converters
from parameters import SESSION register_matplotlib_converters()
import as stm_graphs
import pandas as pd
import statsmodels.api as stm
#Graph map
from mpl_toolkits.basemaps import Basemap
def execute_query(query): def execute_query(query):
...@@ -16,6 +30,28 @@ def ask_q(possibilities, text=">>> "): ...@@ -16,6 +30,28 @@ def ask_q(possibilities, text=">>> "):
answer = input(text) answer = input(text)
return answer return answer
def ask_d(text=">>> "):
t = input(text)
done = False
date_parser = re.compile(
r"(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+) (?P<hour>\d+):(?P<minute>\d+)"
match = False
result = None
while(match == False):
match = date_parser.match(t)
if not match:
print("Veuillez suivre le format demandé")
m = match.groupdict()
result = (int(m['year']), int(m['month']), int(m['day']), int(m['hour']), int(m['minute']))
return result
class Manager: class Manager:
table = None # table name use by the function table = None # table name use by the function
...@@ -61,28 +97,83 @@ class Manager: ...@@ -61,28 +97,83 @@ class Manager:
print("\t-", text, ":", code) print("\t-", text, ":", code)
attr = ask_q(decision.keys()) attr = ask_q(decision.keys())
x = [] ts = pd.Series()
y = [] query = "SELECT time,{} FROM {} WHERE station={}".format(attr,self.table, station.__repr__())
query = "SELECT * FROM {} WHERE station={}".format(self.table, station.__repr__())
for row in execute_query(query): for row in execute_query(query):
value = getattr(row, attr) value = getattr(row, attr)
if value is None: if value is None:
continue continue
x.append(datetime(*list(row.time))) ts.loc[datetime(*list(row.time))] = value
figure = plt.figure(figsize=(25,16))
date, last_date = x[0], x[-1] # first date and last date, initialisation axes = plt.subplot()
x = np.array(x) axes.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
y = np.array(y) _=plt.xticks(rotation=90)
plt.plot(x, y, label=attr)
plt.title("Donnees de " + str(value) + " pour la station : " + station )
plt.plot(ts, label=attr)
plt.title("Donnees de " + str(attr) + " pour la station : " + station )
plt.legend() plt.legend()
plt.savefig('plot.png') plt.savefig('./out/graph_'+station+'_'+ str(attr) +'.png')
res = stm.tsa.seasonal_decompose(ts, freq=15, extrapolate_trend= 'freq')
plt.savefig('./out/decompose_'+station+'_'+ str(attr) +'.png')
ACF = stm_graphs.tsaplots.plot_acf(ts,lags=30)
plt.savefig('./out/acf_'+station+'_'+ str(attr) +'.png')
def map(self): def map(self):
print("Cette fonction n'est pas implémentée") self.table = "TABLE_TIME"
#Ask Date
print("Entrez une date sous la forme YYYY-MM-DD HH:mm")
date = ask_d()
# Search element
decision = {
"tmpf": "La témparature",
"relh": "L'humidité"
print("Choisissez un élément parmis les suivant :")
for code, text in decision.items():
print("\t-", text, ":", code)
attr = ask_q(decision.keys())
df = pd.DataFrame()
query = "SELECT station,lon,lat,{} FROM {} WHERE time={}".format(attr,self.table, date)
for row in execute_query(query):
if getattr(row, "station") is None:
df = df.append({"station": getattr(row, "station"),
map = Basemap(projection='mill',lat_0=26.281898,lon_0=-16.42,lat_1 = 43.08,lon_1 =7.35, resolution='l')
# draw coastlines, country boundaries, fill continents.
# draw the edge of the map projection region (the projection limb)
# draw lat/lon grid lines every 30 degrees.
def cluster(self): def cluster(self):
print("Cette fonction n'est pas implémentée") print("Cette fonction n'est pas implémentée")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment