Commit cbaad544 authored by Tianyang's avatar Tianyang
Browse files

change mode insertion

parent f95b3734
...@@ -70,9 +70,9 @@ def mapFonction2 (x): ...@@ -70,9 +70,9 @@ def mapFonction2 (x):
#Map reduce fonction #Map reduce fonction
def mapReduce_mmm(data,timeNB,targetNB): def mapReduce_mmm(timeNB,targetNB,espace):
results = dict() results = dict()
for row in data.result(): for row in session.execute("select * from caitiany.database_espace where station = '%s'"%espace ):
if timeNB == 1: if timeNB == 1:
data_time = row[timeNB] data_time = row[timeNB]
elif timeNB == 2: elif timeNB == 2:
...@@ -82,7 +82,7 @@ def mapReduce_mmm(data,timeNB,targetNB): ...@@ -82,7 +82,7 @@ def mapReduce_mmm(data,timeNB,targetNB):
else: else:
assert 1==2, "Doesn\'t exits!" assert 1==2, "Doesn\'t exits!"
data_target = row[targetNB] data_target = row[targetNB]
if str(data_time) == 'null' or str(data_target) == 'null': if str(data_time) == 'null' or data_target == None:
continue continue
if results.get(data_time) is None: if results.get(data_time) is None:
results[data_time] = mapFonction1(data_target) results[data_time] = mapFonction1(data_target)
...@@ -103,8 +103,8 @@ def zipValues (values): ...@@ -103,8 +103,8 @@ def zipValues (values):
#Fonction 1: the history courbe graph #Fonction 1: the history courbe graph
def drawCourbe_history(session,time,target,timeNB,targetNB,espace): def drawCourbe_history(session,time,target,timeNB,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 )
results = mapReduce_mmm(data,timeNB,targetNB) results = mapReduce_mmm(timeNB,targetNB,espace)
keys = list(results.keys()) keys = list(results.keys())
values = list(results.values()) values = list(results.values())
zipped_result = zipValues(values) zipped_result = zipValues(values)
...@@ -159,9 +159,9 @@ def caculateMean_Season(result): ...@@ -159,9 +159,9 @@ def caculateMean_Season(result):
#Draw the courbe of the fonction2 #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
results = mapReduce_mmm(data,2,targetNB) results = mapReduce_mmm(2,targetNB,espace)
results = seprateSeason(results,season) results = seprateSeason(results,season)
keys = list(results.keys()) keys = list(results.keys())
values = list(results.values()) values = list(results.values())
......
...@@ -29,14 +29,15 @@ def createMap(data): ...@@ -29,14 +29,15 @@ def createMap(data):
"skyc1", "skyc2", "skyc3", "skyc4", "skyl1", "skyl2", "skyl3", "skyl4", "tmpf", "vsby", "wxcodes"] "skyc1", "skyc2", "skyc3", "skyc4", "skyl1", "skyl2", "skyl3", "skyl4", "tmpf", "vsby", "wxcodes"]
for each in data.result(): for each in data.result():
# print(each) # print(each)
# Here we choose not to display the "nan" values and the METAR ID # 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 str(each[i + 4]) != 'null' l = [attributes[i] + ":" + str(each[i + 4]) for i in range(len(attributes)) if each[i + 4] != None
and attributes[i] != "metar"] and attributes[i] != "metar"]
string='\n'.join(l) string='\n'.join(l)
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/map2.html") m.save("Projet-NF26/map2.html")
print("Generated successfully!")
if __name__ == "__main__": if __name__ == "__main__":
...@@ -46,5 +47,5 @@ if __name__ == "__main__": ...@@ -46,5 +47,5 @@ if __name__ == "__main__":
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:ss'):")
#timestamp = '2017-12-02 00:30:00' #timestamp = '2017-12-02 00:30:00'
timestamp = date + ' ' + time 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) createMap(data)
...@@ -74,11 +74,11 @@ def mapFonction2 (x): ...@@ -74,11 +74,11 @@ def mapFonction2 (x):
#Map reduce to caculate the means of each station #Map reduce to caculate the means of each station
def mapReduce_kmeans(data,targetNB): def mapReduce_kmeans(targetNB,start,end):
results = dict() 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] data_target = row[targetNB]
if str(data_target) == 'null': if data_target == None:
continue continue
data_espace = (row[1],row[2],row[3]) data_espace = (row[1],row[2],row[3])
if results.get(data_espace) is None: if results.get(data_espace) is None:
...@@ -136,11 +136,11 @@ def MapnewCentre(x): ...@@ -136,11 +136,11 @@ def MapnewCentre(x):
#The main algorithm of Kmeans #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 est pour stocler lat, lon de chaque point de chaque cluster
cluster = [[],[],[]] cluster = [[],[],[]]
result = mapReduce_kmeans(data,targetNB) result = mapReduce_kmeans(targetNB,start,end)
if len(result) < 3: if len(result) < 3:
raise Exception ("We\'ve just searched less than 3 station!!") raise Exception ("We\'ve just searched less than 3 station!!")
...@@ -261,5 +261,5 @@ if __name__ == "__main__": ...@@ -261,5 +261,5 @@ if __name__ == "__main__":
targetNB = checkNBvariable(target) targetNB = checkNBvariable(target)
#start = '2008-12-19' #start = '2008-12-19'
#end = '2012-12-14' #end = '2012-12-14'
data = session.execute_async("select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"%(start,end)) #data = session.execute_async("select * from caitiany.database_kmeans where date >= '%s' and date <= '%s' ALLOW FILTERING"%(start,end))
kmeans(data,targetNB,target) kmeans(targetNB,target,start,end)
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