mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-11 15:34:02 +01:00
Some checks are pending
code-runner pre-commit / pre-commit (push) Waiting to run
code-runner tests / test (push) Waiting to run
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
focus-project pre-commit / pre-commit (push) Waiting to run
focus-project tests / test (push) Waiting to run
leetcode-coach pre-commit / pre-commit (push) Waiting to run
leetcode-coach tests / test (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
sql-drills pre-commit / pre-commit (push) Waiting to run
sql-drills tests / test (push) Waiting to run
Minutes past a day's target bank (max 60) and pay on the next project day; status shows real minutes (121/120) plus carried_in/carry_out; carry ledger rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWYGW5NZL5uVpnqmNKo
32 lines
893 B
Python
32 lines
893 B
Python
# Copyright (c) 2026 Krzysztof Rudnicki
|
|
"""A project day's own worked minutes: the union of every source's intervals."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from focus_project import sources
|
|
|
|
if TYPE_CHECKING:
|
|
from datetime import date
|
|
|
|
from focus_project._model import Project
|
|
|
|
|
|
def union_seconds(spans: list[sources.Interval]) -> float:
|
|
"""Total length of the union of ``spans``."""
|
|
total = 0.0
|
|
end = float("-inf")
|
|
for lo, hi in sorted(spans):
|
|
if hi <= end:
|
|
continue
|
|
total += hi - max(lo, end)
|
|
end = hi
|
|
return total
|
|
|
|
|
|
def own_minutes_of(project: Project, day: date, moment: float) -> int:
|
|
"""Whole minutes worked on ``day``, uncapped, nothing after ``moment``."""
|
|
spans = sources.clip(sources.collect(day, project), (float("-inf"), moment))
|
|
return int(union_seconds(spans) // 60)
|