Beispiel #1
0
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))
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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))
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
0
 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
Beispiel #9
0
 def get_data(self) -> str:
     s = parse_json({'columns': self.ret_json_data, 'table_id': 1})
     return s
Beispiel #10
0
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)
Beispiel #11
0
def logout():
    """ Logout """
    user, user_id = get_user()
    UserService.generate_auth_token(str(user_id), -1)
    return parse_json(True)