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
bf216721
Commit
bf216721
authored
Jun 17, 2019
by
sim-baz
Browse files
Add history for station
parent
7e2e0f67
Changes
2
Hide whitespace changes
Inline
Side-by-side
history.py
0 → 100644
View file @
bf216721
import
matplotlib.pyplot
as
plt
from
cassandra.cluster
import
Cluster
from
datetime
import
datetime
table_name
=
"data"
numeric_columns
=
[
"lon"
,
"lat"
,
"tmpf"
,
"dwpf"
,
"relh"
,
"drct"
,
"sknt"
,
"p01i"
,
"alti"
,
"mslp"
,
"vsby"
,
"gust"
,
"skyl1"
,
"skyl2"
,
"skyl3"
,
"skyl4"
,
"feel"
,
"ice_accretion_1hr"
,
"ice_accretion_3hr"
,
"ice_accretion_6hr"
,
"peak_wind_gust"
,
"peak_wind_drct"
,
"peak_wind_time"
]
cluster
=
Cluster
()
session
=
cluster
.
connect
()
session
.
set_keyspace
(
"bazinsim_roisinos_metar"
)
def
getHistory
(
station
,
indicator
):
datas
=
session
.
execute
(
f
"SELECT year, month, day, hour, minute,
{
indicator
}
FROM
{
table_name
}
where station = '
{
station
}
'"
)
# for t in datas:
# print(t[0])
return
datas
def
plotHistory
(
station
,
indicator
):
if
indicator
in
numeric_columns
:
table
=
getHistory
(
station
,
indicator
)
if
not
table
:
print
(
f
"Aucune donnée pour la station
{
station
}
et pour l'indicateur
{
indicator
}
"
)
return
table_date
=
{}
for
r
in
table
:
if
(
r
[
len
(
r
)
-
1
]
!=
None
):
date
=
datetime
.
strptime
(
str
(
r
[
0
])
+
"-"
+
str
(
r
[
1
])
+
"-"
+
str
(
r
[
2
]),
'%Y-%m-%d'
).
date
()
if
date
not
in
table_date
.
keys
():
table_date
[
date
]
=
0
,
0
table_date
[
date
]
=
(
table_date
[
date
][
0
]
+
r
[
len
(
r
)
-
1
],
table_date
[
date
][
1
]
+
1
)
for
d
in
table_date
.
keys
():
table_date
[
d
]
=
table_date
[
d
][
0
]
/
table_date
[
d
][
1
]
currentDateTime
=
datetime
.
now
().
strftime
(
"%Y-%m-%d_%H-%M-%S"
)
file_name
=
str
(
currentDateTime
)
+
"_"
+
station
+
"_"
+
indicator
+
".png"
plt
.
plot_date
(
table_date
.
keys
(),
table_date
.
values
(),
'-'
,
xdate
=
True
)
plt
.
title
(
f
"Evolution de
{
indicator
}
pour la station
{
station
}
"
)
plt
.
xlabel
(
'Date'
)
plt
.
ylabel
(
indicator
)
plt
.
savefig
(
file_name
)
else
:
print
(
"Les données pour cet indicateur ne sont pas numériques, impossible de tracer un graphique"
)
plotHistory
(
"EFKI"
,
"tmpf"
)
\ No newline at end of file
loading.py
View file @
bf216721
...
...
@@ -3,6 +3,7 @@ import csv
import
re
FILE_NAME
=
"asos.txt"
table_name
=
"data"
# Country: Finland
# Dates : 2001 to 2010
...
...
@@ -256,7 +257,7 @@ def createTableQuery(table):
peak_wind_drct decimal,
peak_wind_time decimal,
metar varchar,
PRIMARY KEY(station)
PRIMARY KEY(
(
station)
, year, month, day, hour, minute)
)"""
return
query
...
...
@@ -319,7 +320,6 @@ dict = loadata(FILE_NAME)
# # --------------------------------------------------------
# # A faire seulement 1 fois pour charger les données
# table_name = "data"
# session.execute(dropTableQuery(table_name))
# print(f"Table {table_name} dropped")
# session.execute(createTableQuery(table_name))
...
...
@@ -329,6 +329,4 @@ dict = loadata(FILE_NAME)
# for d in dict:
# session.execute(insertQueryData(d, table_name))
# print(f"Datas inserted into {table_name}")
# # --------------------------------------------------------
# # --------------------------------------------------------
\ No newline at end of file
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