Repository navigation
1. Сабуров Ярослав Семенович. 614 #27
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
Open
Nerey999
wants to merge
31
commits into
python-department:main
Choose a base branch
from
Nerey999:main
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
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
51f874b
set constant values
Nerey999 358a608
write all functions and fix some problems
Nerey999 96aed83
Merge branch 'python-department:main' into main
Nerey999 cac8227
delete last comments in constants.py
Nerey999 f19c891
add tests(pytest) generated by AI. Fix problems.
Nerey999 0ff10e7
add pytest in uv.lock and bash-script to fix problems with formatting
Nerey999 e999d95
add format ruff fix in script
Nerey999 8aa1413
Merge branch 'python-department:main' into main
Nerey999 f1d8bbb
move test files
Nerey999 97f246d
add constants
Nerey999 5923e23
add AI generated tests
Nerey999 1b1f922
Implement utils.py
Nerey999 8966ac4
write remaining functions
Nerey999 ebb1f5d
write all functions in cart
Nerey999 a1b5566
update tests to support any tuple indices
Nerey999 eceab67
Merge branch 'python-department:main' into main
Nerey999 236b80c
add AI tests
Nerey999 0d25788
rename test names
Nerey999 7b6ad21
complete TODO functions in crud, storage, utils
Nerey999 45c1250
add other TODO functions+refactor(Complete task 3)
Nerey999 ddc3ca6
Merge branch 'python-department:main' into main
Nerey999 885153d
Merge branch 'task3'
Nerey999 43b8434
utils.py
Nerey999 0d7b762
AI generated tests + refactor + storage.py
Nerey999 d31b59a
fix utils.py
Nerey999 1777e9b
cart.py and crud.py + refactor utils.py
Nerey999 901f79b
run_admin.py
Nerey999 ca652f5
fixes + refactor
Nerey999 d73ac42
mypy fix
Nerey999 0b59ed8
add mypy check in script
Nerey999 b8dc91a
Merge branch 'python-department:main' into main
Nerey999 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 hidden or 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,25 @@ | ||
| #!/usr/bin/env bash | ||
| # Auto-fix imports/format, then run tests. | ||
| set -euo pipefail | ||
|
|
||
| cd "$(dirname "$0")" | ||
|
|
||
| if ! command -v uv >/dev/null 2>&1; then | ||
| echo "Error: uv is not installed. Install it: https://docs.astral.sh/uv/getting-started/installation/" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "==> Install dependencies" | ||
| uv sync --locked | ||
|
|
||
| echo "==> Ruff fix (imports, lint)" | ||
| uv run ruff check --fix src | ||
| uv run ruff format src | ||
|
|
||
| echo "==> Pytest" | ||
| uv run pytest src/part4/tests | ||
|
|
||
| echo "==> MyPy" | ||
| uv run mypy --strict src | ||
|
|
||
| echo "All done." |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,12 +13,14 @@ | |
| :func:`decode_node_id` and :func:`decode_sequence_id`. | ||
| """ | ||
|
|
||
| import time # noqa: F401 | ||
| import time | ||
|
|
||
| from .constants import ( # noqa: F401 | ||
| from .constants import ( | ||
| EPOCH_MS_DEFAULT, | ||
| NODE_ID_BITS, | ||
| NODE_ID_DEFAULT, | ||
| NODE_ID_MAX, | ||
| SEQUENCE_ID_BITS, | ||
| SEQUENCE_ID_MAX, | ||
| TIMESTAMP_MS_MAX, | ||
| ) | ||
|
|
@@ -34,8 +36,7 @@ def read_current_millis(epoch_ms: int) -> int: | |
| The count of whole milliseconds between ``epoch_ms`` and now. May be | ||
| negative if ``epoch_ms`` lies in the future. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| return int(time.time() * 1000) - epoch_ms | ||
|
|
||
|
|
||
| def decode_timestamp_ms(snowflake_id: int, epoch_ms: int = EPOCH_MS_DEFAULT) -> int: | ||
|
|
@@ -50,8 +51,7 @@ def decode_timestamp_ms(snowflake_id: int, epoch_ms: int = EPOCH_MS_DEFAULT) -> | |
| The absolute Unix time in milliseconds at which the identifier was | ||
| generated. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| return epoch_ms + (snowflake_id >> (NODE_ID_BITS + SEQUENCE_ID_BITS)) | ||
|
|
||
|
|
||
| def decode_node_id(snowflake_id: int) -> int: | ||
|
|
@@ -64,8 +64,7 @@ def decode_node_id(snowflake_id: int) -> int: | |
| The node identifier packed into ``snowflake_id``, in the range | ||
| ``[0, NODE_ID_MAX]``. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| return (snowflake_id >> SEQUENCE_ID_BITS) & ((1 << NODE_ID_BITS) - 1) | ||
|
|
||
|
|
||
| def decode_sequence_id(snowflake_id: int) -> int: | ||
|
|
@@ -78,8 +77,7 @@ def decode_sequence_id(snowflake_id: int) -> int: | |
| The per-millisecond sequence counter packed into ``snowflake_id``, in | ||
| the range ``[0, SEQUENCE_ID_MAX]``. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| return (snowflake_id) & ((1 << SEQUENCE_ID_BITS) - 1) | ||
|
Member
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. |
||
|
|
||
|
|
||
| def generate_snowflake_id( | ||
|
|
@@ -110,5 +108,20 @@ def generate_snowflake_id( | |
| timestamp field (roughly 69 years after ``epoch_ms``). In each of those | ||
| cases an explanatory message is printed to stdout first. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| if not (0 <= node_id <= NODE_ID_MAX): | ||
| print(f"node_id must be in [0, {NODE_ID_MAX}], received {node_id}") | ||
| return None | ||
| if not (0 <= sequence_id <= SEQUENCE_ID_MAX): | ||
| print(f"sequence_id must be in [0, {SEQUENCE_ID_MAX}], received {sequence_id}") | ||
| return None | ||
|
|
||
| elapsed = read_current_millis(epoch_ms) | ||
| if elapsed > TIMESTAMP_MS_MAX: | ||
| print("overflows") | ||
| return None | ||
|
|
||
| return ( | ||
| (elapsed << (NODE_ID_BITS + SEQUENCE_ID_BITS)) | ||
|
Member
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. Это значение тоже рассчитывалось ранее. Так что аналогично |
||
| | (node_id << SEQUENCE_ID_BITS) | ||
| | sequence_id | ||
| ) | ||
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.
Вы же определили константу
NODE_ID_MAX, зачем рассчитывать это значение еще раз тут:(1 << NODE_ID_BITS) - 1. Получается копипаста, нарушение критерияS1- минус балл