Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
51f874b
set constant values
Nerey999 Sep 21, 2026
358a608
write all functions and fix some problems
Nerey999 Sep 24, 2026
96aed83
Merge branch 'python-department:main' into main
Nerey999 Sep 24, 2026
cac8227
delete last comments in constants.py
Nerey999 Sep 24, 2026
f19c891
add tests(pytest) generated by AI. Fix problems.
Nerey999 Sep 24, 2026
0ff10e7
add pytest in uv.lock and bash-script to fix problems with formatting
Nerey999 Sep 24, 2026
e999d95
add format ruff fix in script
Nerey999 Sep 24, 2026
8aa1413
Merge branch 'python-department:main' into main
Nerey999 Sep 26, 2026
f1d8bbb
move test files
Nerey999 Sep 26, 2026
97f246d
add constants
Nerey999 Sep 26, 2026
5923e23
add AI generated tests
Nerey999 Sep 26, 2026
1b1f922
Implement utils.py
Nerey999 Sep 26, 2026
8966ac4
write remaining functions
Nerey999 Oct 1, 2026
ebb1f5d
write all functions in cart
Nerey999 Oct 1, 2026
a1b5566
update tests to support any tuple indices
Nerey999 Oct 2, 2026
eceab67
Merge branch 'python-department:main' into main
Nerey999 Oct 11, 2026
236b80c
add AI tests
Nerey999 Oct 11, 2026
0d25788
rename test names
Nerey999 Oct 12, 2026
7b6ad21
complete TODO functions in crud, storage, utils
Nerey999 Oct 12, 2026
45c1250
add other TODO functions+refactor(Complete task 3)
Nerey999 Oct 12, 2026
ddc3ca6
Merge branch 'python-department:main' into main
Nerey999 Oct 30, 2026
885153d
Merge branch 'task3'
Nerey999 Oct 30, 2026
43b8434
utils.py
Nerey999 Nov 1, 2026
0d7b762
AI generated tests + refactor + storage.py
Nerey999 Nov 1, 2026
d31b59a
fix utils.py
Nerey999 Nov 1, 2026
1777e9b
cart.py and crud.py + refactor utils.py
Nerey999 Nov 1, 2026
901f79b
run_admin.py
Nerey999 Nov 1, 2026
ca652f5
fixes + refactor
Nerey999 Nov 1, 2026
d73ac42
mypy fix
Nerey999 Nov 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions fix_and_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/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 "All done."
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies = []
dev = [
"mypy==2.3.1",
"ruff==0.16.8",
"pytest==9.1.1",
]

[tool.ruff]
Expand All @@ -33,3 +34,13 @@ avoid-escape = true
[tool.ruff.lint.isort]
lines-after-imports = 2
split-on-trailing-comma = true

[tool.mypy]
strict = true
files = ["src"]
mypy_path = "src"
explicit_package_bases = true

[tool.pytest.ini_options]
pythonpath = ["src"]
testpaths = ["src/tests"]
22 changes: 8 additions & 14 deletions src/part1/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@
from typing import Final


# TODO: замените заглушки (0) на корректные значения, см. TASK.md.
# Все константы, зависящие от ёмкостей *_BITS, должны вычисляться из них.

# Twitter's original Snowflake epoch: 2010-11-04 01:42:54.657 UTC.
EPOCH_MS_DEFAULT: Final[int] = 0
EPOCH_MS_DEFAULT: Final[int] = 1288834974657

# Node identifier used when the caller does not supply one.
NODE_ID_DEFAULT: Final[int] = 0
NODE_ID_DEFAULT: Final[int] = 1

# Width of each field, in bits.
TIMESTAMP_BITS: Final[int] = 0
NODE_ID_BITS: Final[int] = 0
SEQUENCE_ID_BITS: Final[int] = 0
TIMESTAMP_BITS: Final[int] = 41
NODE_ID_BITS: Final[int] = 10
SEQUENCE_ID_BITS: Final[int] = 12

# Largest value each field can hold.
TIMESTAMP_MS_MAX: Final[int] = 0
NODE_ID_MAX: Final[int] = 0
SEQUENCE_ID_MAX: Final[int] = 0

# Здесь можно добавить собственные вспомогательные константы
# (например, сдвиги полей при сборке идентификатора).
TIMESTAMP_MS_MAX: Final[int] = 2**TIMESTAMP_BITS - 1
NODE_ID_MAX: Final[int] = 2**NODE_ID_BITS - 1
SEQUENCE_ID_MAX: Final[int] = 2**SEQUENCE_ID_BITS - 1
37 changes: 25 additions & 12 deletions src/part1/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)


def generate_snowflake_id(
Expand Down Expand Up @@ -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))
| (node_id << SEQUENCE_ID_BITS)
| sequence_id
)
Loading
Loading