-
Notifications
You must be signed in to change notification settings - Fork 961
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
base: master
Are you sure you want to change the base?
Conversation
45cb72f
to
a0d7277
Compare
@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. |
a0d7277
to
93c52b6
Compare
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.
1513212
to
c5f8eb7
Compare
Learned more about pandas doing this work! It now works and tests are added to help future maintenance of this parser. |
@use_proxy(country_code="CO", monkeypatch_for_pydataxm=True) | ||
def fetch_consumption( | ||
zone_key: ZoneKey, | ||
zone_key: ZoneKey = ZoneKey("CO"), |
There was a problem hiding this comment.
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.
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__
andrequests.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
poetry run test_parser "zone_key"
pnpx prettier@2 --write .
andpoetry run format
in the top level directory to format my changes.