From 0fc01315c7d97dcfa0f0d71994220cefc757c05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 6 Nov 2026 10:41:14 -0300 Subject: [PATCH] feat: the site's third-round corrections on acceptance, DPI and the final file Residue and thin strokes can be accepted on ready sheets and loose art, with the consent and its time kept on the order. The resolution rule is 96/200 DPI, and a final file must be a transparent 300 DPI PNG. The art score leaves the customer's cart and buy box (Dropstar, 2026-11-05). --- app/api/quotes.py | 15 +++++++++++++-- app/grade_check.py | 31 +++++++++++++++++++++++++++++-- app/quote_review.py | 4 ++++ tests/test_grade_check.py | 32 +++++++++++++++++++++++++------- web/index.html | 8 +++----- web/site-cart.js | 2 +- web/site-compra.js | 3 --- web/site-config.js | 2 +- web/site-packing.js | 1 - web/site-pdf.js | 24 +++++++++++++----------- web/site-quality.js | 19 +++++++++---------- web/site-sheet.js | 29 +++++++++++++++++++++-------- web/site-upload.js | 19 ++++++++++++++++--- 13 files changed, 135 insertions(+), 54 deletions(-) diff --git a/app/api/quotes.py b/app/api/quotes.py index 0111fab..e3c5472 100644 --- a/app/api/quotes.py +++ b/app/api/quotes.py @@ -1,6 +1,7 @@ """Quotes: the customer's cart, approved at once when it can be (app/quote_review.py).""" import hashlib import json +from datetime import datetime, timezone from decimal import Decimal from uuid import UUID, uuid4 @@ -13,7 +14,7 @@ from ..core.auth import owner from ..core.models import QuoteRequest from ..core.pricing import price from .. import quote_review -from ..grade_check import Files, mismatch +from ..grade_check import Files, mismatch, resolution_issue from ..runtime import freight, payment, quote_view, require_delivery_available, storage, upload_row from ..scanning import require_clean @@ -27,6 +28,12 @@ def create_quote(body: QuoteRequest, session_id=Depends(owner)): require_delivery_available(body.freight.service) draft = body.model_dump(mode='json', exclude={'request_key'}) digest = hashlib.sha256(json.dumps(draft, sort_keys=True).encode()).hexdigest() + accepted_at = datetime.now(timezone.utc).isoformat() + for item in draft['items']: + if item.get('residue_accepted'): + item['residue_accepted_at'] = accepted_at + if item.get('stroke_choice'): + item['stroke_choice_at'] = accepted_at reason = quote_review.review_reason(draft) if reason is not None: # Waits for review: check the delivery now, priced at approval. @@ -51,7 +58,11 @@ def create_quote(body: QuoteRequest, session_id=Depends(owner)): # The grade came from the browser and is shown with the order (it no # longer sets the price): before a cart is approved at checkout, the # server works it out from the files. - note = mismatch(Files(storage), draft['items'], rows) if reason is None else None + files = Files(storage) + issue = resolution_issue(files, draft['items'], rows) + if issue: + raise HTTPException(422, issue) + note = mismatch(files, draft['items'], rows) if reason is None else None reason = reason or note uid = uuid4() c.execute('INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,review_note) VALUES(%s,%s,%s,%s,%s,%s) ON CONFLICT(owner,request_key) DO NOTHING', diff --git a/app/grade_check.py b/app/grade_check.py index ab8ba43..b0cd2dc 100644 --- a/app/grade_check.py +++ b/app/grade_check.py @@ -23,7 +23,9 @@ import os import struct import tempfile -DPI_IDEAL = 300 +DPI_IDEAL = 200 +DPI_REFUSE = 96 +PDF_VECTOR_DPI = 300 # The Site analyses PDFs up to 150 MB (GRANDE_BYTES); above that it does not # grade them, so neither does this. PDF_MAX_BYTES = 150 * 1048576 @@ -123,7 +125,7 @@ def pdf_dpi(path): return None found = [(dpi, area) for dpi, area in found if dpi > 0] if not found: - return DPI_IDEAL + return PDF_VECTOR_DPI total = sum(area for _, area in found) or 1 return js_round(sum(dpi * area for dpi, area in found) / total) @@ -178,6 +180,31 @@ def item_grade(files, item, rows): return js_round(sum(grade_of(d) for d in dpis) / len(dpis)) +def resolution_issue(files, items, rows): + """Refuse sub-96 DPI and require recorded consent for measurable 96–199 DPI. + + Unknown formats remain for manual review; they cannot be treated as a + measured zero DPI or silently called high-resolution artwork. + """ + for index, item in enumerate(items, 1): + dpis = [] + for source in item['production']['sources']: + row = rows.get(str(source['upload_id'])) + dpi = source_dpi(files, row, source) if row else None + if dpi is None: + dpis = [] + break + dpis.append(dpi) + if not dpis: + continue + lowest = min(dpis) + if lowest < DPI_REFUSE: + return f'Item {index}: resolução de {js_round(lowest)} DPI abaixo do mínimo de {DPI_REFUSE} DPI.' + if lowest < DPI_IDEAL and (item['quality_status'] != 'warning' or not item['quality_acknowledged']): + return f'Item {index}: confirme a ressalva de resolução entre {DPI_REFUSE} e {DPI_IDEAL - 1} DPI.' + return None + + def mismatch(files, items, rows): """Why a cart's grades cannot be approved at checkout, or None.""" for item in items: diff --git a/app/quote_review.py b/app/quote_review.py index 47bd86b..7bc52dd 100644 --- a/app/quote_review.py +++ b/app/quote_review.py @@ -78,9 +78,13 @@ def approve(c, row, items, reviewer): 'quality_status': original['quality_status'], 'quality_acknowledged': original['quality_acknowledged'], 'residue_accepted': original.get('residue_accepted', 0), + **({'residue_accepted_at': original['residue_accepted_at']} + if original.get('residue_accepted_at') else {}), **({'stroke_px': original['stroke_px'], 'stroke_class': original['stroke_class']} if original.get('stroke_class') else {}), **({'stroke_choice': original['stroke_choice']} if original.get('stroke_choice') else {}), + **({'stroke_choice_at': original['stroke_choice_at']} + if original.get('stroke_choice_at') else {}), **({'split': original['split']} if original.get('split') else {})}) bill_splits(priced) metres = sum(Decimal(i['billed_metres']) for i in priced) diff --git a/tests/test_grade_check.py b/tests/test_grade_check.py index 2a61a20..e616dc3 100644 --- a/tests/test_grade_check.py +++ b/tests/test_grade_check.py @@ -62,25 +62,43 @@ class GradeCheckTests(unittest.TestCase): self.assertEqual(grade_check.pdf_dpi(handle.name), 300) def test_grades_follow_the_site(self): - # 57 cm is 22.44 in: 6059 px is 270 DPI, grade 90; 3366 px is 150 DPI, grade 50. + # 57 cm is 22.44 in: the new clean threshold is 200 DPI. files = FakeFiles({'a.png': encoded('PNG', (6059, 100)), 'b.jpg': encoded('JPEG', (3366, 100)), 'tall.png': encoded('PNG', (100, 2362)), 'x.cdr': b'CDR'}) rows = {n: {'name': n, 'size': 1} for n in files.blobs} # A sheet takes the worst sheet's grade. - self.assertEqual(grade_check.item_grade(files, item('sheet', 0, [('a.png', 57, 0)]), rows), 90) - self.assertEqual(grade_check.item_grade(files, item('sheet', 0, [('a.png', 57, 0), ('b.jpg', 57, 0)]), rows), 50) + self.assertEqual(grade_check.item_grade(files, item('sheet', 0, [('a.png', 57, 0)]), rows), 100) + self.assertEqual(grade_check.item_grade(files, item('sheet', 0, [('a.png', 57, 0), ('b.jpg', 57, 0)]), rows), 75) # Artworks average; a rotated one is measured along its height. - self.assertEqual(grade_check.item_grade(files, item('artwork', 0, [('a.png', 57, 0), ('b.jpg', 57, 0)]), rows), 70) + self.assertEqual(grade_check.item_grade(files, item('artwork', 0, [('a.png', 57, 0), ('b.jpg', 57, 0)]), rows), 88) self.assertEqual(grade_check.item_grade(files, item('artwork', 0, [('tall.png', 20, 90)]), rows), 100) self.assertIsNone(grade_check.item_grade(files, item('sheet', 0, [('x.cdr', 57, 0)]), rows)) # What the cart claims is checked, with a point or two of rounding. claim = lambda g, src: grade_check.mismatch(files, [item('sheet', g, src)], rows) - self.assertIsNone(claim(90, [('a.png', 57, 0)])) - self.assertIsNone(claim(92, [('a.png', 57, 0)])) - self.assertEqual(claim(100, [('a.png', 57, 0)]), 'Nota 100 maior que a do arquivo (90)') + self.assertIsNone(claim(100, [('a.png', 57, 0)])) + self.assertIsNone(claim(77, [('b.jpg', 57, 0)])) + self.assertEqual(claim(100, [('b.jpg', 57, 0)]), 'Nota 100 maior que a do arquivo (75)') self.assertEqual(claim(40, [('x.cdr', 57, 0)]), 'Nota não conferida no servidor') self.assertIsNone(claim(0, [('x.cdr', 57, 0)])) + def test_resolution_boundaries_and_consent(self): + width = lambda dpi: int(dpi * 57 / 2.54) + 1 + files = FakeFiles({f'{dpi}.png': encoded('PNG', (width(dpi), 20)) + for dpi in (95, 96, 199, 200, 287, 293)}) + rows = {name: {'name': name, 'size': 1} for name in files.blobs} + def issue(dpi, status='ok', acknowledged=False): + spec = item('sheet', 0, [(f'{dpi}.png', 57, 0)]) + spec.update(quality_status=status, quality_acknowledged=acknowledged) + return grade_check.resolution_issue(files, [spec], rows) + self.assertIn('abaixo do mínimo', issue(95)) + self.assertIn('confirme a ressalva', issue(96)) + self.assertIn('confirme a ressalva', issue(199)) + self.assertIsNone(issue(96, 'warning', True)) + self.assertIsNone(issue(199, 'warning', True)) + for dpi in (200, 287, 293): + self.assertIsNone(issue(dpi), dpi) + self.assertEqual(grade_check.grade_of(dpi), 100) + if __name__ == '__main__': unittest.main() diff --git a/web/index.html b/web/index.html index 7914a77..ecd3b43 100644 --- a/web/index.html +++ b/web/index.html @@ -906,7 +906,7 @@ h2 em{font-style:normal;color:var(--laranja)} não deixa pagar
  • Pontinho de recorte. A impressora enxerga qualquer resíduo e imprime. Não existe pequeno demais: o site mostra onde cada um está - e só deixa pagar depois que você apagar
  • + e pede que você apague ou aceite imprimir assim
  • Cópias sobrepostas. Duas iguais com 1 mm de diferença saem duplicadas
  • Menos de 96 DPI. Abaixo disso não imprimimos: sai @@ -929,7 +929,6 @@ h2 em{font-style:normal;color:var(--laranja)}