Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nf26-metar
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Simon Bazin
nf26-metar
Commits
bf216721
Commit
bf216721
authored
Jun 17, 2019
by
sim-baz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add history for station
parent
7e2e0f67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
5 deletions
+51
-5
history.py
history.py
+48
-0
loading.py
loading.py
+3
-5
No files found.
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))
...
...
@@ -330,5 +330,3 @@ dict = loadata(FILE_NAME)
# session.execute(insertQueryData(d, table_name))
# print(f"Datas inserted into {table_name}")
# # --------------------------------------------------------
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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