예제 #1
0
    def post(self):
        '''
        Attributes:
        username    Username, string
        password    Password, string
        '''

        parser = reqparse.RequestParser()
        parser.add_argument('username', type=str, help='Username of account')
        parser.add_argument('password', type=str, help='Password of account')
        args = parser.parse_args()

        username = args['username']
        password = args['password']

        if username in [i[0] for i in session.query(User.username).all()]:
            abort(404, {'message': 'Username %s already exists' % username})

        if username is None or password is None:
            abort(404, 'Must supply both username and password')

        user = User(username=username)
        user.hash_password(password)

        try:
            session.add(user)
            session.commit()
        except Exception as e:
            print(str(e))
            session.rollback()
            abort(404, {'message': str(e)})
        return jsonify({'Username': username,
                        'location': 'http://%s:%s/user/%s' % (HOST, PORT, username)})
예제 #2
0
    def get(self, username, model_name):
        ''' Make a batch prediction from a file
        Attributes:
            username    The user's username
            model_name  The user's model to be used for prediction
        '''
        parser = reqparse.RequestParser()
        parser.add_argument('file', type=str, help='Filepath to data')
        parser.add_argument('skipheader',
                            type=bool,
                            help='Should header be skipped?')
        parser.add_argument('delimiter',
                            type=str,
                            help='What delimiter is used in data?')

        args = parser.parse_args()

        file = args['file']
        skipheader = args['skipheader']
        delimiter = args['delimiter']

        model = session.query(Model).join(User).\
                         filter(User.username==username).first()

        model = pickle.loads(model.model)

        try:
            data = read_data(file, skipheader, delimiter)
        except OSError as ose:
            abort(404, {'message': str(ose)})

        predictions = model.predict(data).tolist()
        predictions = json.dumps(predictions)

        return {
            'model': model.get_params(),
            'file': file,
            'predictions': predictions
        }
예제 #3
0
    def get(self, username, model_name):
        '''
        Attributes:
            username    Username of user
            model_name  Name of model to explore
        '''
        result = session.query(Model).join(User).\
                         filter(User.username==username).all()
        if len(result) > 1:
            return jsonify({
                'error':
                'Multiple models under this name: %s' % result.model_name
            })
        else:
            try:
                result = result[0]
            except IndexError:
                abort(404)

        model = pickle.loads(result.model)
        try:
            model_attributes = model.get_params(
            ) if result.model_source == 'sklearn' else 'NA'
        except:
            model_attributes = 'NA'

        try:
            part_of = result.project.project_name
        except Exception as e:
            abort(404, {'error': str(e)})

        return jsonify({
            'model_name': result.model_name,
            'date_added': result.date_added,
            'model_source': result.model_source,
            'user': username,
            'model_attributes': model_attributes,
            'part_of': part_of
        })
예제 #4
0
def get_all_usernames():
    names = session.query(User.username).all()
    return [i[0] for i in names]
예제 #5
0
def get_user(username):
    return session.query(User).filter_by(username=username).first()