Commit 92b2a863 authored by Tianyang's avatar Tianyang
Browse files

Add commentaire

parent f0029c0c
...@@ -6,7 +6,7 @@ import re ...@@ -6,7 +6,7 @@ import re
def connection(): def connection():
import cassandra.cluster import cassandra.cluster
cluster = cassandra.cluster.Cluster(['localhost']) cluster = cassandra.cluster.Cluster(['localhost'])
session = cluster.connect('meurouth_cql') session = cluster.connect('caitiany')
return session return session
def databaseCreate_Q2(session): def databaseCreate_Q2(session):
...@@ -143,7 +143,7 @@ def insertion_sql_Q2(filename,session): ...@@ -143,7 +143,7 @@ def insertion_sql_Q2(filename,session):
data["metar"]) data["metar"])
query = """ query = """
INSERT INTO database_time( INSERT INTO database_kmeans(
date, date,
lon, lon,
lat, lat,
......
...@@ -140,6 +140,7 @@ def drawCourbe_history(session,time,target,timeNB,targetNB,espace): ...@@ -140,6 +140,7 @@ def drawCourbe_history(session,time,target,timeNB,targetNB,espace):
print ("Generate successfully") print ("Generate successfully")
#Check which number of the indicateur
def checkNBvariable (x): def checkNBvariable (x):
i=0 i=0
for each in table_variable: for each in table_variable:
...@@ -160,7 +161,7 @@ def caculateMean_Season(result): ...@@ -160,7 +161,7 @@ def caculateMean_Season(result):
i += 1 i += 1
return total/i , i return total/i , i
#Draw the courbe of the fonction2
def drawCourbe_season(session,season,target,targetNB,espace): 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 #We do the same map reduce as fonction 1 by fixing the time as season
......
...@@ -36,7 +36,7 @@ def createMap(data): ...@@ -36,7 +36,7 @@ def createMap(data):
folium.Marker([each[2],each[1]], folium.Marker([each[2],each[1]],
popup=string, popup=string,
icon=folium.Icon(color='red')).add_to(m) icon=folium.Icon(color='red')).add_to(m)
m.save("Projet-NF26/map.html") m.save("Projet-NF26/map2.html")
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -72,12 +72,12 @@ def mapFonction1 (x): ...@@ -72,12 +72,12 @@ def mapFonction1 (x):
def mapFonction2 (x): def mapFonction2 (x):
return x[1]/x[0] return x[1]/x[0]
#Test if it is a type mean
def testNan (x): def testNan (x):
test = x != x test = x != x
return test return test
#Map reduce to caculate the means of each station
def mapReduce_kmeans(data,targetNB): def mapReduce_kmeans(data,targetNB):
results = dict() results = dict()
for row in data.result(): for row in data.result():
...@@ -94,7 +94,7 @@ def mapReduce_kmeans(data,targetNB): ...@@ -94,7 +94,7 @@ def mapReduce_kmeans(data,targetNB):
results[eachEspace] = mapFonction2(results[eachEspace]) results[eachEspace] = mapFonction2(results[eachEspace])
return results return results
#Caculate the difference of the number of the clusters
def cluster_nb_diff(centre_new,centre): def cluster_nb_diff(centre_new,centre):
sum = 0 sum = 0
for i in range(3): for i in range(3):
...@@ -110,9 +110,8 @@ def map1_kmeans(x): ...@@ -110,9 +110,8 @@ def map1_kmeans(x):
def mapCentre(x): def mapCentre(x):
return [x[0],x[1],x[2],0] 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): def reduceKmeans (x,y):
result = [] result = []
for i in range(4): for i in range(4):
...@@ -132,7 +131,7 @@ def map2_kmeans(x): ...@@ -132,7 +131,7 @@ def map2_kmeans(x):
#Update the new center by means
def MapnewCentre(x): def MapnewCentre(x):
if x[0] != 0: if x[0] != 0:
return x[1]/x[0] return x[1]/x[0]
...@@ -140,7 +139,7 @@ def MapnewCentre(x): ...@@ -140,7 +139,7 @@ def MapnewCentre(x):
return 0 return 0
#The main algorithm of Kmeans
def kmeans (data,targetNB,target): def kmeans (data,targetNB,target):
#cluster est pour stocler lat, lon de chaque point de chaque cluster #cluster est pour stocler lat, lon de chaque point de chaque cluster
cluster = [[],[],[]] cluster = [[],[],[]]
...@@ -205,7 +204,6 @@ def kmeans (data,targetNB,target): ...@@ -205,7 +204,6 @@ def kmeans (data,targetNB,target):
else: else:
#caculate the new centre #caculate the new centre
print ("Cluster number differ: ",cluster_nb_diff(centre_new,centre)) print ("Cluster number differ: ",cluster_nb_diff(centre_new,centre))
print (centre_new)
for eachculster in centre_new: for eachculster in centre_new:
centre_new[eachculster][1] = MapnewCentre(centre_new[eachculster]) centre_new[eachculster][1] = MapnewCentre(centre_new[eachculster])
print("center new: ",centre_new) print("center new: ",centre_new)
...@@ -216,7 +214,7 @@ def kmeans (data,targetNB,target): ...@@ -216,7 +214,7 @@ def kmeans (data,targetNB,target):
cluster = [[],[],[]] cluster = [[],[],[]]
createMap(cluster,result) createMap(cluster,result)
#Create the map of the cluster
def createMap (cluster,result): def createMap (cluster,result):
mean_lat = 0 mean_lat = 0
count = 0 count = 0
...@@ -245,12 +243,11 @@ def createMap (cluster,result): ...@@ -245,12 +243,11 @@ def createMap (cluster,result):
popup=label, popup=label,
icon=folium.Icon(color=color[i])).add_to(m) icon=folium.Icon(color=color[i])).add_to(m)
i +=1 i +=1
print(i)
m.save("Projet-NF26/map.html") m.save("Projet-NF26/map.html")
print("Generate successfully") print("Generate successfully")
#Check which number of the indicateur
def checkNBvariable (x): def checkNBvariable (x):
i=0 i=0
for each in table_variable: for each in table_variable:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment