Compare commits

...

2 Commits

Author SHA1 Message Date
Cauê Faleiros
ba85168c09 fix: parts of 10 m are the code's default too, not only the stack's
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 7m58s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m21s
A stack without PRINT_PART_CM (the local one and CI) cut films in 15 m parts,
4,8 GB decoded, which FlexiPRINT refuses (Marcus, 2026-11-18). The comments
that still said 15 m now say a part.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 15:03:36 -03:00
Cauê Faleiros
b64947eb76 fix: a proof sheet counts its real length in the machine's metres, in metres, not 15 m
PROOF_SHEET_CM (15) was added to a total in metres, so every proof counted
15 m of film: one proof was enough for the 10 m cleaning alert, and Números
overstated production. A proof now counts the film it took, the finest
stroke's window and the colour samples with the clear film between them (up
to 30 cm, Marcus, 2026-11-26), read from its print file; 15 cm for a sheet
made before the samples. One function serves the machine log and Números.
The Kanban's proof rule says 30 cm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 15:03:36 -03:00
10 changed files with 86 additions and 60 deletions

View File

@@ -4,8 +4,8 @@ FlexiPRINT watches 3. Imprimindo/<máquina>/<C1|C2|C3|PREMIUM>/ and takes a
file out of it when it rips. When the operator pulls a card to Imprimindo, its
files go, as a copy, into its machine's folder for the item's contraction
class; a premium item always goes to PREMIUM, whichever class it carries;
the order's own file stays in its stage folder. A film over 15 m is several
parts (item 13): all on the same machine, in order. A machine's folder holds
the order's own file stays in its stage folder. A film longer than a part
(10 m) is several parts (item 13): all on the same machine, in order. A machine's folder holds
as many files at once as it has places in Imprimindo (machines.places, three
since 2026-11-17); the next is written when Flexi takes one.

View File

@@ -28,7 +28,8 @@ entry. Fewer than two entries, no estimate.
"Printed" is what left Imprimindo for Revisão on the machine (orders.machine_id,
the movement imp -> rev not back): the film metres of the items
(COALESCE(metres, billed_metres)), and PROOF_SHEET_CM per item for a proof card.
(COALESCE(metres, billed_metres)), and for a proof card the length of each
proof sheet (film_metres).
"""
from datetime import datetime, timezone
from decimal import Decimal
@@ -66,30 +67,48 @@ NOT_UNDONE = """NOT EXISTS (SELECT 1 FROM dtf_local.movements u WHERE u.order_id
AND u.id=(SELECT min(n.id) FROM dtf_local.movements n WHERE n.order_id=m.order_id AND n.id>m.id))"""
# Each proof sheet's stretches of film, {item index: [[top, bottom], ...]},
# from its print file (app/printpng.py); `o` is the order.
PROOF_WINDOWS = """(SELECT jsonb_object_agg(p.item_index::text, p.detail->'proof_windows')
FROM dtf_local.print_files p WHERE p.order_id=o.id AND p.detail ? 'proof_windows') AS windows"""
def film_metres(snapshot, items=None, windows=None):
"""The film one pass to Revisão printed, in metres, as Decimal: each
item's metres, on a reprint only the `items` that went again (#105). A
proof card's item is its sheet: the finest stroke's window and the colour
samples with the clear film between them, up to 30 cm (Marcus,
2026-11-26), from `windows` ({item index: [[top, bottom], ...]} in cm);
PROOF_SHEET_CM for a sheet made before the samples."""
from .printpng import PROOF_GAP_CM
from .proof import PROOF_SHEET_CM
snapshot = snapshot or {}
proof = bool(snapshot.get('proof_of'))
total = Decimal(0)
for index, item in enumerate(snapshot.get('items') or []):
if items is not None and index not in items:
continue
if proof:
stretches = (windows or {}).get(str(index)) or []
cm = (sum((Decimal(str(b)) - Decimal(str(a)) for a, b in stretches), Decimal(0))
+ PROOF_GAP_CM * (len(stretches) - 1)) if stretches else PROOF_SHEET_CM
total += cm / 100
else:
value = item.get('metres')
if value is None:
value = item.get('billed_metres')
total += Decimal(str(value or 0))
return total
def printed_since(c, machine_id, since):
"""Film metres the machine printed after `since` (None: ever), as Decimal."""
from .proof import PROOF_SHEET_CM
rows = c.execute(f'''SELECT o.snapshot, m.items FROM dtf_local.movements m
rows = c.execute(f'''SELECT o.snapshot, m.items, {PROOF_WINDOWS} FROM dtf_local.movements m
JOIN dtf_local.orders o ON o.id=m.order_id
WHERE o.machine_id=%s AND m.from_state='imp' AND m.to_state='rev' AND NOT m.back AND {NOT_UNDONE}
AND (%s::timestamptz IS NULL OR m.created_at > %s::timestamptz)''',
(machine_id, since, since)).fetchall()
total = Decimal(0)
for row in rows:
snapshot = row['snapshot'] or {}
proof = bool(snapshot.get('proof_of'))
for index, item in enumerate(snapshot.get('items') or []):
# A reprint counts only the items that went again (#105).
if row.get('items') is not None and index not in row['items']:
continue
if proof:
total += PROOF_SHEET_CM
else:
value = item.get('metres')
if value is None:
value = item.get('billed_metres')
total += Decimal(str(value or 0))
return total
return sum((film_metres(row['snapshot'], row.get('items'), row.get('windows')) for row in rows), Decimal(0))
def _last_entry(c, machine_id, kind, item):

View File

@@ -5,7 +5,7 @@ what the board already knows it printed, per machine and calendar month
(America/Sao_Paulo):
Produção printed metres (machine_log rule: imp -> rev, film metres,
PROOF_SHEET_CM per proof item); hours running = the union of the
a proof sheet its real length); hours running = the union of the
time its orders spent in Imprimindo, clipped to the month (two
orders printing together count once); metres per hour = printed
/ hours running; hours stopped = the "stop" events' minutes, in
@@ -33,7 +33,7 @@ from datetime import datetime, time
from decimal import Decimal, ROUND_HALF_UP
from zoneinfo import ZoneInfo
from .machine_log import NOT_UNDONE, SUPPLIES
from .machine_log import NOT_UNDONE, PROOF_WINDOWS, SUPPLIES, film_metres
SAO_PAULO = ZoneInfo('America/Sao_Paulo')
# The five inks Números lists, in the order the sheet knows them.
@@ -119,30 +119,15 @@ def ratios(printed, hours_running=None, supplies_cents=0, parts_cents=0, rolls=N
def _printed_orders(c, machine_id, start, end):
"""The orders that left Imprimindo for Revisão on the machine in the
period, with what is needed to count film and what they sold."""
return c.execute(f'''SELECT o.id, o.snapshot, o.parent_id, o.cancelled_at, o.payment, m.items
return c.execute(f'''SELECT o.id, o.snapshot, o.parent_id, o.cancelled_at, o.payment, m.items, {PROOF_WINDOWS}
FROM dtf_local.movements m JOIN dtf_local.orders o ON o.id=m.order_id
WHERE o.machine_id=%s AND m.from_state='imp' AND m.to_state='rev' AND NOT m.back AND {NOT_UNDONE}
AND m.created_at>=%s AND m.created_at<%s''', (machine_id, start, end)).fetchall()
def _film(snapshot, items=None):
"""The film printed for one order (machine_log's rule), as Decimal; on a
reprint only the `items` that went again."""
from .proof import PROOF_SHEET_CM
snapshot = snapshot or {}
proof = bool(snapshot.get('proof_of'))
total = Decimal(0)
for index, item in enumerate(snapshot.get('items') or []):
if items is not None and index not in items:
continue
if proof:
total += PROOF_SHEET_CM
else:
value = item.get('metres')
if value is None:
value = item.get('billed_metres')
total += Decimal(str(value or 0))
return total
def _film(row):
"""The film one printed order took (machine_log's rule), as Decimal."""
return film_metres(row['snapshot'], row.get('items'), row.get('windows'))
def _sold(row):
@@ -157,7 +142,7 @@ def _sold(row):
def printed_between(c, machine_id, start, end):
"""Film metres the machine printed in [start, end), as Decimal."""
return sum((_film(row['snapshot'], row.get('items')) for row in _printed_orders(c, machine_id, start, end)),
return sum((_film(row) for row in _printed_orders(c, machine_id, start, end)),
Decimal(0))
@@ -189,7 +174,7 @@ def machine_month(c, machine, start, end):
'contribution_cents'}. `machine` is its row from dtf_local.machines."""
mid = machine['id']
rows = _printed_orders(c, mid, start, end)
printed = sum((_film(row['snapshot'], row.get('items')) for row in rows), Decimal(0))
printed = sum((_film(row) for row in rows), Decimal(0))
sold = sum((_sold(row) for row in rows), 0)
ids = [row['id'] for row in rows]
spans = c.execute('''WITH events AS (

View File

@@ -7,7 +7,7 @@ plus a margin; CLAIM_TIMEOUT for a claim made before deadlines existed) is
assumed to belong to a worker that died and is taken again.
The result is a 300 DPI PNG (item 13, app/printpng.py), or its parts for a
film over 15 m: ordinary upload rows owned by an identity derived from the
film longer than a part (10 m): ordinary upload rows owned by an identity derived from the
order, already marked clean, since their only inputs are artwork that passed
the malware scan and the bytes are written here. dtf_local.print_parts lists
them in order. The operator still decides whether they become the final

View File

@@ -19,8 +19,9 @@ holds a whole sheet: the film is composed and written in bands of rows.
- Loose artwork is small: each file is decoded, turned and scaled to its place
once, and copied into every band it crosses.
A layout longer than 15 m leaves as parts of up to 15 m (Dropstar,
2026-10-30), DTF-7-item-1-p3.png, each with its footer saying which part it
A layout longer than a part leaves as parts of up to PART_CM, 10 m since
Marcus's 18/11 answer (Flexi opens up to 4 GB per image; Dropstar,
2026-10-30, was 15 m), DTF-7-item-1-p3.png, each with its footer saying which part it
is. Loose artwork is cut where no piece crosses; a finished sheet between
copies, or else in a clear band of its own pixels, and through the artwork
only when it has none (#136).
@@ -41,8 +42,9 @@ from .printtiles import Pyramid
DPI = 300
PX_PER_CM = DPI / 2.54
# Parts of up to 15 m, 6732 x 177165 px (Dropstar, 2026-10-30).
PART_CM = Decimal(os.environ.get('PRINT_PART_CM', '1500'))
# Parts of up to 10 m (Marcus, 2026-11-18): a 15 m part, 6732 x 177165 px, is
# 4,8 GB decoded and FlexiPRINT refuses it. PRINT_PART_CM overrides it.
PART_CM = Decimal(os.environ.get('PRINT_PART_CM', '1000'))
# A cut through artwork only when no gap between pieces is this close to the limit.
CUT_SEARCH_CM = Decimal('200')
BAND_ROWS = 512

View File

@@ -1,8 +1,9 @@
"""The print proof (Dropstar, 2026-10-21).
An order above 10 m prints a proof before the rest, checked by the print room
without stopping the order. Dropstar's current rule: up to 15 cm, from
the part with the thinnest lines, a piece of each different artwork, at most
without stopping the order. Dropstar's current rule: 15 cm from the part
with the thinnest lines plus samples of the file's main colours, up to 30 cm
in all (Marcus, 2026-11-26), a piece of each different artwork, at most
three proofs per order, never billed. On an order above 10 m the customer
may also ask for a proof at checkout (below 10 m there is none, Dropstar
2026-10-28): that order waits for them, marked "Aguardando contato", until
@@ -37,12 +38,14 @@ def needs_proof(snapshot):
#
# An order with a proof becomes a parent and a child. The child, the card
# "Prova", is an order of its own (orders.parent_id) with a pre-built proof
# sheet of up to 15 cm per contraction class, and follows the normal flow up
# sheet of up to 30 cm per contraction class, and follows the normal flow up
# to Revisão. The parent waits outside the queue, "Aguardando prova". On the
# child, the Vendedor (Gestão and the Administrador too) marks Prova OK, and
# the parent enters the queue; or Prova reprovada, with its reason, and the
# parent goes back to Arte recebida and the child closes. The child is no
# sale: it is not in Tiny, Números, the customer's account or their e-mails.
# The finest stroke's window; with the colour samples the sheet reaches
# app/printpng.py PROOF_MAX_CM.
PROOF_SHEET_CM = Decimal('15')
# Three proofs at most per order, one per item (Dropstar, 2026-10-23).
MAX_PROOFS = 3

View File

@@ -48,9 +48,10 @@ class RenderLimitTests(unittest.TestCase):
return {'production': {'height_cm': height, 'placements': [
{'y_cm': 0, 'length_cm': height, 'source_index': 0}]}}
self.assertEqual(render_seconds(film(800)), RENDER_SECONDS)
# A film in parts gets one part more: a cut moved to a clear band (#136).
self.assertEqual(render_seconds(film(2359.2)), 3 * RENDER_SECONDS)
self.assertEqual(render_seconds(film(4600)), 5 * RENDER_SECONDS)
# Parts of 10 m (Marcus, 2026-11-18), and a film in parts gets one
# part more: a cut moved to a clear band (#136).
self.assertEqual(render_seconds(film(2359.2)), 4 * RENDER_SECONDS)
self.assertEqual(render_seconds(film(4600)), 6 * RENDER_SECONDS)
self.assertEqual(render_seconds({'mode': 'file'}), RENDER_SECONDS)

View File

@@ -7,7 +7,7 @@ import unittest
from decimal import Decimal
from app.hotfolder import reprint_default
from app.machine_stats import _film
from app.machine_log import film_metres
class ReprintTests(unittest.TestCase):
@@ -27,8 +27,24 @@ class ReprintTests(unittest.TestCase):
def test_the_machine_counts_only_the_items_printed_again(self):
snapshot = {'items': [{'billed_metres': '2.0'}, {'billed_metres': '3.5'}]}
self.assertEqual(_film(snapshot), Decimal('5.5'))
self.assertEqual(_film(snapshot, [1]), Decimal('3.5'))
self.assertEqual(film_metres(snapshot), Decimal('5.5'))
self.assertEqual(film_metres(snapshot, [1]), Decimal('3.5'))
class ProofFilmTests(unittest.TestCase):
# A proof sheet is centimetres of film, counted in metres: it once counted
# 15 m per proof, enough for the machine's 10 m cleaning alert.
proof = {'proof_of': 81, 'items': [{'billed_metres': '0'}, {'billed_metres': '0'}]}
def test_a_proof_with_colour_samples_counts_its_real_length(self):
# Marcus, 2026-11-26: the finest stroke's 15 cm and two 5 cm samples,
# 1 cm of clear film between them: 27 cm.
windows = {'0': [['10', '25'], ['40', '45'], ['80', '85']]}
self.assertEqual(film_metres(self.proof, [0], windows), Decimal('0.27'))
def test_a_proof_made_before_the_samples_counts_15_cm(self):
self.assertEqual(film_metres(self.proof), Decimal('0.30'))
self.assertEqual(film_metres(self.proof, None, {'1': [['0', '15']]}), Decimal('0.30'))
if __name__ == '__main__':

View File

@@ -30,7 +30,7 @@ const contactWho=order=>(order.contact_by||'')+' em '+when(order.contact_since);
// The print proof (app/proof.py): asked for at checkout, or an order above 10 m.
// The room marks "Prova OK" once it is checked; without it, no Finalizado.
const PROOF_ABOVE_METRES=10;
const PROOF_RULE='Até 15 cm por classe, do trecho de traço mais fino; no máximo 3 provas por pedido, sem cobrança.';
const PROOF_RULE='Até 30 cm por classe: o trecho de traço mais fino e amostras das cores principais; no máximo 3 provas por pedido, sem cobrança.';
const needsProof=order=>!!order.snapshot.proof||order.snapshot.items.reduce((t,i)=>t+Number(i.billed_metres),0)>PROOF_ABOVE_METRES;
const proofPending=order=>needsProof(order)&&!order.proof_ok_at&&order.state!=='fin'&&!order.cancelled_at&&!order.proof_parent;
// The proof card (app/proof.py): the order's own card waits outside the queue

View File

@@ -626,7 +626,7 @@ async function syncFolder(force=false){
if(stages)await makeStageFolders();
const held=stages?[...new Set([...FOLDER.saved.values()].filter(r=>!r.review).map(r=>r.order).filter(Boolean))].slice(-1000):[];
const {files,states,receipts=[],reviews=[]}=await api('/queue/folder',{early:stages,held,since:stages?FOLDER.since||await folderSince():null});
// By file: an item over 15 m is several parts (item 13), each its own file.
// By file: an item longer than a part (10 m) is several parts (item 13), each its own file.
const wanted=new Map(files.map(f=>[f.upload_id,f]));
const where=stages?'“'+FOLDER.handle.name+'”':'a pasta de downloads';
let removed=0, moved=0, saved=0;