def newtask(): data = request.get_json() msg = Task.checkData(data) if not msg == "": return jsonify({"code" : "err", "msg" : msg}) else : task = Task.newTask(data) return jsonify({"code" : "success", "task" : task.dict()})
def task(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : return jsonify({"task" : task.getInfo()}) else : return jsonify({"code" : "err", "msg" : "No task"})
def submitters(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : return jsonify({"submitters" : task.getSubmitters()}) else : return jsonify({"code" : "err", "msg" : "No task"})
def sbsubmitoriginal(): data = request.form task = Task.getTask(data["prefix"]) user = User.getUser(session["userid"]) original = task.getOriginal(data["id"]) try: if request.files["file"].filename[-3:] == "csv": csv = request.files["file"].stream original.loadcsv( user, csv, original.getNextnth(user), datetime.strptime(data["duration_start"], "%a %b %d %Y").date(), datetime.strptime(data["duration_end"], "%a %b %d %Y").date(), ) elif request.files["file"].filename[-4:] == "xlsx": xlsx = request.files["file"].stream original.loadxlsx( user, xlsx, original.getNextnth(user), datetime.strptime(data["duration_start"], "%a %b %d %Y").date(), datetime.strptime(data["duration_end"], "%a %b %d %Y").date(), ) else: return jsonify({"code": "err", "msg": "Wrong extension"}) except: return jsonify({"code": "err", "msg": "Wrong extension"}) return jsonify({"code": "success"})
def changesubmitterstatus(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : task.changeSubmitterStatus(data["id"],data["status"]) return jsonify({"code" :"success"}) else : return jsonify({"code" : "err", "msg" : "No task"})
def evparsed(): data = request.get_json() task = Task.getTask(data["prefix"]) parsed = task.getParsed(data["id"]) return jsonify({"parsed": parsed.dict(), "task": task.dict()})
def neworiginal(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : msg = Task.checkOriginal(data) if msg != "" : return jsonify({"code" : "err", "msg" : msg}) else : original = task.newOriginal(data["length"],data["name"],data["schemas"]) return jsonify({"code" : "success", "task" : original.dict()}) else : return jsonify({"code" : "err", "msg" : "No task"}) return ""
def taskstatus(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : task.setStatus(data["status"]) return jsonify({"code" : "success","task" : task.getInfo()}) else : return jsonify({"code" : "err", "msg" : "No task"})
def sbparsedlist(): data = request.get_json() task = Task.getTask(data["prefix"]) user = User.getUser(session["userid"]) parsedlist = task.getParsedBySubmitter(user) if task: return jsonify({"code": "success", "parsedlist": map(lambda x: x.dict(), parsedlist)}) else: return jsonify({"code": "err", "msg": "No task"})
def getfile(prefix, id): task = Task.getTask(prefix) parsed = task.getParsed(id) response = make_response(parsed.file) response.headers["Content-type"] = "text/csv" response.headers["Content-Disposition"] = "attachment; filename=parsingdatasequence.csv" return response
def sboriginal(): data = request.get_json() task = Task.getTask(data["prefix"]) user = User.getUser(session["userid"]) original = task.getOriginal(data["id"]) if task: json = original.getInfoByUser(user) return jsonify({"code": "success", "original": json}) else: return jsonify({"code": "err", "msg": "No task"})
def showparseds(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : return jsonify({"code" : "success", "parsedlist" : map(lambda x : x.dict(), task.getParseds())}) else : return jsonify({"code" : "err", "msg" : "No task"}) return ""
def showoriginals(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : originallist = map(lambda x : x.getInfo(), task.getOriginals()) return jsonify({"code" : "success", "originallist" : originallist}) else : return jsonify({"code" : "err", "msg" : "No task"}) return ""
def userparsds(): data = request.get_json() return jsonify({"parsedlist" : Task.getEvaluateAll(data["id"])})
def evsubmitevaluate(): data = request.get_json() task = Task.getTask(data["prefix"]) parsed = task.getParsed(data["id"]) if data["pass"]: parsed.evaluate(data["score"], "Pass") user = User.getUser(parsed.submitterid).setScore() parsed.insertcsv() else: parsed.evaluate(data["score"], "Nonpass") return jsonify({"code": "success"})
def showtupples(): data = request.get_json() task = Task.getTask(data["prefix"]) if task : tupples = task.getTupples() tupples["code"] = "success" return jsonify(tupples) else : return jsonify({"code" : "err", "msg" : "No task"}) return ""
def sbapply(): data = request.get_json() task = Task.getTask(data["prefix"]) user = User.getUser(session["userid"]) if task: task.addUser(user) json = task.dict() json["originals"] = map(lambda x: x.dict(), task.getOriginals()) json["originalnum"] = len(json["originals"]) json["enrolled"] = task.checkUser(session["userid"]) return jsonify({"code": "success", "task": json}) else: return jsonify({"code": "err", "msg": "No task"})
def sbtask(): data = request.get_json() task = Task.getTask(data["prefix"]) user = User.getUser(session["userid"]) if task: json = task.dict() status = task.checkUserStatus(session["userid"]) if task.status == "Stop": status = "Stop" json["originals"] = map(lambda x: x.dict(), task.getOriginals()) json["originalnum"] = len(json["originals"]) json["enrolled"] = task.checkUser(session["userid"]) json["status"] = status json["parsednum"] = task.getParsedNumBySubmitter(user) json["submitok"] = status == "Approved" return jsonify({"code": "success", "task": json}) else: return jsonify({"code": "err", "msg": "No task"})
def evparsedsdone(): return jsonify({"parsedlist": Task.getEvaluateDone(session["userid"])})
def evparseds(): return jsonify({"parsedlist": Task.getEvaluateReady(session["userid"])})
def sbtasks(start=0, end=10): tasklist = Task.getTasks(start, end) return jsonify({"tasks": map(lambda x: x.dict(), tasklist)})
def gettaskcsv(prefix): task = Task.getTask(prefix) csv = task.getCSV() return send_file(csv, attachment_filename="taskdata.csv", as_attachment=True,mimetype="text/csv")