openclimatefix / pv-site-api

Site specific API for PV forecasting
5 stars 8 forks source link

Return forecast as % #125

Open peterdudfield opened 9 months ago

peterdudfield commented 9 months ago

Return forecast as % of the site capacity

Context

Possible Implementation

add bool option to normalize data by site capacity. Default should be false. This could be donehere

This can be done with python loops, but I wonder if there is a way to do this more efficiently

rahul-maurya11b commented 3 months ago

Hi @peterdudfield Sir, I tried to attempt this issue but after running this " poetry run uvicorn pv_site_api.main:app --reload" but it shows API under construction. image

Not able to run pytest

peterdudfield commented 3 months ago

poetry run uvicorn pv_site_api.main:app --reload starts the app up. Can you run pytest seperate? What error do you get?

rahul-maurya11b commented 3 months ago

Yes @peterdudfield sir, by running pytest separately test passes ( by keeping the pv_site_api in root directory of tests) . I have questions:

  1. I have to run test_main.py for this issue to pass right?
  2. how can I generate the output and see results as the API is not working?
peterdudfield commented 3 months ago
  1. All tests need to pass
  2. Yea its a tricky one. The short answer would be to write a new test, that checks the values come out as %. Otherwise you would need to spin up a postgres database, inject some fake data and see if it works. This is quite similar to what the tests do, create a database + inject fake data.

I understand this is a bit tricky

rahul-maurya11b commented 3 months ago

Hi @peterdudfield sir, this is how the output of the forecast looks like

: The forecast value is : [SiteForecastValues(target_datetime_utc=datetime.datetime(2024, 3, 23, 10, 54, 53, 391262), expected_generation_kw=0.0), SiteForecastValues(target_datetime_utc=datetime.datetime(2024, 3, 23, 11, 4, 53, 391262), expected_generation_kw=0.0), SiteForecastValues(target_datetime_utc=datetime.datetime(2024, 3, 23, 11, 14, 53, 391262), expected_generation_kw=0.0), SiteForecastValues(target_datetime_utc=datetime.datetime(2024, 3, 23, 11, 24, 53, 391262), expected_generation_kw=0.0),

how it should look like if returned as percentage. And also while running pytest terminal is getting filed with warnings of DeprecationWarning do we need to update it ?

peterdudfield commented 3 months ago

Warnings would be good to get rid of

I'm surprised all those results are zero?

rahul-maurya11b commented 3 months ago

yes because I am not able to run this command: poetry run pytest tests: The issue with this is :

2024-03-24 10:31:57 2024-03-24 05:01:57.365 UTC [1] LOG: database system is ready to accept connections 2024-03-24 10:33:12 2024-03-24 05:03:12.916 UTC [71] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.978 UTC [72] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.982 UTC [73] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.991 UTC [74] LOG: invalid length of startup packet 2024-03-24 10:33:15 2024-03-24 05:03:15.726 UTC [75] LOG: invalid length of startup packet 2024-03-24 10:31:57 2024-03-24 05:01:57.211 UTC [49] LOG: database system is shut down

and when I am manually running it using pytest only in the test folder then all tests pass except


 :  def test_get_status(client, statuses):
        response = client.get("/api_status")
        assert response.status_code == 200

        returned_status = PVSiteAPIStatus(**response.json())
>       assert returned_status.status == "my_status 1"
E       AssertionError: assert 'my_status 0' == 'my_status 1'
E
E         - my_status 1
E         ?           ^
E         + my_status 0
E         ?           ^
test_status.py:20: AssertionError

because it can't connect to the database, is there something that I am doing wrong while running?

INFO:     Will watch for changes in these directories: ['D:\\openclimate\\pv_site\\pv-site-api']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [2444] using WatchFiles
Could not parse SQLAlchemy URL from string 'not_set'
Could not connect to database
INFO:     Started server process [1576]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
rahul-maurya11b commented 3 months ago

@peterdudfield Sir removed 3 warnings please check. #152

rahul-maurya11b commented 3 months ago

@peterdudfield sir corrected format and new PR #153 please check.

rahul-maurya11b commented 3 months ago

sir, how should I proceed with the return forecast as % issue? as all values are zero .

peterdudfield commented 3 months ago

yes because I am not able to run this command: poetry run pytest tests: The issue with this is :

2024-03-24 10:31:57 2024-03-24 05:01:57.365 UTC [1] LOG: database system is ready to accept connections 2024-03-24 10:33:12 2024-03-24 05:03:12.916 UTC [71] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.978 UTC [72] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.982 UTC [73] LOG: invalid length of startup packet 2024-03-24 10:33:13 2024-03-24 05:03:13.991 UTC [74] LOG: invalid length of startup packet 2024-03-24 10:33:15 2024-03-24 05:03:15.726 UTC [75] LOG: invalid length of startup packet 2024-03-24 10:31:57 2024-03-24 05:01:57.211 UTC [49] LOG: database system is shut down

and when I am manually running it using pytest only in the test folder then all tests pass except


 :  def test_get_status(client, statuses):
        response = client.get("/api_status")
        assert response.status_code == 200

        returned_status = PVSiteAPIStatus(**response.json())
>       assert returned_status.status == "my_status 1"
E       AssertionError: assert 'my_status 0' == 'my_status 1'
E
E         - my_status 1
E         ?           ^
E         + my_status 0
E         ?           ^
test_status.py:20: AssertionError

because it can't connect to the database, is there something that I am doing wrong while running?

INFO:     Will watch for changes in these directories: ['D:\\openclimate\\pv_site\\pv-site-api']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [2444] using WatchFiles
Could not parse SQLAlchemy URL from string 'not_set'
Could not connect to database
INFO:     Started server process [1576]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

pytest will run independently of the database, so you should be able to run them still