diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..53d50380 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.gitignore +__pycache__/ +*.py[cod] +*.egg-info/ +.venv/ +.env +.env.* +.vscode +.idea +node_modules +dist +build diff --git a/.gitignore b/.gitignore index b9cff1ae..524cc3fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,19 @@ -.env -myenv -src/venv. -shsohos -*.pyc -src/.streamlit/secrets.toml +# setuptools / packaging +*.egg-info/ # uv .venv/ .python-version +uv.lock +uv.lock.bak + +# Python __pycache__/ *.py[cod] *$py.class -uv.lock.bak -uv.lock \ No newline at end of file + +# Secrets +.env +src/.streamlit/secrets.toml + +*.egg-info/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1f872016..15144f1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,18 @@ [build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" +requires = [ + "setuptools>=61", + "setuptools-git-versioning>=2.0,<3", +] +build-backend = "setuptools.build_meta" + [project] name = "analysis-dashboard" -version = "0.1.0" +dynamic = ["version"] description = "Analysis dashboard for OCF forecasting systems" -readme = {file = "README.md", content-type = "text/markdown"} -requires-python = ">=3.12.0,<3.13" +readme = { file = "README.md", content-type = "text/markdown" } +requires-python = ">=3.12,<3.13" + dependencies = [ "altair==5.5.0", "requests==2.32.3", @@ -32,14 +37,18 @@ dependencies = [ "fiona>=1.9,<2.0", "herbie-data", "numcodecs>=0.12,<1.0", + + # upstream torch handling (ROLLED BACK as requested) "torch @ https://download.pytorch.org/whl/cpu/torch-2.3.1%2Bcpu-cp312-cp312-linux_x86_64.whl ; platform_system == 'Linux' and platform_machine == 'x86_64'", "torch @ https://download.pytorch.org/whl/cpu/torch-2.3.1%2Bcpu-cp312-cp312-win_amd64.whl ; platform_system == 'Windows' and platform_machine == 'AMD64'", "torch @ https://download.pytorch.org/whl/cpu/torch-2.3.1-cp312-none-macosx_11_0_arm64.whl ; platform_system == 'Darwin' and platform_machine == 'arm64'", + "matplotlib>=3.8,<4.0", "dp-sdk", "aiocache", ] + [project.optional-dependencies] dev = [ "pytest", @@ -47,31 +56,26 @@ dev = [ "ruff", ] -[tool.hatch.metadata] -allow-direct-references = true -[tool.hatch.build.targets.wheel] -packages = ["src"] +[tool.setuptools] +package-dir = { "" = "src" } + +[tool.setuptools.packages.find] +where = ["src"] + + +[tool.setuptools-git-versioning] +enabled = true -[tool.hatch.build.targets.sdist] -include = [ - "src/", - "pyproject.toml", - "README.md", -] [tool.uv] -dev-dependencies = [ - "pytest", - "pytest-cov", - "ruff", -] index-url = "https://download.pytorch.org/whl/cpu" extra-index-url = ["https://pypi.org/simple"] [tool.uv.sources] dp-sdk = { url = "https://github.com/openclimatefix/data-platform/releases/download/v0.13.2/dp_sdk-0.13.2-py3-none-any.whl" } + [tool.pytest.ini_options] testpaths = ["tests"] python_files = ["test_*.py"] diff --git a/src/main.py b/src/main.py index 663be0c5..264dcbbe 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,5 @@ -""" -UK analysis dashboard for OCF +""" +UK analysis dashboard for OCF """ import os @@ -24,7 +24,10 @@ from plots.pinball_and_exceedance_plots import make_pinball_or_exceedance_plot from plots.ramp_rate import make_ramp_rate_plot from plots.utils import ( - get_x_y, get_recent_available_model_names, model_is_probabilistic, model_is_gsp_regional + get_x_y, + get_recent_available_model_names, + model_is_probabilistic, + model_is_gsp_regional, ) from pvsite_forecast import pvsite_forecast_page from sites_toolbox import sites_toolbox_page @@ -38,46 +41,29 @@ from adjuster import adjuster_page from batch_page import batch_page -st.get_option("theme.primaryColor") st.set_page_config(layout="wide", page_title="OCF Dashboard") +from importlib.metadata import version, PackageNotFoundError + def metric_page(): - # Set up sidebar - - # Select start and end date st.sidebar.subheader("Select date range for charts") starttime = st.sidebar.date_input("Start Date", datetime.today() - timedelta(days=30)) endtime = st.sidebar.date_input("End Date", datetime.today()) - - # Adjuster option + use_adjuster = st.sidebar.radio("Use adjuster", [True, False], index=1) - # Select model st.sidebar.subheader("Select Forecast Model") - - # Get the models run in the last week connection = DatabaseConnection(url=os.environ["DB_URL"], echo=True) - + with connection.get_session() as session: models = get_recent_available_model_names(session) - - # Default model is pvnet_v2 + model_name = st.sidebar.selectbox("Select model", models, index=models.index("pvnet_v2")) - # Get metrics for comparing MAE and RMSE without forecast horizon with connection.get_session() as session: - # read database metric values - name_mae = "Daily Latest MAE" - name_rmse = "Daily Latest RMSE" - name_mae_gsp_sum = "Daily Latest MAE All GSPs" - if use_adjuster: - name_mae = "Daily Latest MAE with adjuster" - name_rmse = "Daily Latest RMSE with adjuster" - name_mae_gsp_sum = "Daily Latest MAE All GSPs" - - name_pvlive_mae = "PVLive MAE" - name_pvlive_rmse = "PVLive RMSE" + name_mae = "Daily Latest MAE with adjuster" if use_adjuster else "Daily Latest MAE" + name_rmse = "Daily Latest RMSE with adjuster" if use_adjuster else "Daily Latest RMSE" metric_values_mae = get_metric_value( session=session, @@ -96,179 +82,52 @@ def metric_page(): end_datetime_utc=endtime, model_name=model_name, ) - # Get metric value for mae with pvlive gsp sum truths for comparison - metric_values_mae_gsp_sum = get_metric_value( - session=session, - name=name_mae_gsp_sum, - start_datetime_utc=starttime, - end_datetime_utc=endtime, - model_name=model_name, - ) - - # pvlive - metric_values_pvlive_mae = get_metric_value( - session=session, - name=name_pvlive_mae, - start_datetime_utc=starttime, - end_datetime_utc=endtime, - gsp_id=0, - ) - metric_values_pvlive_rmse = get_metric_value( - session=session, - name=name_pvlive_rmse, - start_datetime_utc=starttime, - end_datetime_utc=endtime, - gsp_id=0, - ) - # transform SQL object into something readable - x_mae_all_gsp, y_mae_all_gsp = get_x_y(metric_values=metric_values_mae_gsp_sum) - x_mae, y_mae = get_x_y(metric_values=metric_values_mae) - x_rmse, y_rmse = get_x_y(metric_values=metric_values_rmse) - x_plive_mae, y_plive_mae = get_x_y(metric_values=metric_values_pvlive_mae) - x_plive_rmse, y_plive_rmse = get_x_y(metric_values=metric_values_pvlive_rmse) + x_mae, y_mae = get_x_y(metric_values_mae) + x_rmse, y_rmse = get_x_y(metric_values_rmse) - st.markdown( - f'