Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Simon Bazin
nf26-metar
Commits
9e3d6cae
Commit
9e3d6cae
authored
Jun 22, 2019
by
sim-baz
Browse files
Fix
parent
51e0479e
Changes
2
Hide whitespace changes
Inline
Side-by-side
history.py
View file @
9e3d6cae
...
...
@@ -2,6 +2,7 @@ import matplotlib.pyplot as plt
from
cassandra.cluster
import
Cluster
from
datetime
import
datetime
import
numpy
as
np
import
math
import
loading
...
...
@@ -66,6 +67,7 @@ def verifyYearValidity(dateMin, dateMax):
return
True
def
plotHistory
(
station
,
indicator
,
dateMin
,
dateMax
):
dateMax
=
dateMax
+
1
# Accept only indicator with numeric values (not factors)
if
indicator
in
numeric_columns
:
if
not
verifyYearValidity
(
dateMin
,
dateMax
):
...
...
@@ -109,11 +111,14 @@ def plotHistory(station, indicator, dateMin, dateMax):
# Configure graduation of plot
# Need to find a nice step for graduation (no more than 6 values to be understandable)
step_graduation
=
max
((
dateMax
-
dateMin
)
/
/
5
,
1
)
step_graduation
=
max
(
math
.
ceil
(
(
dateMax
-
dateMin
)
/
5
)
,
1
)
# Convert the graduation to the date format (yyyy-month-01)
graduation
=
[
"20"
+
"0"
*
(
2
-
len
(
str
(
i
)))
+
str
(
i
)
+
"-01-01"
for
i
in
range
(
int
(
str
(
dateMin
)[
2
:
4
]),
int
(
str
(
dateMax
)[
2
:
4
]),
step_graduation
)]
# Add the last value of graduation for the last day of measures
graduation
.
append
(
"20"
+
"0"
*
(
2
-
len
(
str
(
dateMax
-
1
)[
2
:
4
]))
+
str
(
dateMax
-
1
)[
2
:
4
]
+
"-12-31"
)
# Pour ne pas que la date de fin se superpose avec une autre date
if
(
dateMax
-
dateMin
)
%
2
==
0
or
step_graduation
==
1
:
# Add the last value of graduation for the last day of measures
graduation
.
append
(
"20"
+
"0"
*
(
2
-
len
(
str
(
dateMax
-
1
)[
2
:
4
]))
+
str
(
dateMax
-
1
)[
2
:
4
]
+
"-12-31"
)
# Plot, with both measures and season mean
fig
,
ax1
=
plt
.
subplots
()
...
...
kmeans.py
View file @
9e3d6cae
...
...
@@ -74,14 +74,14 @@ def applyKmeans(deciles, nb_indicators, indicators_list, startPeriod, endPeriod)
stations_name
.
append
(
station
)
for
i
in
range
(
nb_indicators
):
t
+=
deciles
[
station
][
i
][
indicators_list
[
i
]]
print
(
t
)
table
.
append
(
t
)
nb_clusters
=
3
if
len
(
stations_name
)
<
nb_clusters
:
print
(
f
"Le nombre de villes ayant des données est trop inférieur (
{
len
(
stations_name
)
}
) pour appliquer les kmeans pour la période du
{
startPeriod
}
au
{
endPeriod
}
"
)
return
None
kmeans
=
KMeans
(
n_clusters
=
3
,
max_iter
=
100
).
fit
(
table
)
kmeans
=
KMeans
(
n_clusters
=
nb_clusters
,
max_iter
=
100
).
fit
(
table
)
res
=
{}
i
=
0
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment