Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Thomas Meurou
NF26 Project
Commits
57136175
Commit
57136175
authored
Jun 22, 2019
by
Tianyang
Browse files
change database: date
parent
cbaad544
Changes
5
Hide whitespace changes
Inline
Side-by-side
.DS_Store
View file @
57136175
No preview for this file type
database_pre2.py
View file @
57136175
...
...
@@ -12,7 +12,8 @@ def connection():
def
databaseCreate_Q2
(
session
):
query
=
"""
CREATE TABLE database_time (
date timestamp,
date varchar,
time varchar,
lon float,
lat float,
station varchar,
...
...
@@ -43,7 +44,7 @@ def databaseCreate_Q2(session):
peak_wind_time varchar,
feel float,
metar varchar,
PRIMARY KEY ((date),lon,lat,station)
PRIMARY KEY ((date),
time,
lon,lat,station)
)"""
session
.
execute
(
query
)
print
(
"DATA BASE database_time created!"
)
...
...
@@ -51,17 +52,20 @@ def databaseCreate_Q2(session):
def
load_data
(
filename
):
with
open
(
filename
)
as
f
:
dateparser
=
re
.
compile
(
"(?P<date>\d+-\d+-\d+) (?P<time>\d+:\d+)"
)
for
r
in
csv
.
DictReader
(
f
):
match_time
=
dateparser
.
match
(
r
[
"valid"
])
if
not
r
[
"valid"
]:
continue
time
=
match_time
.
groupdict
()
for
colonne
in
r
:
if
r
[
colonne
]
==
"M"
:
r
[
colonne
]
=
"nan"
data
=
{}
data
[
"date"
]
=
r
[
"valid
"
]
data
[
"date"
]
=
time
[
"date
"
]
data
[
"station"
]
=
r
[
"station"
]
data
[
"time"
]
=
time
[
"time"
]
data
[
"lon"
]
=
float
(
r
[
"lon"
])
data
[
"lat"
]
=
float
(
r
[
"lat"
])
data
[
"tmpf"
]
=
float
(
r
[
"tmpf"
])
...
...
database_pre3.py
View file @
57136175
...
...
@@ -16,6 +16,7 @@ def databaseCreate_Q3(session):
lon float,
lat float,
station varchar,
time varchar,
tmpf float,
dwpf float,
relh float,
...
...
@@ -43,27 +44,30 @@ def databaseCreate_Q3(session):
peak_wind_time varchar,
feel float,
metar varchar,
PRIMARY KEY ((date),lon,lat,station)
PRIMARY KEY ((date),lon,lat,station
,time
)
)"""
session
.
execute
(
query
)
print
(
"DATA BASE database_kmeans created!"
)
def
load_data
(
filename
):
dateparser
=
re
.
compile
(
"(?P<date>\d+-\d+-\d+) (?P<time>\d+:\d+)"
)
with
open
(
filename
)
as
f
:
for
r
in
csv
.
DictReader
(
f
):
if
not
r
[
"valid"
]:
match_time
=
dateparser
.
match
(
r
[
"valid"
])
if
not
match_time
:
continue
time
=
match_time
.
groupdict
()
for
collonne
in
r
:
if
r
[
collonne
]
==
"M"
:
r
[
collonne
]
=
"nan"
data
=
{}
data
[
"date"
]
=
r
[
"valid
"
]
data
[
"date"
]
=
time
[
"date
"
]
data
[
"station"
]
=
r
[
"station"
]
data
[
"lon"
]
=
float
(
r
[
"lon"
])
data
[
"lat"
]
=
float
(
r
[
"lat"
])
data
[
"time"
]
=
time
[
"time"
]
data
[
"tmpf"
]
=
float
(
r
[
"tmpf"
])
data
[
"dwpf"
]
=
float
(
r
[
"dwpf"
])
data
[
"relh"
]
=
float
(
r
[
"relh"
])
...
...
question2.py
View file @
57136175
...
...
@@ -12,8 +12,8 @@ def createMap(data):
count
=
0
for
each
in
data
.
result
():
#print(each)
mean_lat
+=
each
[
1
]
mean_lon
+=
each
[
2
]
mean_lat
+=
each
[
2
]
mean_lon
+=
each
[
3
]
count
+=
1
if
count
==
0
:
print
(
'No data available at this timestamp !'
)
...
...
@@ -28,12 +28,14 @@ def createMap(data):
"metar"
,
"mslp"
,
"p01i"
,
"peak_wind_drct"
,
"peak_wind_gust"
,
"peak_wind_time"
,
"relh"
,
"sknt"
,
"skyc1"
,
"skyc2"
,
"skyc3"
,
"skyc4"
,
"skyl1"
,
"skyl2"
,
"skyl3"
,
"skyl4"
,
"tmpf"
,
"vsby"
,
"wxcodes"
]
for
each
in
data
.
result
():
#
print(each)
print
(
each
)
# Here we choose not to display the None values and the METAR ID
l
=
[
attributes
[
i
]
+
":"
+
str
(
each
[
i
+
4
])
for
i
in
range
(
len
(
attributes
))
if
each
[
i
+
4
]
!=
None
ls
=
[
"station:"
+
each
[
4
]
+
"
\n
"
]
l
=
[
attributes
[
i
]
+
":"
+
str
(
each
[
i
+
5
])
for
i
in
range
(
len
(
attributes
))
if
each
[
i
+
5
]
!=
None
and
attributes
[
i
]
!=
"metar"
]
l
=
ls
+
l
string
=
'
\n
'
.
join
(
l
)
folium
.
Marker
([
each
[
2
],
each
[
1
]],
folium
.
Marker
([
each
[
3
],
each
[
2
]],
popup
=
string
,
icon
=
folium
.
Icon
(
color
=
'red'
)).
add_to
(
m
)
m
.
save
(
"Projet-NF26/map2.html"
)
...
...
@@ -44,8 +46,7 @@ if __name__ == "__main__":
session
=
connection
()
# Timestamp user wants to search
date
=
input
(
"Please enter the date you want to search (format 'yyyy-MM-dd'):"
)
time
=
input
(
"Please enter the time you want to search (format 'hh:MM
:ss
'):"
)
time
=
input
(
"Please enter the time you want to search (format 'hh:MM'):"
)
#timestamp = '2017-12-02 00:30:00'
timestamp
=
date
+
' '
+
time
data
=
session
.
execute_async
(
"select * from caitiany.database_time where date = '%s' ALLOW FILTERING"
%
(
timestamp
))
data
=
session
.
execute_async
(
"select * from caitiany.database_time where date = '%s' AND time = '%s'"
%
(
date
,
time
))
createMap
(
data
)
question3.py
View file @
57136175
...
...
@@ -6,6 +6,7 @@ import matplotlib.pyplot as plt
import
re
import
folium
import
random
import
datetime
table_variable
=
[
...
...
@@ -13,6 +14,7 @@ table_variable = [
'lon'
,
'lat'
,
'station'
,
'time'
,
'alti'
,
'drct'
,
'dwpf'
,
...
...
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