def __save_foreflow_biz(self, idforeflows, indicator): sqlflows = [] for id, flows in idforeflows.items(): for flow in flows: sqlflows.append((id, indicator, flow[1], flow[2], flow[3], flow[0].strftime("%Y-%m-%d %H:%M:%S"))) get_res_dao().executeInsert(self.__insert_result(), sqlflows)
def __query_hisflow_biz(self, bizids): __sql = self.__create_query(bizids) bizIdToSendAvgFlow = dict() bizIdToSendMaxFlow = dict() bizIdToRecevieAvgFlow = dict() bizIdToRecevieMaxFlow = dict() for id in bizids: bizIdToSendAvgFlow[id] = dict() bizIdToSendMaxFlow[id] = dict() bizIdToRecevieAvgFlow[id] = dict() bizIdToRecevieMaxFlow[id] = dict() try: results = get_res_dao().executeQuery(sql=__sql, param="None") for row in results: bizid = row[0] time = row[5].isoformat() bizIdToSendAvgFlow.get(bizid).setdefault(time, row[1]) bizIdToSendMaxFlow.get(bizid).setdefault(time, row[2]) bizIdToRecevieAvgFlow.get(bizid).setdefault(time, row[3]) bizIdToRecevieMaxFlow.get(bizid).setdefault(time, row[4]) except Exception as e: logging.error("exception:%s" % e) logging.error("Error: unable to fecth data") return bizIdToSendAvgFlow, bizIdToSendMaxFlow, bizIdToRecevieAvgFlow, bizIdToRecevieMaxFlow
def biz_flow_predicted(ids): print(ids) __sql = """CREATE TABLE t_forecastbizflow( emsid BIGINT NOT NULL, bizid BIGINT NOT NULL, indicator BIGINT NOT NULL, yhat DOUBLE NOT NULL, yhat_lower DOUBLE NOT NULL, yhat_upper DOUBLE NOT NULL, predicted_time TIMESTAMP NOT NULL, PRIMARY KEY (emsid,bizid,indicator,predicted_time)) ENGINE = MYISAM;""" get_res_dao().executeQuery("DROP TABLE IF EXISTS t_forecastbizflow;", param="None") get_res_dao().executeQuery(sql=__sql, param="None") logging.info("begin biz flow predicted...!@###") predict = EmsBizFlowPredict(10000, 30) predict.predict_biz_flow(ids) logging.info("end biz flow predicted...") return 0
def __query_hisflow_port(self, ports): portToFlow = dict() for port in ports: portToFlow[port] = dict() for month in range(1, 12): __sql = self.__create_query(month, ports) try: # 执行SQL语句 results = get_res_dao().executeQuery(sql=__sql, param="None") for row in results: port = Port(self.emsid, row[0], row[1], row[2], row[3], row[4]) time = row[9].isoformat() portToFlow.get(port).setdefault( time, [row[5], row[6], row[7], row[8]]) except Exception as e: logging.error("exception:%s" % e) logging.error("Error: unable to fecth data") return portToFlow