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
cbaad544
Commit
cbaad544
authored
Jun 22, 2019
by
Tianyang
Browse files
change mode insertion
parent
f95b3734
Changes
3
Hide whitespace changes
Inline
Side-by-side
question1.py
View file @
cbaad544
...
...
@@ -70,9 +70,9 @@ def mapFonction2 (x):
#Map reduce fonction
def
mapReduce_mmm
(
data
,
timeNB
,
targetNB
):
def
mapReduce_mmm
(
timeNB
,
targetNB
,
espace
):
results
=
dict
()
for
row
in
data
.
result
(
):
for
row
in
session
.
execute
(
"select * from caitiany.database_espace where station = '%s'"
%
espace
):
if
timeNB
==
1
:
data_time
=
row
[
timeNB
]
elif
timeNB
==
2
:
...
...
@@ -82,7 +82,7 @@ def mapReduce_mmm(data,timeNB,targetNB):
else
:
assert
1
==
2
,
"Doesn
\'
t exits!"
data_target
=
row
[
targetNB
]
if
str
(
data_time
)
==
'null'
or
str
(
data_target
)
==
'null'
:
if
str
(
data_time
)
==
'null'
or
data_target
==
None
:
continue
if
results
.
get
(
data_time
)
is
None
:
results
[
data_time
]
=
mapFonction1
(
data_target
)
...
...
@@ -103,8 +103,8 @@ def zipValues (values):
#Fonction 1: the history courbe graph
def
drawCourbe_history
(
session
,
time
,
target
,
timeNB
,
targetNB
,
espace
):
data
=
session
.
execute_async
(
"select * from caitiany.database_espace where station = '%s'"
%
espace
)
results
=
mapReduce_mmm
(
data
,
timeNB
,
targetNB
)
#
data = session.execute_async("select * from caitiany.database_espace where station = '%s'"%espace )
results
=
mapReduce_mmm
(
timeNB
,
targetNB
,
espace
)
keys
=
list
(
results
.
keys
())
values
=
list
(
results
.
values
())
zipped_result
=
zipValues
(
values
)
...
...
@@ -159,9 +159,9 @@ def caculateMean_Season(result):
#Draw the courbe of the fonction2
def
drawCourbe_season
(
session
,
season
,
target
,
targetNB
,
espace
):
data
=
session
.
execute_async
(
"select * from caitiany.database_espace where station = '%s'"
%
espace
)
#
data = session.execute_async("select * from caitiany.database_espace where station = '%s'"%espace )
#We do the same map reduce as fonction 1 by fixing the time as season
results
=
mapReduce_mmm
(
data
,
2
,
targetNB
)
results
=
mapReduce_mmm
(
2
,
targetNB
,
espace
)
results
=
seprateSeason
(
results
,
season
)
keys
=
list
(
results
.
keys
())
values
=
list
(
results
.
values
())
...
...
question2.py
View file @
cbaad544
...
...
@@ -29,14 +29,15 @@ def createMap(data):
"skyc1"
,
"skyc2"
,
"skyc3"
,
"skyc4"
,
"skyl1"
,
"skyl2"
,
"skyl3"
,
"skyl4"
,
"tmpf"
,
"vsby"
,
"wxcodes"
]
for
each
in
data
.
result
():
# print(each)
# Here we choose not to display the
"nan"
values and the METAR ID
l
=
[
attributes
[
i
]
+
":"
+
str
(
each
[
i
+
4
])
for
i
in
range
(
len
(
attributes
))
if
str
(
each
[
i
+
4
]
)
!=
'null'
# 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
and
attributes
[
i
]
!=
"metar"
]
string
=
'
\n
'
.
join
(
l
)
folium
.
Marker
([
each
[
2
],
each
[
1
]],
popup
=
string
,
icon
=
folium
.
Icon
(
color
=
'red'
)).
add_to
(
m
)
m
.
save
(
"Projet-NF26/map2.html"
)
print
(
"Generated successfully!"
)
if
__name__
==
"__main__"
:
...
...
@@ -46,5 +47,5 @@ if __name__ == "__main__":
time
=
input
(
"Please enter the time you want to search (format 'hh:MM:ss'):"
)
#timestamp = '2017-12-02 00:30:00'
timestamp
=
date
+
' '
+
time
data
=
session
.
execute_async
(
"select * from
meurouth_cql
.database_time where date = '%s' ALLOW FILTERING"
%
(
timestamp
))
data
=
session
.
execute_async
(
"select * from
caitiany
.database_time where date = '%s' ALLOW FILTERING"
%
(
timestamp
))
createMap
(
data
)
question3.py
View file @
cbaad544
...
...
@@ -74,11 +74,11 @@ def mapFonction2 (x):
#Map reduce to caculate the means of each station
def
mapReduce_kmeans
(
data
,
targetNB
):
def
mapReduce_kmeans
(
targetNB
,
start
,
end
):
results
=
dict
()
for
row
in
data
.
result
(
):
for
row
in
session
.
execute
(
"select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"
%
(
start
,
end
)
):
data_target
=
row
[
targetNB
]
if
str
(
data_target
)
==
'null'
:
if
data_target
==
None
:
continue
data_espace
=
(
row
[
1
],
row
[
2
],
row
[
3
])
if
results
.
get
(
data_espace
)
is
None
:
...
...
@@ -136,11 +136,11 @@ def MapnewCentre(x):
#The main algorithm of Kmeans
def
kmeans
(
data
,
targetNB
,
target
):
def
kmeans
(
targetNB
,
target
,
start
,
end
):
#cluster est pour stocler lat, lon de chaque point de chaque cluster
cluster
=
[[],[],[]]
result
=
mapReduce_kmeans
(
data
,
targetNB
)
result
=
mapReduce_kmeans
(
targetNB
,
start
,
end
)
if
len
(
result
)
<
3
:
raise
Exception
(
"We
\'
ve just searched less than 3 station!!"
)
...
...
@@ -261,5 +261,5 @@ if __name__ == "__main__":
targetNB
=
checkNBvariable
(
target
)
#start = '2008-12-19'
#end = '2012-12-14'
data
=
session
.
execute_async
(
"select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"
%
(
start
,
end
))
kmeans
(
data
,
targetNB
,
target
)
#
data = session.execute_async("select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"%(start,end))
kmeans
(
targetNB
,
target
,
start
,
end
)
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