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
reorder_attention.py · 2.2 KB · 67 lines
1"""system_reorder_attention -- how many shelves are waiting on a decision.
2
3COUNT {} -> {count, detail}
4
5The open reorder suggestions, and nothing else. `ordered` means somebody
6went and bought some; `dismissed` means somebody looked and said no, which
7is a real answer and has to be available -- a count that could not be
8dismissed would stay permanently lit and teach people to stop reading the
9whole band it sits in.
10
11Severity `warning` rather than `normal` in the manifest: unlike a receipt
12sitting in a queue somebody put it in, nobody chose to be here, and the
13consequence of ignoring it is running out of something a customer wants
14to buy. It is not `urgent` -- that is reserved for the server reporting
15that it stopped doing its own work, and a low shelf is a business problem
16rather than a broken machine.
17
18The detail names the WORST one rather than a total, because "12 products
19to reorder" is a number and "12 products to reorder, one is 6 below its
20point" is a reason to open the page.
21
22Degrades to zero when reorder_suggestions is absent rather than raising,
23the same posture system_shipment_attention and system_scan_attention
24take: a rollup pass should not log an error every five minutes about a
25collection nobody installed.
26"""
27
28import os
29
30import object_records
31
32ACTOR = "system_reorder_attention"
33
34WAITING_STATUS = "open"
35
36
37def _text(value):
38 return str(value if value is not None else "").strip()
39
40
41def _number(value):
42 try:
43 return float(_text(value) or 0)
44 except (TypeError, ValueError):
45 return 0.0
46
47
48def COUNT(request):
49 base = os.environ.get("DBBASIC_DATA_DIR", "data")
50 try:
51 rows = object_records.read_collection_records("reorder_suggestions",
52 base_dir=base)
53 except Exception:
54 return {"count": 0}
55
56 waiting = [row for row in rows
57 if _text(row.get("status")) == WAITING_STATUS]
58 if not waiting:
59 return {"count": 0}
60
61 gaps = [_number(row.get("reorder_point")) - _number(row.get("on_hand"))
62 for row in waiting]
63 worst = max(gaps)
64 if worst <= 0:
65 return {"count": len(waiting)}
66 return {"count": len(waiting),
67 "detail": f"one is {worst:g} below its point"}