Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
time_attention.py · 2.0 KB · 61 lines
1"""system_time_attention -- how much logged time is waiting for an approver.
2
3COUNT {} -> {count, detail}
4
5`submitted` on a time log is a gate with a second person in it: the
6approver is deliberately not the person who logged the hours, so this
7queue can only ever be cleared by somebody who has no reason to know it
8exists. That is exactly the shape of queue that quietly grows for a month
9and then turns into an invoicing argument, and exactly what an attention
10count is for.
11
12The detail carries hours rather than a second count, because "9 entries"
13and "62 hours" are different amounts of urgency and only the second one
14tells an approver how much of their afternoon this is.
15
16COUNT rather than GET or POST: the verb is the contract with the daemon's
17attention pass. Nothing here writes. A missing collection reads as zero
18(app-timers not installed here); a genuine failure raises, so the rollup
19records an error and keeps the last count instead of reporting calm.
20"""
21
22import os
23
24import object_records
25
26ACTOR = "system_time_attention"
27
28# draft is still being worked on, approved/rejected have had a decision,
29# billed is on an invoice. `submitted` is the one that is waiting.
30WAITING_STATUS = "submitted"
31
32
33def _base_dir():
34 return os.environ.get("DBBASIC_DATA_DIR", "data")
35
36
37def _text(value):
38 return str(value if value is not None else "").strip()
39
40
41def _seconds(value):
42 try:
43 return int(_text(value) or 0)
44 except ValueError:
45 # A hand-edited duration must not take the count down with it.
46 return 0
47
48
49def COUNT(request):
50 try:
51 rows = object_records.read_collection_records("time_logs", base_dir=_base_dir())
52 except Exception:
53 return {"count": 0}
54
55 waiting = [row for row in rows if _text(row.get("status")) == WAITING_STATUS]
56 if not waiting:
57 return {"count": 0}
58
59 hours = sum(_seconds(row.get("duration_seconds")) for row in waiting) / 3600.0
60 detail = f"{hours:.1f} hours awaiting approval" if hours else ""
61 return {"count": len(waiting), "detail": detail}