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

DSR GET Method - Filter by Column #133

Merged
merged 9 commits into from
Sep 26, 2023
Merged

Conversation

CWestICL
Copy link
Contributor

@CWestICL CWestICL commented Sep 22, 2023

Added functionality for filtering by column when making a GET request for DSR data. Columns can be specified with a query parameter with multiple values being separated by comma. E.g. /dsr?col=activity types,kwh cost

Default behaviour of index filtering has also been modified. By default, the DSR GET method now only exports the most recent value in the DSR data array. This can be changed with the start and end query parameters.

Closes #131

Opened in draft as tests need to be updated.

@CWestICL CWestICL self-assigned this Sep 22, 2023
@CWestICL CWestICL marked this pull request as ready for review September 22, 2023 15:49
Copy link
Collaborator

@AdrianDAlessandro AdrianDAlessandro left a comment

Choose a reason for hiding this comment

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

Overall really good, but there are a couple of small details that need changing. Specifically that we need to use the field name and not the alias in the query because spaces in urls are not good. I tied myself in knots trying to work out the parts of the code that need to change, so I ended up just making the changes myself. I'll push them.

Let me know if you're ok with my changes and I'll approve and merge it.

datahub/main.py Outdated
@@ -155,7 +155,9 @@ def upload_dsr(file: UploadFile) -> dict[str, str | None]:


@app.get("/dsr", response_class=ORJSONResponse)
def get_dsr_data(start: int = 0, end: int | None = None) -> ORJSONResponse:
def get_dsr_data(
start: int = len(dt.dsr_data) - 1, end: int | None = None, col: str | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default value of start won't update with dt.dsr_data, if will just get the value from the first time it is defined. Luckily, we can just use -1 (it has probably worked so far because the length would be 0 to begin with).

Suggested change
start: int = len(dt.dsr_data) - 1, end: int | None = None, col: str | None = None
start: int = -1, end: int | None = None, col: str | None = None

@CWestICL
Copy link
Contributor Author

Yep, all looks good to me. Happy to get this merged.

@AdrianDAlessandro AdrianDAlessandro merged commit d23211d into develop Sep 26, 2023
5 checks passed
@AdrianDAlessandro AdrianDAlessandro deleted the dsr-column-get branch September 26, 2023 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Send over only the data that is required in DSR GET method
2 participants