fix: the proof crops the finest stroke and closes the contact wait (0.1)
The browser records where the thinnest stroke sits in the assembled film; the proof takes a 15 cm window around it instead of always the top. A free proof no longer fails the layout's billed-metres check, and answering the proof card clears "Aguardando contato" and ends its timer.
This commit is contained in:
@@ -141,9 +141,10 @@ def run():
|
||||
client.call('/operator/orders/' + oid + '/move', {'state': 'tra', 'version': version}, operator=True)
|
||||
version += 1
|
||||
# Printing, the folders still get the file of an order they hold (to take
|
||||
# it to Finalizado later), and no one else's.
|
||||
machine = client.call('/operator/machines', {'name': 'Print test '+uuid4().hex[:6],
|
||||
'products': ['textil']}, operator=True)['id']
|
||||
# it to Finalizado later), and no one else's. The pull chooses the machine.
|
||||
tag = uuid4().hex[:6]
|
||||
machine = client.call('/operator/machines', {'name': f'Hot {tag}', 'products': ['textil']},
|
||||
operator=True)['id']
|
||||
client.call('/operator/orders/' + oid + '/move', {'state': 'imp', 'version': version,
|
||||
'machine_id': machine}, operator=True)
|
||||
version += 1
|
||||
@@ -170,10 +171,7 @@ def run():
|
||||
# Item 10: printing, the file goes once into its machine's hot folder for
|
||||
# its class; Flexi taking it is reported; leaving Imprimindo withdraws
|
||||
# what Flexi did not take.
|
||||
tag = uuid4().hex[:6]
|
||||
machine = client.call('/operator/machines', {'name': f'Hot {tag}', 'products': ['textil']}, operator=True)['id']
|
||||
try:
|
||||
client.call('/operator/orders/' + oid + '/machine', {'machine_id': machine}, operator=True)
|
||||
# No class measured or chosen: the part waits for one.
|
||||
assert not [p for p in client.call('/operator/queue/hot', {}, operator=True)['write'] if p['order'] == oid]
|
||||
client.call('/operator/orders/' + oid + '/contraction', {'item_index': 0, 'value': 'C2'}, operator=True)
|
||||
@@ -215,6 +213,7 @@ def run():
|
||||
unread = upload_bytes(client, b'LOCAL PRINT TEST - NOT AN IMAGE', name='LOCAL-PROOF-TEST.cdr')
|
||||
long = loose_item(unread, copies=1)
|
||||
long['metres'] = '10.5'
|
||||
long['proof_y_fraction'] = '0.8'
|
||||
long['production'] = {**long['production'], 'height_cm': 1050,
|
||||
'placements': [{**long['production']['placements'][0], 'y_cm': 1040}]}
|
||||
parent = paid_order(client, long)
|
||||
@@ -223,6 +222,13 @@ def run():
|
||||
card = next(o for o in board if o['id'] == mine['proof_card']['id'])
|
||||
assert card['proof_parent']['number'] == parent['number'] and card['state'] == 'rec', card
|
||||
assert card['snapshot']['proof_of'] == parent['number'] and card['payment'] == {'provider': 'prova'}
|
||||
assert float(card['snapshot']['items'][0]['proof_y_fraction']) == 0.8, card['snapshot']['items'][0]
|
||||
# The proof answer is the customer contact: the old "Aguardando contato"
|
||||
# mark must not survive it (item 0.1).
|
||||
with db.connect() as c:
|
||||
c.execute("""UPDATE dtf_local.orders SET contact_since=now(), contact_by='Site',
|
||||
contact_note='Prova pedida no site' WHERE id=%s""", (parent['id'],))
|
||||
c.execute('INSERT INTO dtf_local.contact_waits(order_id,started_at) VALUES(%s,now())', (parent['id'],))
|
||||
with db.connect() as c:
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.outbox WHERE event_key LIKE %s', (card['id'] + '%',)).fetchone()
|
||||
c.execute("UPDATE dtf_local.orders SET state='rev' WHERE id=%s", (card['id'],))
|
||||
@@ -249,6 +255,10 @@ def run():
|
||||
mine = next(o for o in board if o['id'] == parent['id'])
|
||||
assert mine['state'] == 'rec' and mine['proof_card']['proof_result'] == 'rejected', mine['proof_card']
|
||||
assert mine['proof_card']['proof_reason'] == 'Cor do fundo errada'
|
||||
assert not mine.get('contact_since'), mine
|
||||
with db.connect() as c:
|
||||
assert c.execute('SELECT ended_at FROM dtf_local.contact_waits WHERE order_id=%s',
|
||||
(parent['id'],)).fetchone()['ended_at']
|
||||
assert not [o for o in board if o['id'] == card['id']], 'an answered proof card leaves the board'
|
||||
# Rejection releases the parent for corrected artwork, until a new proof card is opened.
|
||||
final = upload_bytes(client, artwork(), name='LOCAL-PROOF-FINAL.png', order_id=parent['id'])
|
||||
|
||||
26
tests/test_proof_cut.py
Normal file
26
tests/test_proof_cut.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""The proof window: 15 cm around the finest stroke, never outside the film."""
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
from app.printpng import proof_cut
|
||||
|
||||
|
||||
class ProofCutTests(unittest.TestCase):
|
||||
def test_centres_the_window_on_the_finest_stroke(self):
|
||||
self.assertEqual(proof_cut(100, 15, 0.5), [Decimal('42.5'), Decimal('57.5')])
|
||||
self.assertEqual(proof_cut(100, 15, 0.8), [Decimal('72.5'), Decimal('87.5')])
|
||||
|
||||
def test_clamps_at_both_ends(self):
|
||||
self.assertEqual(proof_cut(100, 15, 0), [Decimal(0), Decimal(15)])
|
||||
self.assertEqual(proof_cut(100, 15, 1), [Decimal(85), Decimal(100)])
|
||||
|
||||
def test_a_short_film_is_the_whole_proof(self):
|
||||
self.assertEqual(proof_cut(10, 15, 0.5), [Decimal(0), Decimal(10)])
|
||||
self.assertEqual(proof_cut(10, 15, None), [Decimal(0), Decimal(10)])
|
||||
|
||||
def test_without_a_measure_the_old_top_window_remains(self):
|
||||
self.assertEqual(proof_cut(100, 15, None), [Decimal(0), Decimal(15)])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
66
tests/test_proof_render.py
Normal file
66
tests/test_proof_render.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""A free proof is a 15 cm window around the measured fine stroke, not the top."""
|
||||
import io
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from app.printpng import render
|
||||
|
||||
PX_CM = 300 / 2.54
|
||||
|
||||
|
||||
def item(height_cm=30, fraction='0.75'):
|
||||
return {
|
||||
'mode': 'file', 'metres': '10.5', 'billed_metres': '0',
|
||||
'production': {
|
||||
'version': 3, 'film_width_cm': 20, 'height_cm': height_cm,
|
||||
'sources': [{'upload_id': '00000000-0000-0000-0000-000000000001',
|
||||
'kind': 'sheet', 'width_cm': 20, 'length_cm': height_cm,
|
||||
'copies': 1, 'rotation_degrees': 0, 'mirrored': False,
|
||||
'measurement': 'file'}],
|
||||
'placements': [{'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0,
|
||||
'width_cm': 20, 'length_cm': height_cm,
|
||||
'rotation_degrees': 0, 'mirrored': False}],
|
||||
},
|
||||
'proof_parent_item_index': 0, 'proof_y_fraction': fraction,
|
||||
}
|
||||
|
||||
|
||||
class ProofRenderTests(unittest.TestCase):
|
||||
def _sheet(self, folder):
|
||||
height = round(30 * PX_CM)
|
||||
width = round(20 * PX_CM)
|
||||
image = Image.new('RGBA', (width, height), (220, 30, 60, 255))
|
||||
ImageDraw.Draw(image).rectangle((0, height // 2, width - 1, height - 1),
|
||||
fill=(30, 60, 220, 255))
|
||||
path = Path(folder) / 'sheet.png'
|
||||
image.save(path, 'PNG', dpi=(300, 300))
|
||||
return str(path)
|
||||
|
||||
def test_the_window_follows_the_finest_stroke(self):
|
||||
with tempfile.TemporaryDirectory() as source, tempfile.TemporaryDirectory() as out:
|
||||
sheet = self._sheet(source)
|
||||
parts, detail = render(item(), {0: (sheet, 'sheet.png')}, out, 'proof',
|
||||
limit_cm=15, proof_fraction='0.75')
|
||||
self.assertEqual(len(parts), 1)
|
||||
self.assertEqual(detail['parts'][0]['from_cm'], '15')
|
||||
with Image.open(parts[0][0]) as proof:
|
||||
self.assertEqual(proof.width, round(20 * PX_CM))
|
||||
self.assertLessEqual(abs(proof.height - round(15 * PX_CM)), 1)
|
||||
# The bottom half is blue: the window covered 15 to 30 cm.
|
||||
self.assertEqual(proof.getpixel((proof.width // 2, round(5 * PX_CM))), (30, 60, 220, 255))
|
||||
|
||||
def test_the_top_is_still_the_default_without_a_measure(self):
|
||||
with tempfile.TemporaryDirectory() as source, tempfile.TemporaryDirectory() as out:
|
||||
sheet = self._sheet(source)
|
||||
parts, detail = render(item(fraction=None), {0: (sheet, 'sheet.png')}, out, 'proof',
|
||||
limit_cm=15)
|
||||
self.assertEqual(detail['parts'][0]['from_cm'], '0')
|
||||
with Image.open(parts[0][0]) as proof:
|
||||
self.assertEqual(proof.getpixel((proof.width // 2, round(5 * PX_CM))), (220, 30, 60, 255))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user