def get(self, datasource_id, page_size, page):
     user_id = get_jwt_identity()
     datasource = DatasourceModel.find_one_by_id(user_id, datasource_id)
     dataframe = datasource.get_datasource_per_page(page, page_size)
     dataset = Dataset(dataframe)
     header = DatasourceModel.get_columns(datasource.user_schema_name,
                                          datasource.user_table_name)
     return {'header': header, 'data': dataset.get_json()}
    def post(self, experiment_name):
        user_id = get_jwt_identity()
        data = Prediction.parser.parse_args()
        raw_data = data['data']
        dataset = File.read_json(raw_data)

        result = ExperimentModel.find_by_name(user_id, experiment_name)
        y_col = result.y_col
        datasource_id = result.datasource_id
        project_id = result.project_id

        result = DatasourceModel.find_one_by_id(user_id, datasource_id)
        user_schema_name = result.user_schema_name
        user_table_name = result.user_table_name
        columns = [
            col['column_name'] for col in DatasourceModel.get_columns(
                user_schema_name, user_table_name)
        ]

        try:
            columns_filter_id = ProjectModel.find_one_by_id(
                project_id, user_id).columns_filter_id
        except Exception as e:
            return {
                'message':
                ERROR_CANNOT_GET_COLUMNS_FILTER_ID.format(project_id)
            }, 500

        try:
            columns_filter = ProjectUnstructureModel.find_by_object_id(
                ObjectId(columns_filter_id))['columns']
        except Exception as e:
            return {
                'message': ERROR_CANNOT_GET_COLUMNS_FILTER.format(project_id)
            }, 500
        try:
            predict = Predicting(experiment_name, dataset, columns,
                                 columns_filter, y_col, user_id)
            predict.decorate_dataframe()
            predict.load_model()
            predict.predict()
            dataset = predict.merge_predict_to_dataframe()
            json_data = Dataset(dataset).get_json()
        except Exception as e:
            print(e)
            return {
                'message':
                ERROR_CANNOT_GET_PREDICT_WITH_DATA.format(experiment_name)
            }, 500
        # try:
        #     DatasourceModel.append_datasource(dataset, user_schema_name, user_table_name)
        # except Exception as e:
        #     return {'message': ERROR_CANNOT_INSERT_DB}, 500

        return {'data': json_data}, 200
 def get(self, project_id, experiment_name):
     user_id = get_jwt_identity()
     experiment = ExperimentModel.find_by_experiment_name(
         user_id, experiment_name)
     datasource = DatasourceModel.find_one_by_id(user_id,
                                                 experiment.datasource_id)
     data_columns = DatasourceModel.get_columns(datasource.user_schema_name,
                                                datasource.user_table_name)
     return {
         'datasource_name': datasource.datasource_name,
         'header': data_columns
     }, 200
 def get(self, datasource_name):
     user_id = get_jwt_identity()
     user_schema_name = 'u{}'.format(user_id)
     user_table_name = datasource_name
     datasource_description = ''
     datasource = DatasourceModel(datasource_name, datasource_description,
                                  user_schema_name, user_table_name,
                                  user_id)
     dataframe = datasource.get_datasource()
     dataset = Dataset(dataframe)
     header = DatasourceModel.get_columns(user_schema_name, user_table_name)
     return {'header': header, 'data': dataset.get_json()}
 def get(self, datasource_id):
     user_id = get_jwt_identity()
     datasource = DatasourceModel.find_one_by_id(user_id, datasource_id)
     if (datasource):
         datasource_name = datasource.datasource_name
         user_schema_name = 'u{}'.format(user_id)
         user_table_name = datasource_name
         header = DatasourceModel.get_columns(user_schema_name,
                                              user_table_name)
         return {'message': 'sucess', 'header': header}, 200
     else:
         return {'message': 'Cannot fetch columns'}, 500
 def get(self, datasource_id):
     user_id = get_jwt_identity()
     datasource = DatasourceModel.find_one_by_id(user_id, datasource_id)
     metadata = {
         'datasource_id': datasource.datasource_id,
         'datasource_name': datasource.datasource_name,
         'datasource_description': datasource.datasource_description,
         'user_schema_name': datasource.user_schema_name,
         'user_table_name': datasource.user_table_name,
         'created_at': str(datasource.created_at)
     }
     header = DatasourceModel.get_columns(datasource.user_schema_name,
                                          datasource.user_table_name)
     return {'header': header, 'metadata': metadata}
 def get(self, datasource_name):
     user_id = get_jwt_identity()
     user_schema_name = 'u{}'.format(user_id)
     user_table_name = datasource_name
     header = DatasourceModel.get_columns(user_schema_name, user_table_name)
     return {'message': 'sucess', 'header': header}, 200