fix: Números measures what Dropstar asked: machines by film printed, stages by order
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 3m23s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m7s

- a machine's metres are the film printed, not the metres billed, which round
  up to one metre and made small orders look like fast printing
- orders in Imprimindo together on one machine count that time once
- a stage's median time is per order, the sum of its passages, so rework
  reads as one slow order instead of quick passages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-22 15:25:08 -03:00
parent 80975b9424
commit 3ae453f47a
5 changed files with 80 additions and 19 deletions

View File

@@ -22,12 +22,15 @@ def signed_in(email, password=PASSWORD):
return client
def order_fixture(c, owner, mode, metres='1'):
"""A paid order straight in the database, as the payment would leave it."""
def order_fixture(c, owner, mode, metres='1', printed=None):
"""A paid order straight in the database, as the payment would leave it:
`metres` billed, `printed` the film the sheet takes, when it differs."""
quote, order = uuid4(), uuid4()
item = {'mode': mode, 'grade': 100, 'billed_metres': metres, 'unit_cents': 1490, 'uploads': []}
if printed is not None:
item['metres'] = printed
content = {'customer': {'mail': 'm@example.test', 'cnpj': '11222333000181', 'zap': '16999999999'},
'items': [{'mode': mode, 'grade': 100, 'billed_metres': metres, 'unit_cents': 1490,
'uploads': []}], 'freight': {'service': 'pickup'}, 'total_cents': 1490}
'items': [item], 'freight': {'service': 'pickup'}, 'total_cents': 1490}
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
VALUES(%s,%s,%s,'users-fixture',%s,%s,now())''', (quote, owner, uuid4(), Jsonb(content), Jsonb(content)))
c.execute('INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment) VALUES(%s,%s,%s,%s,%s)',
@@ -209,20 +212,36 @@ def run():
board = {o['id']: o for o in su.call('/operator/board', operator=True)['orders']}
assert not board[second]['machine']['chosen']
# Números per machine: an order printed for half an hour on its machine, then finished.
# Números per machine: an order printed for half an hour on its machine, then
# finished. It counts the film printed (0,40 m), not the metre billed.
before = {m['id']: m for m in su.call('/operator/stats?days=7', operator=True)['machines']}
with db.connect() as c:
# A real payment: Números leaves test orders out.
c.execute('UPDATE dtf_local.orders SET payment=%s WHERE id=%s',
c.execute('''UPDATE dtf_local.orders SET payment=%s,
snapshot=jsonb_set(snapshot, '{items,0,metres}', '"0.40"') WHERE id=%s''',
(Jsonb({'provider': 'mercadopago', 'id': f'users-{tag}'}), third))
for frm, to, at in (('rec', 'imp', "now()-interval '30 minutes'"), ('imp', 'fin', 'now()')):
c.execute(f'''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,created_at)
VALUES(%s,%s,%s,'users-test','',false,{at})''', (third, frm, to))
after = {m['id']: m for m in su.call('/operator/stats?days=7', operator=True)['machines']}
assert after[target]['orders'] == before[target]['orders'] + 1
assert after[target]['metres'] == before[target]['metres'] + 1.0
assert round(after[target]['metres'] - before[target]['metres'], 2) == 0.4, (before[target], after[target])
assert after[target]['last_finished'] and after[target]['metres_per_hour'] is not None
assert after[target]['printing_hours'] >= before[target]['printing_hours'] + 0.49
# Two orders printing at once on one machine: the half hour they share counts
# once, so the machine did 1,50 m in 0,5 h, not in 1 h.
with db.connect() as c:
together = [order_fixture(c, owner, 'file', printed=printed) for printed in ('0.60', '0.90')]
made.extend(together)
for _, oid in together:
c.execute('''UPDATE dtf_local.orders SET payment=%s, state='fin', machine_id=%s, machine_chosen=true
WHERE id=%s''', (Jsonb({'provider': 'mercadopago', 'id': f'users-{tag}-{oid}'}), textil2, oid))
for frm, to, at in (('rec', 'imp', "now()-interval '30 minutes'"), ('imp', 'fin', 'now()')):
c.execute(f'''INSERT INTO dtf_local.movements(order_id,from_state,to_state,operator,reason,back,created_at)
VALUES(%s,%s,%s,'users-test','',false,{at})''', (oid, frm, to))
shared = next(m for m in su.call('/operator/stats?days=7', operator=True)['machines'] if m['id'] == textil2)
assert (shared['orders'], shared['metres'], shared['printing_hours'], shared['metres_per_hour']) == \
(2, 1.5, 0.5, 3.0), shared
# Switched off, a machine gives its automatic orders to another one.
with db.connect() as c: