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
bank_attention.py · 2.7 KB · 79 lines
1"""system_bank_attention -- how many bank lines nothing has matched.
2
3COUNT {} -> {count, detail}
4
5`match_status: unmatched` is the reconciliation queue in one field: money
6moved in the real world and this server has no book record that explains
7it. `system_bank_matcher` has already had its go and either found nothing
8or found nothing it was confident enough to accept, so what is left is
9precisely the set a person has to look at.
10
11`suggested` is deliberately NOT counted. A suggestion is the machine
12having done its job; the line is answerable in one click from /reconcile
13and does not need the front page to say so. Only `unmatched` -- nothing
14proposed, nobody has looked -- is a queue in the sense this layer means.
15
16The detail names how many have been sitting there long enough that
17`system_bank_escalation` would already have raised them, because a line
18unmatched this morning and a line unmatched since March are the same row
19count and completely different problems.
20
21COUNT rather than GET or POST: the verb is the contract with the daemon's
22attention pass. Nothing here writes. A missing collection reads as zero;
23a genuine failure raises, so the rollup records it and keeps the last
24count rather than reporting a reconciled bank that nobody reconciled.
25"""
26
27import os
28from datetime import date
29
30import object_records
31
32ACTOR = "system_bank_attention"
33
34# Nothing proposed and nobody has looked. `suggested` has a candidate,
35# `matched` and `resolved` have an answer.
36WAITING_STATUS = "unmatched"
37
38# The same silence window system_bank_escalation defaults to, so the two
39# surfaces cannot disagree about what "stale" means on one deployment.
40STALE_DAYS = 7
41
42
43def _base_dir():
44 return os.environ.get("DBBASIC_DATA_DIR", "data")
45
46
47def _text(value):
48 return str(value if value is not None else "").strip()
49
50
51def _day(value):
52 try:
53 year, month, day = (int(part) for part in _text(value).split("-"))
54 return date(year, month, day)
55 except (ValueError, AttributeError):
56 # A line with no posting date still counts; it just says nothing
57 # about age.
58 return None
59
60
61def COUNT(request):
62 try:
63 rows = object_records.read_collection_records("bank_lines", base_dir=_base_dir())
64 except Exception:
65 return {"count": 0}
66
67 today = date.today()
68 waiting = [row for row in rows
69 if _text(row.get("match_status") or WAITING_STATUS) == WAITING_STATUS]
70 if not waiting:
71 return {"count": 0}
72
73 stale = 0
74 for row in waiting:
75 posted = _day(row.get("posted_on"))
76 if posted is not None and (today - posted).days >= STALE_DAYS:
77 stale += 1
78 detail = f"{stale} older than {STALE_DAYS} days" if stale else ""
79 return {"count": len(waiting), "detail": detail}