Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve and move isfloat(num) #127

Merged
merged 8 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README-DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Die Diskussion findet im [Forum](https://www.akkudoktor.net/forum/diy-energie-op
Gute Install Anleitung:
https://meintechblog.de/2024/09/05/andreas-schmitz-joerg-installiert-mein-energieoptimierungssystem/

Das Projekt erfordert Python 3.8 oder neuer.
Das Projekt erfordert Python 3.10 oder neuer.

### Schnellanleitung

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
Good installation guide:
https://meintechblog.de/2024/09/05/andreas-schmitz-joerg-installiert-mein-energieoptimierungssystem/

The project requires Python 3.8 or newer.
The project requires Python 3.10 or newer.

### Quick Start Guide

Expand Down
9 changes: 0 additions & 9 deletions src/akkudoktoreos/class_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
from akkudoktoreos.visualize import visualisiere_ergebnisse


def isfloat(num: Any) -> bool:
"""Check if a given input can be converted to float."""
try:
float(num)
return True
except ValueError:
return False


class optimization_problem:
def __init__(
self,
Expand Down
22 changes: 21 additions & 1 deletion src/akkudoktoreosserver/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from datetime import datetime
from typing import Any, TypeGuard

import matplotlib

Expand All @@ -14,7 +15,7 @@
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
Expand All @@ -26,6 +27,25 @@
)


def isfloat(num: Any) -> TypeGuard[float]:
"""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
Expand Down
Loading