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

courbe ok

parent 0fbf76c1
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="dec891dc-2fad-4291-af33-64d4fd64029d" name="Default Changelist" comment=""> <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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" 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" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -30,8 +27,8 @@ ...@@ -30,8 +27,8 @@
<file pinned="false" current-in-tab="true"> <file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="507"> <state relative-caret-position="298">
<caret line="64" column="8" selection-start-line="64" selection-start-column="8" selection-end-line="64" selection-end-column="8" /> <caret line="112" selection-start-line="112" selection-end-line="112" />
<folding> <folding>
<element signature="e#38#56#0" expanded="true" /> <element signature="e#38#56#0" expanded="true" />
</folding> </folding>
...@@ -332,8 +329,8 @@ ...@@ -332,8 +329,8 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/main.py"> <entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="507"> <state relative-caret-position="298">
<caret line="64" column="8" selection-start-line="64" selection-start-column="8" selection-end-line="64" selection-end-column="8" /> <caret line="112" selection-start-line="112" selection-end-line="112" />
<folding> <folding>
<element signature="e#38#56#0" expanded="true" /> <element signature="e#38#56#0" expanded="true" />
</folding> </folding>
......
"""File to execute to show results""" """File to execute to show results"""
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from datetime import datetime from datetime import datetime, timedelta
from parameters import SESSION from parameters import SESSION
...@@ -40,10 +40,15 @@ class Manager: ...@@ -40,10 +40,15 @@ class Manager:
self.table = "TABLE_SPACE" self.table = "TABLE_SPACE"
# Search station # Search station
query = "SELECT DISTINCT station FROM {}".format(self.table) stations = []
stations = [row.station for row in execute_query(query)]
print("Choisissez une station parmis celles-ci:") 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) station = ask_q(stations)
# Search element # Search element
...@@ -58,13 +63,72 @@ class Manager: ...@@ -58,13 +63,72 @@ class Manager:
x = [] x = []
y = [] 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__()) 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)
if value is None:
continue
x.append(datetime(*list(row.time))) 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) x = np.array(x)
y = np.array(y) y = np.array(y)
plt.plot(x, y, label=attr) 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.title(station)
plt.legend() plt.legend()
plt.show() 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