def get_host_tables(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) resp_json, hid = get_param(Params.ID) if hid is None: return json.dumps(resp_json)
def get_fixed_price_tables(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) resp_json.guest_table = get_table_param(Params.GTID) if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) return func_get_target_tables(uid, guest_table, TransType.TRAIN.value)
def show_table(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) resp_json, gid = get_param(Params.ID) if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) return json.dumps(func_show_table(uid, gid))
def user_page(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return redirect(url_for('index_page')) user = User.query.get(uid) guest_table_names = user.table_names print(uid) hosts = User.query.filter(User.id != uid).all() print(hosts) return render_template('user.html', user=user, guest_table_names=guest_table_names, hosts=hosts)
def hetero_lr_train(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK: return json.dumps(resp_json) amount = get_param(Params.AMOUNT) if amount is None: resp_json[Params.RESULT] = RetVal.LACK_PARAM return json.dumps(resp_json) trans = Transaction() trans.gid = uid trans.amount = amount trans.type = TransType.TOPUP db.session.add(trans) user = User.query.get(uid) user.wallet += amount db_commit() return json.dumps(resp_json)
def add_table(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) name, id_col, label_col, memo = get_params( (Params.NAME, Params.ID_COL, Params.LABEL_COL, Params.MEMO)) if name is None or 'file' not in request.files: resp_json[Params.RESULT] = RetVal.LACK_PARAM.value return json.dumps(resp_json) # save table name tn_rec = TableName() tn_rec.uid = uid tn_rec.name = name db.session.add(tn_rec) resp_json = db_commit() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) # save table record to get name t_rec = Table() t_rec.name_id = tn_rec.id t_rec.memo = memo t_rec.id_col = id_col t_rec.y_col = label_col db.session.add(t_rec) resp_json = db_commit() if resp_json[Params.RESULT] != RetVal.OK.value: db.session.delete(tn_rec) db_commit() return json.dumps(resp_json) # check csv file local_path = t_rec.get_local_path() file = request.files['file'] file.save(local_path) try: df = pd.read_csv(local_path) resp_json[Params.RESULT] = RetVal.OK.value except Exception as e: os.unlink(local_path) logger = Logger.get_logger() logger.error('upload_file exception: %s', str(e)) resp_json[Params.RESULT] = RetVal.FILE_INV.value df = None if df is not None: r, c = df.shape if r <= MAX_ROW and c <= MAX_COLUMN and id_col in df.columns: if label_col in df.columns: label_id = df.drop(id_col, axis=1).columns.get_loc(label_col) elif len(label_col) == 0: label_id = -1 else: label_id = None resp_json[Params.RESULT] = RetVal.FILE_INV.value if label_id is not None: t_rec.y_col_id = label_id node = Node(uid) fate_path = t_rec.get_fate_path() node.upload(local_path, fate_path) resp_json = db_commit() if resp_json[Params.RESULT] == RetVal.OK: return json.dumps(resp_json) else: resp_json[Params.RESULT] = RetVal.FILE_LARGE.value db.session.delete(tn_rec) db.session.delete(t_rec) db_commit() os.unlink(local_path) return json.dumps(resp_json)
def get_hosts(): resp_json, uid = get_uid() if resp_json[Params.RESULT] != RetVal.OK.value: return json.dumps(resp_json) return json.dumps(func_show_hosts(uid))