fix: koreksi pembulatan ke entry terbesar, filter author date ketat
- distribute_hours: simpan diff pembulatan ke entry terbesar (bukan terakhir) agar tidak bisa jadi 0.00h saat banyak entry - get_commits_today: filter strict author date = today, cegah commit dari hari lain yg di-rebase/push masuk ke timesheet hari ini Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -212,6 +212,9 @@ def get_commits_today(repo_path: str, author: str, today: str) -> list[dict]:
|
||||
parts = line.split("|", 2)
|
||||
if len(parts) == 3:
|
||||
dt = datetime.strptime(parts[1], "%Y-%m-%d %H:%M")
|
||||
# Filter ketat: pastikan author date = today (bukan commit dari hari lain yg di-rebase)
|
||||
if dt.strftime("%Y-%m-%d") != today:
|
||||
continue
|
||||
commits.append({
|
||||
"hash": parts[0],
|
||||
"date": dt.strftime("%Y-%m-%d"),
|
||||
@@ -246,12 +249,14 @@ def commit_spans(sorted_commits: list[dict]) -> list[int]:
|
||||
|
||||
|
||||
def distribute_hours(weights: list[int], total: float = 8.0) -> list[float]:
|
||||
"""Pro-rata berdasarkan bobot (menit span). Sum = total. Adjustment di entry terakhir."""
|
||||
"""Pro-rata berdasarkan bobot (menit span). Sum = total. Adjustment di entry terbesar."""
|
||||
total_weight = sum(weights)
|
||||
raw = [Decimal(str(total)) * Decimal(w) / Decimal(total_weight) for w in weights]
|
||||
rounded = [float(r.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)) for r in raw]
|
||||
diff = round(total - sum(rounded), 2)
|
||||
rounded[-1] = round(rounded[-1] + diff, 2)
|
||||
# Terapkan koreksi ke entry terbesar agar tidak bisa jadi 0
|
||||
largest_idx = rounded.index(max(rounded))
|
||||
rounded[largest_idx] = round(rounded[largest_idx] + diff, 2)
|
||||
return rounded
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user