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
92b2a863
Commit
92b2a863
authored
Jun 21, 2019
by
Tianyang
Browse files
Add commentaire
parent
f0029c0c
Changes
4
Show whitespace changes
Inline
Side-by-side
database_pre2.py
View file @
92b2a863
...
...
@@ -6,7 +6,7 @@ import re
def
connection
():
import
cassandra.cluster
cluster
=
cassandra
.
cluster
.
Cluster
([
'localhost'
])
session
=
cluster
.
connect
(
'
meurouth_cql
'
)
session
=
cluster
.
connect
(
'
caitiany
'
)
return
session
def
databaseCreate_Q2
(
session
):
...
...
@@ -143,7 +143,7 @@ def insertion_sql_Q2(filename,session):
data
[
"metar"
])
query
=
"""
INSERT INTO database_
time
(
INSERT INTO database_
kmeans
(
date,
lon,
lat,
...
...
question1.py
View file @
92b2a863
...
...
@@ -140,6 +140,7 @@ def drawCourbe_history(session,time,target,timeNB,targetNB,espace):
print
(
"Generate successfully"
)
#Check which number of the indicateur
def
checkNBvariable
(
x
):
i
=
0
for
each
in
table_variable
:
...
...
@@ -160,7 +161,7 @@ def caculateMean_Season(result):
i
+=
1
return
total
/
i
,
i
#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
)
#We do the same map reduce as fonction 1 by fixing the time as season
...
...
question2.py
View file @
92b2a863
...
...
@@ -36,7 +36,7 @@ def createMap(data):
folium
.
Marker
([
each
[
2
],
each
[
1
]],
popup
=
string
,
icon
=
folium
.
Icon
(
color
=
'red'
)).
add_to
(
m
)
m
.
save
(
"Projet-NF26/map.html"
)
m
.
save
(
"Projet-NF26/map
2
.html"
)
if
__name__
==
"__main__"
:
...
...
question3.py
View file @
92b2a863
...
...
@@ -72,12 +72,12 @@ def mapFonction1 (x):
def
mapFonction2
(
x
):
return
x
[
1
]
/
x
[
0
]
#Test if it is a type mean
def
testNan
(
x
):
test
=
x
!=
x
return
test
#Map reduce to caculate the means of each station
def
mapReduce_kmeans
(
data
,
targetNB
):
results
=
dict
()
for
row
in
data
.
result
():
...
...
@@ -94,7 +94,7 @@ def mapReduce_kmeans(data,targetNB):
results
[
eachEspace
]
=
mapFonction2
(
results
[
eachEspace
])
return
results
#Caculate the difference of the number of the clusters
def
cluster_nb_diff
(
centre_new
,
centre
):
sum
=
0
for
i
in
range
(
3
):
...
...
@@ -110,9 +110,8 @@ def map1_kmeans(x):
def
mapCentre
(
x
):
return
[
x
[
0
],
x
[
1
],
x
[
2
],
0
]
#input [tmpt,tmpt,tmpt,tmpt] and [c1,c2,c3,0] -> [|tmpt - c1|,|tmpt - c2|,|tmpt - c3|,tmpt]
#input [tmpt,tmpt,tmpt,tmpt] and [c1,c2,c3,0] -> [|tmpt - c1|,|tmpt - c2|,|tmpt - c3|,tmpt]
def
reduceKmeans
(
x
,
y
):
result
=
[]
for
i
in
range
(
4
):
...
...
@@ -132,7 +131,7 @@ def map2_kmeans(x):
#Update the new center by means
def
MapnewCentre
(
x
):
if
x
[
0
]
!=
0
:
return
x
[
1
]
/
x
[
0
]
...
...
@@ -140,7 +139,7 @@ def MapnewCentre(x):
return
0
#The main algorithm of Kmeans
def
kmeans
(
data
,
targetNB
,
target
):
#cluster est pour stocler lat, lon de chaque point de chaque cluster
cluster
=
[[],[],[]]
...
...
@@ -205,7 +204,6 @@ def kmeans (data,targetNB,target):
else
:
#caculate the new centre
print
(
"Cluster number differ: "
,
cluster_nb_diff
(
centre_new
,
centre
))
print
(
centre_new
)
for
eachculster
in
centre_new
:
centre_new
[
eachculster
][
1
]
=
MapnewCentre
(
centre_new
[
eachculster
])
print
(
"center new: "
,
centre_new
)
...
...
@@ -216,7 +214,7 @@ def kmeans (data,targetNB,target):
cluster
=
[[],[],[]]
createMap
(
cluster
,
result
)
#Create the map of the cluster
def
createMap
(
cluster
,
result
):
mean_lat
=
0
count
=
0
...
...
@@ -245,12 +243,11 @@ def createMap (cluster,result):
popup
=
label
,
icon
=
folium
.
Icon
(
color
=
color
[
i
])).
add_to
(
m
)
i
+=
1
print
(
i
)
m
.
save
(
"Projet-NF26/map.html"
)
print
(
"Generate successfully"
)
#Check which number of the indicateur
def
checkNBvariable
(
x
):
i
=
0
for
each
in
table_variable
:
...
...
Write
Preview
Supports
Markdown
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