-
Notifications
You must be signed in to change notification settings - Fork 23
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
Hydration #61
Open
matin
wants to merge
9
commits into
main
Choose a base branch
from
hydration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hydration #61
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1cae471
daily hydration
matin 402add5
fix typo
matin 89eaa14
testing
matin 63e11eb
version bump
matin ea47b50
coderabbit config
matin 05e72c1
use parens
matin 7012890
fix typing
matin 02ad953
coderabbit path instructions
matin 4546623
minor
matin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations | ||
language: "en-US" | ||
early_access: true | ||
reviews: | ||
profile: "assertive" | ||
request_changes_workflow: false | ||
high_level_summary: true | ||
poem: false | ||
review_status: true | ||
collapse_walkthrough: false | ||
auto_review: | ||
enabled: true | ||
drafts: false | ||
path_filters: | ||
- "!tests/**/cassettes/**" | ||
path_instructions: | ||
- path: "tests/**" | ||
instructions: | | ||
- test functions shouldn't have a return type hint | ||
- it's ok to use `assert` instead of `pytest.assume()` | ||
chat: | ||
auto_reply: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
from datetime import date, timedelta | ||
from typing import ClassVar, List, Optional, Union | ||
from typing import ClassVar, List, Optional, Type, Union | ||
|
||
from pydantic.dataclasses import dataclass | ||
|
||
from .. import http | ||
from ..utils import camel_to_snake_dict, format_end_date | ||
|
||
BASE_PATH = "/usersummary-service/stats/stress" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Stats: | ||
|
@@ -18,7 +16,7 @@ class Stats: | |
|
||
@classmethod | ||
def list( | ||
cls, | ||
cls: Type["Stats"], | ||
end: Union[date, str, None] = None, | ||
period: int = 1, | ||
*, | ||
|
@@ -32,15 +30,14 @@ def list( | |
page = cls.list(end, cls._page_size, client=client) | ||
if not page: | ||
return [] | ||
page = ( | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider optimizing recursive calls. The recursive call to def list(
cls: Type["Stats"],
end: Union[date, str, None] = None,
period: int = 1,
*,
client: Optional[http.Client] = None,
) -> List["Stats"]:
client = client or http.client
end = format_end_date(end)
period_type = "days" if "daily" in cls._path else "weeks"
results = []
while period > cls._page_size:
page = cls.list(end, cls._page_size, client=client)
if not page:
return results
results = page + results
end -= timedelta(**{period_type: cls._page_size})
period -= cls._page_size
start = end - timedelta(**{period_type: period - 1})
path = cls._path.format(start=start, end=end, period=period)
page_dirs = client.connectapi(path)
if not page_dirs:
return results
if "values" in page_dirs[0]:
page_dirs = [{**stat, **stat.pop("values")} for stat in page_dirs]
page_dirs = [camel_to_snake_dict(stat) for stat in page_dirs]
return [cls(**stat) for stat in page_dirs] + results |
||
cls.list( | ||
end - timedelta(**{period_type: cls._page_size}), | ||
period - cls._page_size, | ||
client=client, | ||
) | ||
+ page | ||
) | ||
return page | ||
|
||
start = end - timedelta(**{period_type: period - 1}) | ||
path = cls._path.format(start=start, end=end, period=period) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import ClassVar | ||
|
||
from pydantic.dataclasses import dataclass | ||
|
||
from ._base import Stats | ||
|
||
BASE_PATH = "/usersummary-service/stats/hydration" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DailyHydration(Stats): | ||
value_in_ml: float | ||
goal_in_ml: float | ||
|
||
_path: ClassVar[str] = f"{BASE_PATH}/daily/{{start}}/{{end}}" | ||
_page_size: ClassVar[int] = 28 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.4.46" | ||
__version__ = "0.4.47" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Authorization: | ||
- Bearer SANITIZED | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 | ||
(KHTML, like Gecko) Mobile/15E148 | ||
method: GET | ||
matin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uri: https://connectapi.garmin.com/usersummary-service/stats/hydration/daily/2024-06-29/2024-06-29 | ||
response: | ||
body: | ||
string: '[{"calendarDate": "2024-06-29", "valueInML": 1750.0, "goalInML": 2800.0}]' | ||
headers: | ||
CF-Cache-Status: | ||
- DYNAMIC | ||
CF-RAY: | ||
- 89baf564a97ac302-IAH | ||
Cache-Control: | ||
- no-cache, no-store, private | ||
Connection: | ||
- keep-alive | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Sun, 30 Jun 2024 03:09:37 GMT | ||
NEL: | ||
- '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}' | ||
Report-To: | ||
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=GRxjJQH4AeepFPPzqKaKzuF%2FwWsdMivGK4yskWFLewsm9h57VSu9AdrdMi9bdST3vzQ4oVJDxEfU4vR6EXLlsbom6nYoo6nCAtih9MJ3sIlW7aih0DTEBXrNcwILDtsSsmHmUe%2FM1A%3D%3D"}],"group":"cf-nel","max_age":604800}' | ||
Server: | ||
- cloudflare | ||
Set-Cookie: | ||
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- _cfuvid=SANITIZED; path=SANITIZED; domain=SANITIZED; HttpOnly; Secure; SameSite=SANITIZED | ||
Transfer-Encoding: | ||
- chunked | ||
alt-svc: | ||
- h3=":443"; ma=86400 | ||
pragma: | ||
- no-cache | ||
set-cookie: | ||
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED; | ||
Secure | ||
- _cfuvid=SANITIZED; path=SANITIZED; domain=SANITIZED; HttpOnly; Secure; SameSite=SANITIZED | ||
status: | ||
code: 200 | ||
matin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message: OK | ||
version: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from datetime import date | ||
|
||
import pytest | ||
|
||
from garth import DailyHydration | ||
from garth.http import Client | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_daily_hydration(authed_client: Client): | ||
matin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end = date(2024, 6, 29) | ||
daily_hydration = DailyHydration.list(end, client=authed_client) | ||
assert daily_hydration[-1].calendar_date == end | ||
matin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider adding a description for the schema URL.
Adding a brief description for the schema URL can improve the readability of the configuration file.
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations
Would you like me to add this comment for better clarity?
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.
yes
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.
@matin, I've added the requested description to the
.coderabbit.yaml
file for better clarity.# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json # Schema for CodeRabbit configurations
This should improve the readability of the configuration file.
Learnings added