mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-04-19 08:55:15 +00:00
moved isfloat(num)
improved isfloat for case "None" and strings with surrounding whitespace and special types like +-inf.
This commit is contained in:
parent
ae5ead0884
commit
c9db30859b
@ -2,6 +2,7 @@
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
import matplotlib
|
||||
|
||||
@ -9,15 +10,14 @@ import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
|
||||
import pandas as pd
|
||||
from flask import Flask, jsonify, redirect, request, send_from_directory, url_for
|
||||
|
||||
from akkudoktoreos.class_load import LoadForecast
|
||||
from akkudoktoreos.class_load_container import Gesamtlast
|
||||
from akkudoktoreos.class_load_corrector import LoadPredictionAdjuster
|
||||
from akkudoktoreos.class_optimize import isfloat, optimization_problem
|
||||
from akkudoktoreos.class_optimize import optimization_problem
|
||||
from akkudoktoreos.class_pv_forecast import PVForecast
|
||||
from akkudoktoreos.class_strompreis import HourlyElectricityPriceForecast
|
||||
from akkudoktoreos.config import get_start_enddate, optimization_hours, prediction_hours
|
||||
from flask import Flask, jsonify, redirect, request, send_from_directory, url_for
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@ -26,6 +26,25 @@ opt_class = optimization_problem(
|
||||
)
|
||||
|
||||
|
||||
def isfloat(num: Any) -> bool:
|
||||
"""Check if a given input can be converted to float."""
|
||||
if num is None:
|
||||
return False
|
||||
|
||||
if isinstance(num, str):
|
||||
num = num.strip() # Strip any surrounding whitespace
|
||||
|
||||
try:
|
||||
float_value = float(num)
|
||||
return not (
|
||||
float_value == float("inf")
|
||||
or float_value == float("-inf")
|
||||
or float_value != float_value
|
||||
) # Excludes NaN or Infinity
|
||||
except (ValueError, TypeError):
|
||||
return False
|
||||
|
||||
|
||||
@app.route("/strompreis", methods=["GET"])
|
||||
def flask_strompreis():
|
||||
# Get the current date and the end date based on prediction hours
|
||||
|
Loading…
x
Reference in New Issue
Block a user