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 5m58s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m4s
A new Números section, "Máquinas, mês a mês", one column per machine and a month at a time: metres printed, metres per hour and hours running (time shared by two orders counted once), hours stopped with their reasons; metres per film roll, ink per 100 m by colour, powder per 100 m; supplies, parts and total cost per metre; what the printed orders sold, the month's contribution and since installation; and the return in % and months to pay back once Gestão types the price. Refills stand for consumption. Every ratio without data shows "—". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
3.5 KiB
Python
79 lines
3.5 KiB
Python
"""The machine month's pure calculations (Fase 2, front 1b), without a database."""
|
|
import unittest
|
|
from datetime import datetime, timedelta
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from app.machine_stats import month_bounds, ratios
|
|
|
|
SAO_PAULO = ZoneInfo('America/Sao_Paulo')
|
|
|
|
|
|
class MonthBoundsTest(unittest.TestCase):
|
|
def test_a_valid_month(self):
|
|
start, end = month_bounds('2026-11')
|
|
self.assertEqual((start.year, start.month, start.day), (2026, 11, 1))
|
|
self.assertEqual((start.hour, start.minute, start.second), (0, 0, 0))
|
|
self.assertEqual(start.utcoffset(), timedelta(hours=-3))
|
|
self.assertEqual(start.tzinfo, SAO_PAULO)
|
|
self.assertEqual((end.year, end.month, end.day), (2026, 12, 1))
|
|
|
|
def test_the_year_turns_over(self):
|
|
start, end = month_bounds('2026-12')
|
|
self.assertEqual((start.year, start.month), (2026, 12))
|
|
self.assertEqual((end.year, end.month, end.day), (2027, 1, 1))
|
|
|
|
def test_a_malformed_month_is_invalid(self):
|
|
for month in ('2026-13', '2026-1', 'novembro', '2026-11-05', ''):
|
|
with self.subTest(month=month):
|
|
with self.assertRaises(ValueError):
|
|
month_bounds(month)
|
|
|
|
def test_none_is_the_current_month(self):
|
|
now = datetime.now(SAO_PAULO)
|
|
start, end = month_bounds(None)
|
|
self.assertEqual((start.year, start.month), (now.year, now.month))
|
|
|
|
|
|
class RatiosTest(unittest.TestCase):
|
|
def test_zero_or_unknown_divisors_are_none(self):
|
|
value = ratios(0, hours_running=0, supplies_cents=100, parts_cents=50,
|
|
rolls=0, inks={'ink_c': 1}, powder=0, price_cents=1000,
|
|
contribution_cents=200, months=10)
|
|
self.assertIsNone(value['metres_per_hour'])
|
|
self.assertIsNone(value['metres_per_roll'])
|
|
self.assertIsNone(value['ink_per_100m']['ink_c'])
|
|
self.assertIsNone(value['powder_g_per_100m'])
|
|
self.assertIsNone(value['supplies_per_metre_cents'])
|
|
self.assertIsNone(value['parts_per_metre_cents'])
|
|
self.assertIsNone(value['total_per_metre_cents'])
|
|
self.assertEqual(value['roi_pct'], 20.0)
|
|
|
|
def test_no_price_leaves_the_return_blank(self):
|
|
value = ratios(0, contribution_cents=500, installed_parts_cents=100, months=5)
|
|
self.assertIsNone(value['roi_pct'])
|
|
self.assertIsNone(value['payback_months'])
|
|
|
|
def test_the_known_ratios(self):
|
|
value = ratios(100, hours_running=10, supplies_cents=10000, parts_cents=5000,
|
|
rolls=2, inks={'ink_c': 1}, powder=1, price_cents=100000,
|
|
contribution_cents=30000, installed_parts_cents=20000, months=10)
|
|
self.assertEqual(value['metres_per_hour'], 10.0)
|
|
self.assertEqual(value['metres_per_roll'], 50.0)
|
|
self.assertEqual(value['ink_per_100m']['ink_c'], 1.0)
|
|
self.assertEqual(value['powder_g_per_100m'], 1000.0)
|
|
self.assertEqual(value['supplies_per_metre_cents'], 100)
|
|
self.assertEqual(value['parts_per_metre_cents'], 50)
|
|
self.assertEqual(value['total_per_metre_cents'], 150)
|
|
self.assertEqual(value['roi_pct'], 25.0)
|
|
self.assertEqual(value['payback_months'], 30.0)
|
|
|
|
def test_a_negative_average_has_no_payback(self):
|
|
value = ratios(100, price_cents=100000, contribution_cents=-1000,
|
|
installed_parts_cents=0, months=10)
|
|
self.assertEqual(value['roi_pct'], -1.0)
|
|
self.assertIsNone(value['payback_months'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|