def refresh_summary_acperiodcate(): userID = request.args.get('userID') startDate = request.args.get('startDate') endDate = request.args.get('endDate') modeDate = 2 from controls.GetJson_ACPeriodCate import GetJson_ACPeriodCate json_response = GetJson_ACPeriodCate(userID, modeDate, startDate, endDate) if 'errMsg' not in json_response: # 解包,翻译,打包 legendLabels = json_response['json_dateTrend']['legendLabels'] seriesData = json_response['json_dateTrend']['seriesData'] legendLabels = map(lambda x: helpers.translate(x), legendLabels) for datum in seriesData: datum['name'] = helpers.translate(datum['name']) json_response['json_dateTrend']['legendLabels'] = legendLabels json_response['json_dateTrend']['seriesData'] = seriesData legendLabels = json_response['json_timeDistribution']['legendLabels'] seriesData = json_response['json_timeDistribution']['seriesData'] legendLabels = map(lambda x: helpers.translate(x), legendLabels) for datum in seriesData: datum['name'] = helpers.translate(datum['name']) json_response['json_timeDistribution']['legendLabels'] = legendLabels json_response['json_timeDistribution']['seriesData'] = seriesData return jsonify(json_response)
def refresh_chart_concategory(): form = Form_Concategory() form.userID.data = request.args.get('userID') form.dateRange.data = request.args.get('dateRange') if not form.validate(): return jsonify(errMsg=form.errors['userID']) if not check_user_id(form.userID.data): return jsonify(errMsg=lstr.warn_userIDNon) userID = form.userID.data startDate = form.dateRange.data[:10] endDate = form.dateRange.data[-10:] from controls.GetJson_ConCategory import GetJson_ConCategory json_response = GetJson_ConCategory(userID, startDate, endDate) if 'errMsg' not in json_response: titles = json_response['titles'] seriesData = json_response['seriesData'] for datum in seriesData: datum['name'] = helpers.translate(datum['name']) titles = [helpers.translate(title) for title in titles] json_response['titles'] = titles json_response['seriesData'] = seriesData return jsonify(json_response)
def refresh_chart_acvalid(): form = Form_Acvalid() form.userID.data = request.args.get('userID') form.dateRange.data = request.args.get('dateRange') if not form.validate(): return jsonify(errMsg=form.errors['userID']) if not check_user_id(form.userID.data): return jsonify(errMsg=lstr.warn_userIDNon) userID = form.userID.data startDate = form.dateRange.data[:10] endDate = form.dateRange.data[-10:] from controls.GetJson_ACValid import GetJson_ACValid json_response = GetJson_ACValid(userID, startDate, endDate) if 'errMsg' not in json_response: titles = json_response['titles'] seriesData = json_response['seriesData'] titles = map(lambda x: helpers.translate(x), titles) for datum in seriesData: datum['name'] = helpers.translate(datum['name']) json_response['titles'] = titles json_response['seriesData'] = seriesData return jsonify(json_response)
def ac_overall(userID, startDate, endDate): # 不同门禁地点的数量 # 总门禁次数 # 地点信息:名称,次数,分类 sql = ( "SELECT node_des,COUNT(acrec.node_des)as con from acrec where user_id='%s' GROUP BY node_des ORDER BY con DESC" % (userID) ) # sql = db.session.query(acrec.node_des, func.count(acrec.node_des)).filter(acrec.user_id==userID) results = db.session.execute(sql).fetchall() if len(results) == 0: return {"count_nodes": -1, "total_count": -1, "ac_items": -1} node_des = [result.node_des for result in results] # 地点名 count = [result.con for result in results] # 地点门禁次数 node_cate = [] # 地点分类 total_count = sum(count) # 总门禁次数 ac_items = [] for i in xrange(len(node_des)): sql = db.session.query(ac_loc.category).filter(ac_loc.node_des == node_des[i]) # 查询地点的分类 node_cate.append(helpers.translate(sql.first())) # 翻译并加入 ac_items.append({"node_des": node_des[i], "count": count[i], "node_cate": node_cate[i]}) return {"count_nodes": len(node_des), "total_count": total_count, "ac_items": ac_items}
def refresh_chart_acperiodcate(): """Codes mainly in controls.ACPeriodCate.py. """ form = Form_Acperiodcate() form.userID.data = request.args.get('userID') form.dateRange.data = request.args.get('dateRange') form.modeDate.data = request.args.get('modeDate') if not form.validate(): return jsonify(errMsg=form.errors['userID']) if not check_user_id(form.userID.data): return jsonify(errMsg=lstr.warn_userIDNon) userID = form.userID.data startDate = form.dateRange.data[:10] endDate = form.dateRange.data[-10:] modeDate = int(form.modeDate.data) from controls.GetJson_ACPeriodCate import GetJson_ACPeriodCate json_response = GetJson_ACPeriodCate(userID,modeDate,startDate,endDate) if 'errMsg' not in json_response: # 解包,翻译,打包 legendLabels = json_response['json_dateTrend']['legendLabels'] seriesData = json_response['json_dateTrend']['seriesData'] legendLabels = map(lambda x: helpers.translate(x), legendLabels) for datum in seriesData: datum['name'] = helpers.translate(datum['name']) json_response['json_dateTrend']['legendLabels'] = legendLabels json_response['json_dateTrend']['seriesData'] = seriesData legendLabels = json_response['json_timeDistribution']['legendLabels'] seriesData = json_response['json_timeDistribution']['seriesData'] legendLabels = map(lambda x: helpers.translate(x), legendLabels) for datum in seriesData: datum['name'] = helpers.translate(datum['name']) json_response['json_timeDistribution']['legendLabels'] = legendLabels json_response['json_timeDistribution']['seriesData'] = seriesData return jsonify(json_response)
def refresh_summary_concategory(): userID = request.args.get('userID') startDate = request.args.get('startDate') endDate = request.args.get('startDate') from controls.GetJson_ConCategory import GetJson_ConCategory json_response = GetJson_ConCategory(userID, startDate, endDate) if 'errMsg' not in json_response: titles = json_response['titles'] seriesData = json_response['seriesData'] for datum in seriesData: datum['name'] = helpers.translate(datum['name']) titles = [helpers.translate(title) for title in titles] json_response['titles'] = titles json_response['seriesData'] = seriesData return jsonify(json_response)
def bill(userID, startDate, endDate): # 账单: 最近一月: # 消费类型比例 concategory, conablilty, expenditure # 一月消费总额 # init total_expend = -1 top_cate = "" con_per_month = -1 # Get total_expend 总支出 from GetJson_Expenditure import GetJson_expenditure json_Expenditure = GetJson_expenditure(userID, 0, 2, startDate, endDate) if "errMsg" not in json_Expenditure: dateTrend = json_Expenditure["json_dateTrend"] total_expend = dateTrend["accumulatedVals"][-1] # 消费分类排名 from GetJson_ConCategory import GetJson_ConCategory json_ConCategory = GetJson_ConCategory(userID, startDate, endDate) if "errMsg" not in json_ConCategory: con_items = json_ConCategory["seriesData"] top_cate = helpers.translate(con_items[0]["name"]) # [{'name': 'food', 'value': 2653.9}, {'name': 'shop', 'value': 177.5}, {'name': 'None', 'value': 56.5}, ...] # 消费能力 from GetJson_ConAbility import GetJson_ConAbility json_ConAbility = GetJson_ConAbility(userID) # 月均消费 if "errMsg" not in json_ConAbility: con_per_month = json_ConAbility["userAmount"] return {"total_expend": total_expend, "top_cate": top_cate, "con_per_month": con_per_month}