def select_table(): table_id = request.json.get('table_id') user, user_id = get_user() if user is None or user_id is None: return parse_json(401, False) dataset = DatasetService.get(ObjectId(table_id)) return parse_json(dataset.get_dict(True))
def get_tables(): user, user_id = get_user() if user is None or user_id is None: return parse_json(401, False) s = DatasetService.get_tables_json(user.data_ids) return parse_json(s)
def login(): """ Login """ email = request.json.get('email') password = request.json.get('password') if UserService.check(email, password): user, user_id = UserService.get(email) token = UserService.generate_auth_token(str(user_id)) return parse_json({'token': token}) else: return parse_json(False, False)
def apply_classifier(classifier): user, user_id = get_user() if user is None or user_id is None: return parse_json(401, False) table_id = request.json.get('table_id') removed_labels = request.json.get('removed_labels') class_label = request.json.get('class_label') score = DatasetService.apply(classifier, ObjectId(table_id), removed_labels, class_label) return parse_json(score)
def predict(classifier): user, user_id = get_user() if user is None or user_id is None: return parse_json(401, False) table_id = request.json.get('table_id') _predict = request.json.get( 'predict') # [['label': 'label_name', 'value': 1212], ...] score = DatasetService.predict(classifier, ObjectId(table_id), _predict) return parse_json(str(score))
def upload(): user, user_id = get_user() if user is None or user_id is None: return parse_json(401, False) if 'file' not in request.files: return parse_json(500, False) file = request.files['file'] if file: dataset = Dataset(file.filename, DatasetService.get_data(file), Binary(b'')) DatasetService.create(dataset, user_id) return parse_json(dataset.get_dict(True)) return parse_json('Bad file format', False)
def register(): """ Register """ name = request.json.get('name') email = request.json.get('email') password = request.json.get('password') if name is None or password is None or email is None: return parse_json("missing arguments", False) if UserService.does_exist(email): return parse_json("existing user", False) user = User(name, email, password, []) user_id = UserService.create(user) token = UserService.generate_auth_token(str(user_id)) return parse_json({'token': token}, True)
def get_data(file_path: str) -> str: data = pd.read_csv(file_path) ret_data = pd.concat([data.head(DataProcessing.N), data.tail(DataProcessing.N)]) json_data = ret_data.to_json() s = parse_json({'columns': ret_data.to_json(), 'table_id': 1}) return s
def get_data(self) -> str: s = parse_json({'columns': self.ret_json_data, 'table_id': 1}) return s
def is_valid_token(): user, user_id = get_user() if user is None or user_id is None: return parse_json(False) else: return parse_json(True)
def logout(): """ Logout """ user, user_id = get_user() UserService.generate_auth_token(str(user_id), -1) return parse_json(True)