Commit e5246f65 authored by Romain Creuzenet's avatar Romain Creuzenet

Cluster finish'

parent 2c17dd6c
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
<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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="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" />
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/create_table.py"> <entry file="file://$PROJECT_DIR$/create_table.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state> <state relative-caret-position="279">
<caret line="51" column="17" selection-start-line="51" selection-start-column="17" selection-end-line="51" selection-end-column="17" /> <caret line="51" column="17" selection-start-line="51" selection-start-column="17" selection-end-line="51" selection-end-column="17" />
</state> </state>
</provider> </provider>
...@@ -25,12 +25,10 @@ ...@@ -25,12 +25,10 @@
<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="659"> <state relative-caret-position="439">
<caret line="297" column="51" selection-start-line="297" selection-start-column="51" selection-end-line="297" selection-end-column="51" /> <caret line="296" column="14" selection-start-line="296" selection-start-column="14" selection-end-line="296" selection-end-column="14" />
<folding> <folding>
<element signature="e#45#96#0" expanded="true" /> <element signature="e#45#107#0" expanded="true" />
<element signature="e#3287#4955#0" />
<element signature="e#4984#7500#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
...@@ -48,8 +46,8 @@ ...@@ -48,8 +46,8 @@
<file pinned="false" current-in-tab="false"> <file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/parameters.py"> <entry file="file://$PROJECT_DIR$/parameters.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="228"> <state relative-caret-position="-443">
<caret line="15" column="1" lean-forward="true" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" /> <caret line="15" column="1" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" />
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -101,7 +99,17 @@ ...@@ -101,7 +99,17 @@
<foldersAlwaysOnTop value="true" /> <foldersAlwaysOnTop value="true" />
</navigator> </navigator>
<panes> <panes>
<pane id="ProjectPane" /> <pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="nf26_projet" type="b2602c69:ProjectViewProjectNode" />
<item name="nf26_projet" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" /> <pane id="Scope" />
</panes> </panes>
</component> </component>
...@@ -139,7 +147,7 @@ ...@@ -139,7 +147,7 @@
<frame x="67" y="25" width="1853" height="1055" extended-state="6" /> <frame x="67" y="25" width="1853" height="1055" extended-state="6" />
<editor active="true" /> <editor active="true" />
<layout> <layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.16229509" /> <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.16229509" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" /> <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" /> <window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" /> <window_info anchor="bottom" id="Message" order="0" />
...@@ -213,9 +221,16 @@ ...@@ -213,9 +221,16 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/env_nf26/lib/python3.6/site-packages/cassandra/cluster.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="291">
<caret line="140" column="8" selection-start-line="140" selection-start-column="8" selection-end-line="140" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/create_table.py"> <entry file="file://$PROJECT_DIR$/create_table.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state> <state relative-caret-position="279">
<caret line="51" column="17" selection-start-line="51" selection-start-column="17" selection-end-line="51" selection-end-column="17" /> <caret line="51" column="17" selection-start-line="51" selection-start-column="17" selection-end-line="51" selection-end-column="17" />
</state> </state>
</provider> </provider>
...@@ -227,28 +242,19 @@ ...@@ -227,28 +242,19 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/env_nf26/lib/python3.6/site-packages/cassandra/cluster.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="291">
<caret line="140" column="8" selection-start-line="140" selection-start-column="8" selection-end-line="140" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/parameters.py"> <entry file="file://$PROJECT_DIR$/parameters.py">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="228"> <state relative-caret-position="-443">
<caret line="15" column="1" lean-forward="true" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" /> <caret line="15" column="1" selection-start-line="15" selection-start-column="1" selection-end-line="15" selection-end-column="1" />
</state> </state>
</provider> </provider>
</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="659"> <state relative-caret-position="439">
<caret line="297" column="51" selection-start-line="297" selection-start-column="51" selection-end-line="297" selection-end-column="51" /> <caret line="296" column="14" selection-start-line="296" selection-start-column="14" selection-end-line="296" selection-end-column="14" />
<folding> <folding>
<element signature="e#45#96#0" expanded="true" /> <element signature="e#45#107#0" expanded="true" />
<element signature="e#3287#4955#0" />
<element signature="e#4984#7500#0" />
</folding> </folding>
</state> </state>
</provider> </provider>
......
...@@ -16,7 +16,7 @@ import numpy as np ...@@ -16,7 +16,7 @@ import numpy as np
# Graph map # Graph map
from mpl_toolkits.basemap import Basemap from mpl_toolkits.basemap import Basemap
from pandas.plotting import register_matplotlib_converters from pandas.plotting import register_matplotlib_converters
from datetime import datetime from datetime import datetime, timedelta
register_matplotlib_converters() register_matplotlib_converters()
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
...@@ -258,25 +258,31 @@ class Manager: ...@@ -258,25 +258,31 @@ class Manager:
print("Entrez le nombre de cluster voulus") print("Entrez le nombre de cluster voulus")
nb_cluster = ask_int() nb_cluster = ask_int()
# Calc of mean
query = "SELECT station, lon, lat, {attr} FROM {table} WHERE time >= {begin} AND time <= {end} " \
"ALLOW FILTERING".format(
attr=", ".join(ATTRIBUTS.keys()),
table=self.table,
begin=date_begin,
end=date_end
)
stations = {} # station: {'nb': 3, 'attr1': 5, 'attr2': 7, ..., 'lon': 3.27, 'lat': 12} stations = {} # station: {'nb': 3, 'attr1': 5, 'attr2': 7, ..., 'lon': 3.27, 'lat': 12}
for row in execute_query(query): datetime_begin = datetime(*list(date_begin)) # Convert datetime
if None in [row.station, row.lon, row.lat] + [getattr(row, attr) for attr in ATTRIBUTS.keys()]: datetime_end = datetime(*list(date_end)) # Convert datetime
continue
if row.station in stations: while datetime_begin <= datetime_end:
print("Données récupérée pour {}".format(datetime_begin.strftime("%Y-%m-%d %H:%M")), end="\r")
# Calc of mean
query = "SELECT station, lon, lat, {attr} FROM {table} WHERE time = {date}".format(
attr=", ".join(ATTRIBUTS.keys()),
table=self.table,
date=(datetime_begin.year, datetime_begin.month, datetime_begin.day, datetime_begin.hour,
datetime_begin.minute)
)
for row in execute_query(query):
if None in [row.station, row.lon, row.lat] + [getattr(row, attr) for attr in ATTRIBUTS.keys()]:
continue
if row.station not in stations:
stations[row.station] = {'nb': 0, 'lon': row.lon, 'lat': row.lat,
**{key: 0 for key in ATTRIBUTS.keys()}}
for attr in ATTRIBUTS.keys(): for attr in ATTRIBUTS.keys():
stations[row.station][attr] += getattr(row, attr) stations[row.station][attr] += getattr(row, attr)
stations[row.station]['nb'] += 1 stations[row.station]['nb'] += 1
else: datetime_begin += timedelta(minutes=1)
stations[row.station] = {'nb': 1, 'lon': row.lon, 'lat': row.lat,
**{key: 0 for key in ATTRIBUTS.keys()}}
for value in stations.values(): for value in stations.values():
for attr in ATTRIBUTS.keys(): for attr in ATTRIBUTS.keys():
value[attr] = value[attr] / value['nb'] value[attr] = value[attr] / value['nb']
...@@ -288,6 +294,8 @@ class Manager: ...@@ -288,6 +294,8 @@ class Manager:
for _ in range(nb_cluster) for _ in range(nb_cluster)
] ]
print()
print("Clusterisation...")
while old_centroids != new_centroids: while old_centroids != new_centroids:
old_centroids = new_centroids old_centroids = new_centroids
data = [ data = [
......
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