def getMostComm(type): db.dbName =DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] word_list = [] print(db_view) hasrows = True rowperpage = 300 page = 0 startid = " " most_comm = [] returndata = [] while hasrows: skip = 0 if page == 0 else 1 page+=1 data = db.query(db_view,rowperpage,skip,startid) if len(data)==0: break else: startid = data.rows[-1].value["id"] for words in data.rows: for singleword in words.value["correction"].split(): if singleword not in excluded_Words: most_comm.append((singleword)) data ={ 'rows':[{'text': key, 'weight': val} for (key, val) in Counter(most_comm).most_common(20)] } #print(db_view) #print(data) ##### present the data based on the most_common return jsonify(data)
def getScatterData(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] counter = Counter() resultsCount = Counter() data = None # "Percentage" needs to query by group if str(type).lower() =="percentage": data =list(db.getAllViewData(db_view,True)) else: data = list(db.getAllViewData(str(db_view))) test = 0 for rows in data: if rows.value: counter[rows.value] += 1 #print(rows.value) test+=1 data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Score', 'number'), ('Count', 'number')])), 'rows': [{'c': [{'v': key}, {'v': val}]} for (key, val) in counter.items()] } return jsonify(data)
def getTrendData(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] listdata =[] data = None test = 0 # "Percentage" needs to query by group if str(type).lower() =="percentage": data =list(db.getAllViewData(db_view,True)) else: data = list(db.getAllViewData(str(db_view))) for rows in data: if rows.value["sentiment"]["senti_Polarity"] >0: listdata.append([convertTime(rows.value["time"]),"pos"]) test+=1 elif rows.value["sentiment"]["senti_Polarity"] ==0: #listdata.append([convertTime(rows.value["time"]),"neu"]) test+=1 else: listdata.append([convertTime(rows.value["time"]),"neg"]) test+=1 # make list to be a three dimensional list ("2014-08-11",5,5 ) templist = list(Counter([tuple(l) for l in listdata]).items()) multituples = sorted(templist,key=lambda x:x[0][0]) tempTime = "" tempPosCount = 0 tempNegCount =0 sentimentList = [] for sentimentData in multituples: if tempTime == "" or tempTime == sentimentData[0][0]: if sentimentData[0][1] == "pos": tempPosCount = sentimentData[1] elif sentimentData[0][1] == "neg": tempNegCount = sentimentData[1] tempTime = sentimentData[0][0] else: sentimentList.append({'c': [{'v': tempTime}, {'v': tempPosCount},{'v': tempNegCount}]}) tempPosCount = 0 tempNegCount = 0 tempTime = sentimentData[0][0] if sentimentData[0][1] == "pos": tempPosCount = sentimentData[1] elif sentimentData[0][1] == "neg": tempNegCount = sentimentData[1] data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Year', 'string'), ('pos', 'number'),('neg', 'number')])), 'rows': sentimentList } #print(sentimentList) return jsonify(data)
def getHousePricewithRenterPayment(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] data = list(db.getAllViewData(db_view)) rows = [{'c': [{'v': rows.value["date"]}, {'v': rows.value["ratio"]},{'v': rows.value["attribute"]['renter_payment']},{'v': rows.value["attribute"]['houseprice']}]} for rows in data] data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Year', 'string'),('House Price Rent Ratio', 'number'), ('Annual renter payment', 'number'), ('House price', 'number')])), 'rows': rows } #print(data) return jsonify(data)
def getHousePriceIncomeRatio(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] data = list(db.getAllViewData(db_view)) rows = [{'c': [{'v': converTimeISO8601(rows.value["date"])}, {'v': rows.value["ratio"]},{'v': rows.value["attribute"]['Annual_income']},{'v': rows.value["attribute"]['houseprice']}]} for rows in data] data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Year', 'string'),('House-price-income-ratio', 'number'), ('Annual Income', 'number'), ('House price', 'number')])), 'rows': rows } # print(data) return jsonify(data)
def getBubbleHousingIndex(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] data = list(db.getAllViewData(db_view)) rows = [{'c': [{'v': converTimeISO8601(rows.value["date"])}, {'v': rows.value["index"]}]} for rows in data] data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Year', 'string'), ('index', 'number'),])), 'rows': rows } #print(data) return jsonify(data)
def getIndividSentiemntResult(type): db.dbName = DBMapping.get(str(type).lower(),lambda: "nothing")()["DB_Name"] listdata =[] db_view = DBMapping.get(str(type).lower(),lambda: "nothing")()["view_Name"] data = list(db.getAllViewData(str(db_view))) #print(len(data)) rows = [{'c': [{'v': convertTimeToDate(rows.value["time"])}, {'v': rows.value["text"]},{'v': rows.value["sentiment"]["perception"]}]} for rows in data] #rows = [[convertTimeToDate(rows.value["time"]),rows.value["text"],rows.value["sentiment"]["perception"]] for rows in data] data = { 'cols': list(map(lambda x: {'id': x[0], 'label': x[0], 'type': x[1]}, [('Year', 'date'), ('text', 'string'),('sentiment', 'string')])), 'rows': rows } #print(data) return jsonify(data)
def sMostCommonByKeyWord(type): db_view = DBMapping.get(str(type).lower(),lambda: "nothing")() searchword = request.args["searchword"] if "searchword" in request.args else "None" data = [] hasrows = True rowperpage = 300 page = 0 startid = " " most_comm = [] #print(db_view) while hasrows: skip = 0 if page == 0 else 1 page+=1 rows = [ x["value"] for x in db.query(db_view,rowperpage,skip,startid).rows if str(x["value"]["text"]).find(searchword)!= -1] if len(rows)==0: break else: startid =rows[-1]["id"] data.append(rows) return jsonify({"data":data})