Commit ec24abd2 authored by Tianyang's avatar Tianyang
Browse files

Change database1

parent 57136175
No preview for this file type
import cassandra.cluster
def countData(database,session):
years = [i for i in range(2008,2018)]
for year in years:
count = 0
number = session.execute_async("select year from caitiany.%s where year = %d ALLOW FILTERING" %(database,year))
for row in number.result():
count += 1
print (year,' has ',count,' datas.\n')
if __name__ == "__main__":
cluster = cassandra.cluster.Cluster(['localhost'])
session = cluster.connect('caitiany')
countData('database_espace',session)
\ No newline at end of file
......@@ -14,7 +14,7 @@ def databaseCreate_Q1(session):
CREATE TABLE database_espace (
station varchar,
year int,
season varchar,
season int,
month int,
day int,
hour int,
......@@ -64,13 +64,13 @@ def load_data(filename):
time = match_time.groupdict()
#add season
if 3<=int(time["month"])<=5:
r["season"]="Spring"
r["season"]=0
elif 6<=int(time["month"])<=8:
r["season"]="Summer"
r["season"]=1
elif 9<=int(time["month"])<=11:
r["season"]="Autumn"
r["season"]=2
elif int(time["month"]) in (12,1,2):
r["season"]="Winter"
r["season"]=3
else:
continue
......@@ -81,7 +81,7 @@ def load_data(filename):
data = {}
data["station"] = r["station"]
data["year"] = int(time["year"])
data["season"] = r["season"]
data["season"] = int(r["season"])
data["month"] = int(time["month"])
data["day"] = int(time["day"])
data["hour"] = int(time["hour"])
......
......@@ -114,6 +114,14 @@ def drawCourbe_history(session,time,target,timeNB,targetNB,espace):
each = list(each)
if timeNB == 2:
each[0] = str(each[0])
if each[1] == 0:
each[1] = "Spring"
elif each[1] == 1:
each[1] = "Summer"
elif each[1] == 2:
each[1] = "Autumn"
elif each[1] == 3:
each[1] = "Winter"
keys[index_each] = ".".join(each)
elif timeNB == 3:
each[0] = str(each[0])
......@@ -170,6 +178,14 @@ def drawCourbe_season(session,season,target,targetNB,espace):
index_each = keys.index(each)
each = list(each)
each[0] = str(each[0])
if each[1] == 0:
each[1] = "Spring"
elif each[1] == 1:
each[1] = "Summer"
elif each[1] == 2:
each[1] = "Autumn"
elif each[1] == 3:
each[1] = "Winter"
keys[index_each] = ".".join(each)
fig, ax = plt.subplots(1, 1)
......@@ -196,6 +212,14 @@ def drawCourbe_season(session,season,target,targetNB,espace):
#Choose the data of the season we want
def seprateSeason (results,season):
output = dict()
if season == "Spring":
season = 0
elif season == "Summer":
season = 1
elif season == "Autumn":
season = 2
elif season == "Winter":
season = 3
for each in results:
if season in each:
output[each] = results[each]
......
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