def validateuser(username): message = "Success" code = 200 result = False try: rjson = request.get_json() utility.validateParam(rjson, "username") utility.validateParam(rjson, "password") result = projectmgr.ValidateUser(rjson["username"], rjson["password"]) except Exception as e: message = str(e) code = 500 return jsonify({"statuscode": code, "message": message, "result": result})
def updateuser(username): message = "Success" code = 200 result = [] try: rjson = request.get_json() utility.validateParam(rjson, "name") projectmgr.UpdateUser(username, rjson["name"], rjson["email"]) except Exception as e: message = str(e) code = 500 return jsonify({"statuscode": code, "message": message, "result": result})
def updateuserpassword(username): message = "Success" code = 200 result = [] try: rjson = request.get_json() utility.validateParam(rjson, "currentpassword") utility.validateParam(rjson, "password") valid = projectmgr.ValidateUser(username, rjson["currentpassword"]) if valid: projectmgr.UpdateUserPassword(username, rjson["password"]) else: raise Exception("Please enter valid current password") except Exception as e: message = str(e) code = 500 return jsonify({"statuscode": code, "message": message, "result": result})
def predlogs(): message = "Success" code = 200 result = [] try: rjson = request.get_json() utility.validateParam(rjson, "category") utility.validateParam(rjson, "servicename") utility.validateParam(rjson, "status") utility.validateParam(rjson, "start") utility.validateParam(rjson, "end") start = parser.parse(rjson["start"] + " 00:00") end = parser.parse(rjson["end"] + " 23:59") logs = logmgr.GetLogs(rjson["servicename"], rjson["category"], start, end, rjson["status"]) for l in logs: result.append({"cat": l.servicetype, "name": l.servicename, "start": l.start, "end": l.end, "duration": l.duration, "status": l.status, "message": l.message}) except Exception as e: message = str(e) code = 500 return jsonify({"statuscode": code, "message": message, "result": result})
def dataplot(): message = "Success" code = 200 result = [] try: rjson = request.json utility.validateParam(rjson, "name") utility.validateParam(rjson, "filename") utility.validateParam(rjson, "method") options = utility.getVal(rjson, "options") result = dataanalyzer.plot(rjson["name"], rjson["filename"], rjson["method"], options) except Exception as e: message = str(e) code = 500 return jsonify({"statuscode": code, "message": message, "result": result})
def plot(name, filename, method, options=None): df = loaddata(name, filename) d = [] if method == "factor": utility.validateParam(options, "x") utility.validateParam(options, "y") d = plotmgr.Axis_FactorPlot(df, options["x"], options["y"], utility.getVal(options, "hue"), utility.getVal(options, "row"), utility.getVal(options, "col"), utility.getVal(options, "kind", "point")) elif method == "lm": utility.validateParam(options, "x") utility.validateParam(options, "y") d = plotmgr.Axis_LMPlot(df, options["x"], options["y"], utility.getVal(options, "hue")) elif method == "pair": d = plotmgr.Axis_PairPlot(df, utility.getVal(options, "vars"), utility.getVal(options, "hue")) elif method == "joint": utility.validateParam(options, "x") utility.validateParam(options, "y") d = plotmgr.Axis_JointPlot(df, options["x"], options["y"], utility.getVal(options, "kind", "scatter")) elif method == "strip": utility.validateParam(options, "x") d = plotmgr.Cat_StripPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue"), utility.getVal(options, "jitter", False)) elif method == "swarm": utility.validateParam(options, "x") d = plotmgr.Cat_SwarmPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "box": utility.validateParam(options, "x") d = plotmgr.Cat_BoxPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "violin": utility.validateParam(options, "x") d = plotmgr.Cat_ViolinPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "lv": utility.validateParam(options, "x") d = plotmgr.Cat_LVPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "point": utility.validateParam(options, "x") d = plotmgr.Cat_LVPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "bar": utility.validateParam(options, "x") d = plotmgr.Cat_BarPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "count": utility.validateParam(options, "x") d = plotmgr.Cat_CountPlot(df, options["x"], utility.getVal(options, "y"), utility.getVal(options, "hue")) elif method == "reg": utility.validateParam(options, "x") utility.validateParam(options, "y") d = plotmgr.Reg_RegPlot(df, options["x"], utility.getVal(options, "y")) elif method == "kde": utility.validateParam(options, "x") utility.validateParam(options, "y") d = plotmgr.Reg_RegPlot(df, options["x"], utility.getVal(options, "y")) elif method == "rug": utility.validateParam(options, "x") d = plotmgr.Reg_RugPlot(df, options["x"]) return d