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

fix(parsers, CO): adopt use_proxy, fix parsing, add tests #7690

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

consideRatio
Copy link
Contributor

@consideRatio consideRatio commented Jan 6, 2025

Currently based on top of #7686

This PR includes #7686, as it builds further on changes to the use_proxy decorator.

Issue

Description

CO proxy needed and added with monkeypatching

The CO parser now needs to be proxied from CO. However, since the CO parser makes use of the library pydataxm to make requests, and it can't be configured to use a proxy, I've monkeypatched aiohttp.ClientSession.__init__ and requests.post temporarily so that when they are used by pydataxm, it will proxy traffic anyhow.

An upstream issue about this is EquipoAnaliticaXM/API_XM#37.

Live consumption parser fix

There was a datetime string returned sub-seconds, so I removed them before parsing the datetime.fromisoformat which in Python <= 3.10 doesn't handle that.

Historical parsers fixes

While pydataxm.ReadDB().reques_data() has a function signature with start_date and end_date, it turns out that sometimes they aren't respected and more data for additional dates are returned. This seems to happen when requesting data from not very recent dates.

I've updated the parser to handle receiving multiple dates for consumption/production/price parser, which all had the issue, but where the production parser didn't error but instead generated incorrect data I think.

Double check

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
    export WEBSHARE_USERNAME=...
    export WEBSHARE_PASSWORD=...
    poetry run test-parser CO production
    poetry run test-parser CO production --target_datetime "2025-01-01T00:00:00-05:00"
    poetry run test-parser CO consumption
    poetry run test-parser CO consumption --target_datetime "2025-01-01T00:00:00-05:00"
    poetry run test-parser CO price
    poetry run test-parser CO price --target_datetime "2025-01-01T00:00:00-05:00"
    
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

@consideRatio
Copy link
Contributor Author

@VIKTORVAV99 I got this parser functional with this PR, but it builds on #7686 currently so I've made it draft until that PR resolves one way or another.

Changes:

- Makes calling `fetch_production()` without args or kwargs not run into
  issues stemming from `zone_key` being explicitly passed as None.
- Adds a comment on what webshare.io subscription is useful for use by
  this project.
- Re-configures session.proxies back to what it was in a way that I
  think now will work, while previously I think we just stored a
  reference to the proxies object that we then also modified.

  This likely won't impact anyone.
- Adjusted the code for readability, which is an opinionated matter of
  course.
@consideRatio consideRatio marked this pull request as ready for review January 7, 2025 23:39
@consideRatio
Copy link
Contributor Author

Learned more about pandas doing this work! It now works and tests are added to help future maintenance of this parser.

@consideRatio consideRatio changed the title fix(parsers, CO): start using a CO proxy as it now is needed fix(parsers, CO): adopt use_proxy, fix parsing, add tests Jan 7, 2025
Comment on lines +59 to +61
@use_proxy(country_code="CO", monkeypatch_for_pydataxm=True)
def fetch_consumption(
zone_key: ZoneKey,
zone_key: ZoneKey = ZoneKey("CO"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I think this makes sense I need to double check a few things internally before we can merge this, specifically how much bandwidth/data we have available first as they don't yet support pay as you go billing or if we need to increase this so not all parsers that use the proxy goes down.

Hopefully I can get this done tomorrow or on Friday otherwise it will be early next week.

@VIKTORVAV99 VIKTORVAV99 self-requested a review January 8, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser python Pull requests that update Python code tests zone config Pull request or issue for zone configurations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Colombian electricity data is not up date CO production parser down
2 participants