Esempio n. 1
0
 def post(self, **kwargs):
     """Creates next week crowd forecast"""
     if FLASK_ENV == 'development':
         try:
             return jsonify(
                 SuccessObject.create_response(
                     self, HTTPStatus.OK,
                     _ForecastService.create_next_week_prediction(
                         self,
                         start_date=request.args.get('start_date'),
                         number_of_weeks_to_use=request.args.get(
                             'number_of_weeks'),
                         use_start_of_the_week=request.args.get(
                             'use_start_of_the_week'))))
         except Exception as err:
             if (len(err.args) == 1):
                 return ErrorObject.create_response(self,
                                                    HTTPStatus.BAD_REQUEST,
                                                    str(err))
             else:
                 return ErrorObject.create_response(self, err.args[0],
                                                    err.args[1])
     else:
         return ErrorObject.create_response(self, HTTPStatus.NOT_FOUND,
                                            HTTPStatus.NOT_FOUND.phrase)
Esempio n. 2
0
 def get(self, data_id):
     """Fetch a single data point"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.get_one_data_point(self, data_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 3
0
 def get(self, name: str):
     """Retrieves data sources created by user"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_data_source_by_user(self, username=name)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 4
0
 def get(self):
     """Fetches all data sources"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.get_all_data_sources(self), True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 5
0
 def get(self, name: str):
     """Retrieves user by username"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_user_by_username(self, name)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 6
0
 def get(self, data_source_id):
     """Fetch a single data source"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.get_data_source_by_id(
                     self, data_source_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 7
0
 def post(self, token_id: int):
     """Deactivates a specific data source token"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.deactivate_token_of_user(
                     self, token['user']['id'], token_id)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 8
0
 def get(self):
     """Retrieves data source tokens created by the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_data_source_tokens_by_user(
                     self, token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 9
0
 def post(self):
     """Sets the username of the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.set_username(self, token['user']['id'],
                                           api.payload['username'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 10
0
 def get(self):
     """Retrieves the information of the logged in user"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _UserService.get_user_by_id(self, token['user']['id'],
                                             True)))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 11
0
 def post(self, **kwargs):
     """Creates a new data source"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_service.add_data_source(
                     self, kwargs['tupled_output'], token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 12
0
 def post(self, **kwargs):
     """Creates new data"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.post_data(
                     self, token['data_source_token']['data_source'],
                     kwargs['tupled_output'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 13
0
 def get(self, **kwargs):
     """Retrieves crowd forecast per week"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _ForecastService.get_crowd_forecast(
                     self,
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     return_data_frame=request.args.get('get_dataframe'))))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 14
0
 def post(self, data_source_id):
     """Creates a token for data source"""
     token = get_jwt_identity()
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _data_source_token_service.create_token_for_data_source(
                     self,
                     data_source_id=data_source_id,
                     user_id=token['user']['id'])))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 15
0
 def get(self):
     """Fetches data from all sources"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _DataSourceDataService.get_all_data(
                     self,
                     limit=request.args.get('limit'),
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     sort=request.args.get('sort')), True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])
Esempio n. 16
0
 def post(self, token_id: int):
     """Deactivates a specific data source token"""
     token = get_jwt_identity()
     if token['user']['id'] == 1:
         try:
             return jsonify(
                 SuccessObject.create_response(
                     self, HTTPStatus.OK,
                     _DataSourceTokenService.admin_revoke_token(
                         self, token_id)))
         except Exception as err:
             return ErrorObject.create_response(self, err.args[0],
                                                err.args[1])
     else:
         return ErrorObject.create_response(
             self, HTTPStatus.FORBIDDEN,
             "You are unable to access this endpoint.")
Esempio n. 17
0
 def get(self):
     """Fetches all weather data"""
     try:
         return jsonify(
             SuccessObject.create_response(
                 self, HTTPStatus.OK,
                 _WeatherService.retrieve_all_weather_data(
                     self,
                     limit=request.args.get('limit'),
                     start_date=request.args.get('start_date'),
                     end_date=request.args.get('end_date'),
                     order_by=request.args.get('order_by'),
                     sort=request.args.get('sort'),
                     forecast_type=request.args.get('forecast_type')),
                 True))
     except Exception as err:
         return ErrorObject.create_response(self, err.args[0], err.args[1])