Commit 92b2a863 authored by Tianyang's avatar Tianyang

Add commentaire

parent f0029c0c
......@@ -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,
......
......@@ -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
......
......@@ -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/map2.html")
if __name__ == "__main__":
......
......@@ -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:
......
Markdown is supported
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