Commit 6dabbbad authored by Romain Creuzenet's avatar Romain Creuzenet

courbe ok

parent 0fbf76c1
......@@ -2,10 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="dec891dc-2fad-4291-af33-64d4fd64029d" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/create_table.py" beforeDir="false" afterPath="$PROJECT_DIR$/create_table.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/espagne_2001_2010.csv" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/parameters.py" beforeDir="false" afterPath="$PROJECT_DIR$/parameters.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -30,8 +27,8 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="507">
<caret line="64" column="8" selection-start-line="64" selection-start-column="8" selection-end-line="64" selection-end-column="8" />
<state relative-caret-position="298">
<caret line="112" selection-start-line="112" selection-end-line="112" />
<folding>
<element signature="e#38#56#0" expanded="true" />
</folding>
......@@ -332,8 +329,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="507">
<caret line="64" column="8" selection-start-line="64" selection-start-column="8" selection-end-line="64" selection-end-column="8" />
<state relative-caret-position="298">
<caret line="112" selection-start-line="112" selection-end-line="112" />
<folding>
<element signature="e#38#56#0" expanded="true" />
</folding>
......
"""File to execute to show results"""
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
from datetime import datetime, timedelta
from parameters import SESSION
......@@ -40,10 +40,15 @@ class Manager:
self.table = "TABLE_SPACE"
# Search station
query = "SELECT DISTINCT station FROM {}".format(self.table)
stations = [row.station for row in execute_query(query)]
stations = []
print("Choisissez une station parmis celles-ci:")
print("\t".join(stations))
query = "SELECT DISTINCT station FROM {}".format(self.table)
for i, row in enumerate(execute_query(query), 1):
end = "\n" if i % 3 == 0 else ""
print("\t", row.station, end=end)
stations.append(row.station)
print()
station = ask_q(stations)
# Search element
......@@ -58,13 +63,72 @@ class Manager:
x = []
y = []
saisons = {
'spring': {
'n': 0,
'somme': 0,
'month': [3, 4, 5], # March - May
'end': lambda dt: datetime(dt.year, 6, 1) - timedelta(days=1),
'legend': False,
'color': 'r'
},
'summer': {
'n': 0,
'somme': 0,
'month': [6, 7, 8], # June - August
'end': lambda dt: datetime(dt.year, 9, 1) - timedelta(days=1),
'legend': False,
'color': 'y'
},
'automne': {
'n': 0,
'somme': 0,
'month': [9, 10, 11], # September - November
'end': lambda dt: datetime(dt.year, 12, 1) - timedelta(days=1),
'legend': False,
'color': 'm'
},
'winter': {
'n': 0,
'somme': 0,
'month': [12, 1, 2], # December - Febrarie
'end': lambda dt: datetime(dt.year + 1, 3, 1) - timedelta(days=1),
'legend': False,
'color': 'k'
}
}
query = "SELECT * FROM {} WHERE station={}".format(self.table, station.__repr__())
for row in execute_query(query):
value = getattr(row, attr)
if value is None:
continue
x.append(datetime(*list(row.time)))
y.append(getattr(row, attr))
y.append(value)
# For saison
for saison, d in saisons.items():
if row.time[1] in d['month']:
d['n'] += 1
d['somme'] += value
break
date, last_date = x[0], x[-1] # first date and last date, initialisation
x = np.array(x)
y = np.array(y)
plt.plot(x, y, label=attr)
# Mark saison
while date < last_date:
for saison, d in saisons.items():
if date.month in d['month']:
next_date = min(last_date, d['end'](date))
moyenne = d['somme'] / d['n']
if d['legend']:
plt.plot([date, next_date], [moyenne, moyenne], d['color'], linewidth=4)
else:
plt.plot([date, next_date], [moyenne, moyenne], d['color'], label=saison, linewidth=4)
d['legend'] = True
date = next_date + timedelta(days=1)
break
plt.title(station)
plt.legend()
plt.show()
......
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