def delete_temp(self, request): """delete""" user_id = request.form.get("user_id", None) task_id = request.form.get("task_id", None) os.system("rm -rf ./temp/%s/%s" % (user_id, task_id)) result = {"user_id": user_id, "task_id": task_id} return output.normal_result(result)
def upload(self, request): """upload file""" user_id = request.form.get("user_id", None) task_id = request.form.get("task_id", None) filename = request.form.get("filename", None) task_log = request.form.get("task_log", None) try: filestream = request.files["file"] except Exception as e: filestream = None if not all([user_id, task_id, filestream, filename]): return output.error_result( -1, (user_id, task_id, str(filestream), filename)) try: os.listdir("./temp/%s/%s" % (user_id, task_id)) except: return output.error_result(-1, u"Task_id Error") try: filestream.save("./temp/%s/%s/%s" % (user_id, task_id, filename)) except: return output.error_result( -1, u"Shard_file upload Error-->[%s]" % filename) result = { "user_id": user_id, "task_id": task_id, "filename": filename, "task_log": task_log } return output.normal_result(result)
def trend(self, request): start_time = request.args.get("start_time", None) end_time = request.args.get("end_time", None) collection = "carno" app_id = request.args.get("app_id", None) station_id = request.args.get("station_id", None) plot = request.args.get("plot", None) interval = request.args.get("interval", None) filename = "start_time=%s|end_time=%s|app_id=%s|interval=%s" % ( str(start_time), str(end_time), str(app_id), str(interval)) path = "./data/%s.png" % filename if not plot: plot = False else: plot = True m = cal.MongoQuery(start_time=start_time, end_time=end_time, collection=collection) result = m.get_trend(app_id, station_id=station_id, interval=interval, plot=plot, path=path) if plot: result = { "trend": list(result), "down_picture": "/data/%s.png" % filename } else: result = {"trend": list(result)} return output.normal_result(result)
def get_task_id(self, request): """get task id""" user_id = request.form.get("user_id", None) task_log = request.form.get("task_log", None) os.system("mkdir -p ./data/%s/%s" % (user_id, task_log)) task_id = str(time.time()) os.system("mkdir -p ./temp/%s/%s" % (user_id, task_id)) result = {"user_id": user_id, "task_id": task_id, "task_log": task_log} return output.normal_result(result)
def order(self, request): """""" start_time = request.args.get("start_time", None) end_time = request.args.get("end_time", None) collection = "carno" app_id = request.args.get("app_id", None) station_id = request.args.get("station_id", None) m = cal.MongoQuery(start_time=start_time, end_time=end_time, collection=collection) result = m.get_order(app_id, station_id=station_id) result = {"order_Number": result} return output.normal_result(result)
def flow(self, request): start_time = request.args.get("start_time", None) end_time = request.args.get("end_time", None) collection = "carno" app_id = request.args.get("app_id", None) station_id = request.args.get("station_id", None) freq = request.args.get("freq", None) if not freq: freq = False else: freq = True m = cal.MongoQuery(start_time=start_time, end_time=end_time, collection=collection) result = m.Flow(app_id, station_id=station_id, freq=freq) result = {"flowTo": list(result)} return output.normal_result(result)
def merge(self, request): """merge""" user_id = request.form.get("user_id", None) task_id = request.form.get("task_id", None) filename = request.form.get("filename", None) task_log = request.form.get("task_log", None) if not all([user_id, task_id, filename]): os.system("rm -rf ./temp/%s/%s" % (user_id, task_id)) return output.error_result(-1, u"Argument Error") try: os.listdir("./temp/%s/%s" % (user_id, task_id)) except: os.system("rm -rf ./temp/%s/%s" % (user_id, task_id)) return output.error_result(-1, u"Task_id Error") file_list = os.listdir("./temp/%s/%s" % (user_id, task_id)) if file_list: rename_file = os.listdir("./data/%s/%s/" % (user_id, task_log)) if filename in rename_file: now = time.time() os.system("mv ./data/%s/%s/%s ./data/%s/%s/%s_%s" % (user_id, task_log, filename, user_id, task_log, filename, now)) file_list.sort() for one in file_list: os.system("cat ./temp/%s/%s/%s >> ./data/%s/%s/%s" % (user_id, task_id, one, user_id, task_log, filename)) else: os.system("rm -rf ./temp/%s/%s" % (user_id, task_id)) return output.error_result(-1, u"No file to merge") result = { "user_id": user_id, "task_id": task_id, "filename": filename, "task_log": task_log } os.system("rm -rf ./temp/%s/%s" % (user_id, task_id)) return output.normal_result(result)
def panda_test(self, request): return output.normal_result("Welcome to use panda data")