async def run(self, main_func_name): reqs = os.listdir(self.req_dir) if reqs: req_name = reqs[0] req_path = os.path.join(self.req_dir, req_name) req_content = read_json(req_path) os.remove(req_path) # 읽은 후 바로 삭제 res = getattr(self.worker, main_func_name)(**req_content) res_path = os.path.join(self.res_dir, req_name) write_json(res, res_path) # res 파일 생성
def webhook(): if request.method == 'POST': r = request.get_json() for command in command_list: for regular in command.keys: if re.match(regular, r['message']['text']) is not None: send_message(r['message']['chat']['id'], command.process(r)) return jsonify(r) send_message(r['message']['chat']['id'], 'unknown command') utility.write_json(r) return jsonify(r) return render_template('landing.html')
def my_custom_loss_func(ground_truth, p, n, json): # Calculate Precision-Recall-F-Score precision, recall, fscore, _ = precision_recall_fscore_support( ground_truth, p, labels=[1, 0]) # Calculate Precision-Recall Curve prc, rec, _ = precision_recall_curve(ground_truth, p, pos_label=1) # Calculate AUPRC auprc = average_precision_score(ground_truth, p) # Calculate False Positive Rate (FPR) and True Positive Rate (TPR) # [FPR, TNR] [TPR, FNR] fpr, tpr, _ = roc_curve(ground_truth, p) # Calculate AUROC auroc = auc(fpr, tpr) # Save the metrics as a ordered dictionary scores = [ ("class", n), # class number ("positives", np.count_nonzero(ground_truth)), ("precision0", precision[1]), ("precision1", precision[0]), ("recall0", recall[1]), ("recall1", recall[0]), ("fscore0", fscore[1]), ("fscore1", fscore[0]), ("prc10", prc.tolist()), ("rec10", rec.tolist()), ("auprc", auprc), ("fpr10", fpr.tolist()), ("tpr10", tpr.tolist()), ("auroc", auroc) ] # Write scores into the json file write_json(json, scores) return 0
# Add Json extension f_temp = p_sim + f_temp + ".json" # Classifier c = cl[x] # Save the header as a dictionary header = [ ("Ontology", sys.argv[1]), ("Classifier", x), #("Parameters", c.get_params()), ("Start_Time", time.strftime("%c")) ] # Write the header into the json file write_json(f_temp, header) # Different branches for linearly and non-linearly separable classes if switch: for j in range(Y.shape[1]): if j in lc: metrics(c, X, Y.getdensecol(j), j, f_temp) else: for j in range(0, Y.shape[1], 5): metrics(c, X, Y.getdensecol(j), j, f_temp) # Save the footer as a dictionary footer = [("End_Time", time.strftime("%c"))] # Write the footer into the json file write_json(f_temp, footer)
def _send_request(self, content): write_json(content, self.req_path)
# Path to the simulation directory of the chosen ontology p_sim = "Simulation/" + onto_name + "/" # Part of the filenames associated to the Json files f_sim = p_sim + "M_" + onto_name + "_" # Read Annotation Matrix Y = load_annotation(f_ann) for classname, classifier in classifiers.items(): filename_out = f_sim + classname + '.json' # Save the header as a dictionary header = [ ("Ontology", onto_name), ("Classifier", classname), #("Parameters", classifier.get_params()), ("Start_Time", time.strftime("%c")) ] # Write the header into the json file write_json(filename_out, header) for x in range(0, Y.shape[1], 5): metrics(classifier, X, Y.getdensecol(x), x, filename_out) # Save the footer as a dictionary footer = [("End_Time", time.strftime("%c"))] # Write the footer into the json file write_json(filename_out, footer)