diff --git a/.DS_Store b/.DS_Store index a2c1177..ff4e6c1 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/dwd_global_rad_api_server/app.py b/dwd_global_rad_api_server/app.py index 8c59b41..ad9948d 100644 --- a/dwd_global_rad_api_server/app.py +++ b/dwd_global_rad_api_server/app.py @@ -11,24 +11,42 @@ # Instantiate main object objGlobalRadiation = dgr.GlobalRadiation() -# Configure logging -logging.basicConfig(level=logging.DEBUG) +# Configure logging with a custom formatter +class CustomFormatter(logging.Formatter): + def format(self, record): + log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' + formatter = logging.Formatter(log_format, datefmt='%Y-%m-%d %H:%M:%S') + return formatter.format(record) -@app.route('/process', methods=['POST']) -def process(): - if 'dataset' not in request.files or 'locations' not in request.form: - app.logger.error("Missing dataset or locations parameter") - return jsonify({'error': 'Missing dataset or locations parameter'}), 400 +# Remove the default Flask handlers if any +for handler in app.logger.handlers[:]: + app.logger.removeHandler(handler) +handler = logging.StreamHandler() +handler.setFormatter(CustomFormatter()) +app.logger.addHandler(handler) +app.logger.setLevel(logging.INFO) - dataset_file = request.files['dataset'] - locations = json.loads(request.form['locations']) +app.logger.propagate = False - try: - app.logger.info(f"Locations received: {locations}") - app.logger.info("Loading dataset") - ds = pickle.load(dataset_file) - app.logger.info("Dataset loaded successfully") +@app.route('/process', methods=['POST']) +def process(): + try: + if 'dataset' in request.files: + app.logger.info("Dataset provided in request") + dataset_file = request.files['dataset'] + ds = pickle.load(dataset_file) + else: + app.logger.info("No dataset provided, fetching internally") + objGlobalRadiation.fetch_forecasts() + ds = objGlobalRadiation.forecast_data.all_grid_forecasts + + if 'locations' in request.form: + app.logger.info("Locations provided in request") + locations = json.loads(request.form['locations']) + else: + app.logger.info("No locations provided, using internal locations") + locations = [{"lat": loc.latitude, "lon": loc.longitude} for loc in objGlobalRadiation.locations] app.logger.info("Creating animation") output_file = main.create_animation(ds, locations) diff --git a/dwd_global_rad_api_server/main.py b/dwd_global_rad_api_server/main.py index 40240f2..205f407 100644 --- a/dwd_global_rad_api_server/main.py +++ b/dwd_global_rad_api_server/main.py @@ -10,9 +10,9 @@ import logging # Set up logging configuration to show only warnings and errors -logging.basicConfig(level=logging.WARNING) -logging.getLogger('fiona').setLevel(logging.WARNING) -logging.getLogger('matplotlib').setLevel(logging.WARNING) +#logging.basicConfig(level=logging.WARNING) +#logging.getLogger('fiona').setLevel(logging.WARNING) +#logging.getLogger('matplotlib').setLevel(logging.WARNING) def create_animation(ds, custom_locations): lats = ds['lat'].values