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 6m20s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Successful in 1m11s
The machine's name in Imprimindo (and "Ficha" in Usuários › Máquinas) opens its sheet: metres since the last cleaning and since the last film change, each supply's estimate, pending alerts and the entries. The room enters supplies (film, ink by colour, powder; a supply without cost takes the last one), parts (cap, damper, head, wiper, other) and events (cleaning, head alignment, a stop with reason and minutes). Gestão types the price, installation date and supply minimums. Alerts appear when someone pulls the next card onto the machine, never mid-print: 10 m since the last cleaning, 20 m after a film change without aligning the head, and a supply at its minimum. Marked done it records the event; postponed once it lets one more card through. The server refuses the pull otherwise. Counters start when the sheet went live (machines.log_since), not from everything printed before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
2.3 KiB
Python
51 lines
2.3 KiB
Python
"""The machine sheet's pure calculations (Fase 2, front 1a), without a database."""
|
|
import unittest
|
|
from decimal import Decimal
|
|
|
|
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, estimate,
|
|
one_decimal, supply_low)
|
|
|
|
|
|
class EstimateTest(unittest.TestCase):
|
|
def test_two_entries_give_an_estimate(self):
|
|
value = estimate([Decimal('1'), Decimal('2')], [Decimal('10')], Decimal('5'), Decimal('0.5'))
|
|
self.assertEqual(value['per_metre'], Decimal('0.2'))
|
|
self.assertEqual(value['stock'], Decimal('1.0'))
|
|
self.assertEqual(value['metres_left'], Decimal('5'))
|
|
self.assertEqual(value['minimum'], Decimal('0.5'))
|
|
self.assertFalse(supply_low(value))
|
|
|
|
def test_one_entry_has_no_estimate(self):
|
|
self.assertIsNone(estimate([Decimal('1')], [], Decimal('10'), None))
|
|
|
|
def test_an_interval_without_film_has_no_estimate(self):
|
|
self.assertIsNone(estimate([Decimal('1'), Decimal('1')], [Decimal('0')], Decimal('0'), None))
|
|
|
|
def test_the_minimum_reached_is_an_alert(self):
|
|
# 0.1 per metre, one litre refilled on average, nine metres later:
|
|
# 0.1 L left, below the machine's 1.5 L minimum.
|
|
value = estimate([Decimal('1'), Decimal('1')], [Decimal('10')], Decimal('9'), Decimal('1.5'))
|
|
self.assertEqual(value['stock'], Decimal('0.1'))
|
|
self.assertTrue(supply_low(value))
|
|
|
|
def test_only_the_last_intervals_are_averaged(self):
|
|
# Four intervals; SUPPLY_INTERVALS is three, so the 100 m one is ignored.
|
|
value = estimate([Decimal('1'), Decimal('1'), Decimal('3'), Decimal('3'), Decimal('3')],
|
|
[Decimal('100'), Decimal('10'), Decimal('10'), Decimal('10')], Decimal('0'), None)
|
|
self.assertEqual(value['per_metre'], Decimal('0.3'))
|
|
|
|
def test_the_thresholds_are_the_documented_ones(self):
|
|
self.assertEqual(CLEAN_EVERY_METRES, Decimal('10'))
|
|
self.assertEqual(ALIGN_AFTER_FILM_METRES, Decimal('20'))
|
|
|
|
|
|
class AlertTextTest(unittest.TestCase):
|
|
def test_one_decimal_uses_a_comma(self):
|
|
self.assertEqual(one_decimal(Decimal('10.44')), '10,4')
|
|
self.assertEqual(one_decimal(Decimal('3')), '3,0')
|
|
self.assertEqual(one_decimal(Decimal('19.86')), '19,9')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|