Apply isort and ruff code style

This commit is contained in:
Michael Osthege
2024-10-03 11:05:44 +02:00
committed by Andreas
parent 05a3c1a5bb
commit a4d178d250
23 changed files with 1787 additions and 866 deletions

View File

@@ -1,35 +1,43 @@
from flask import Flask, jsonify, request
import numpy as np
from datetime import datetime
import modules.class_load as cl
from pprint import pprint
from flask import Flask, jsonify, request
import modules.class_load as cl
app = Flask(__name__)
# Constants
DATE_FORMAT = '%Y-%m-%d'
DATE_FORMAT = "%Y-%m-%d"
EXPECTED_ARRAY_SHAPE = (2, 24)
FILEPATH = r'.\load_profiles.npz'
FILEPATH = r".\load_profiles.npz"
def get_load_forecast(year_energy):
"""Initialize LoadForecast with the given year_energy."""
return cl.LoadForecast(filepath=FILEPATH, year_energy=float(year_energy))
def validate_date(date_str):
"""Validate the date string and return a datetime object."""
try:
return datetime.strptime(date_str, DATE_FORMAT)
except ValueError:
raise ValueError("Date is not in the correct format. Expected format: YYYY-MM-DD.")
raise ValueError(
"Date is not in the correct format. Expected format: YYYY-MM-DD."
)
@app.route('/getdata', methods=['GET'])
@app.route("/getdata", methods=["GET"])
def get_data():
# Retrieve the date and year_energy from query parameters
date_str = request.args.get('date')
year_energy = request.args.get('year_energy')
date_str = request.args.get("date")
year_energy = request.args.get("year_energy")
if not date_str or not year_energy:
return jsonify({"error": "Missing 'date' or 'year_energy' query parameter."}), 400
return jsonify(
{"error": "Missing 'date' or 'year_energy' query parameter."}
), 400
try:
# Validate and convert the date
@@ -54,5 +62,6 @@ def get_data():
# Return a generic error message for unexpected errors
return jsonify({"error": "An unexpected error occurred."}), 500
if __name__ == '__main__':
if __name__ == "__main__":
app.run(debug=True)