All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 6m29s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m5s
A machine whose only finished order passed through Imprimindo in seconds showed 110671,5 m per hour. The pace (per machine and month by month) now needs at least 15 minutes of printing time and shows a dash below that. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
92 lines
3.9 KiB
Python
92 lines
3.9 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, pace, 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'])
|
|
|
|
|
|
|
|
class PaceTest(unittest.TestCase):
|
|
def test_seconds_in_imprimindo_give_no_pace(self):
|
|
# 16/11: an order moved through Imprimindo in seconds showed 110671,5 m/h.
|
|
self.assertIsNone(pace(1.01, 10 / 3600))
|
|
self.assertIsNone(pace(5, 0))
|
|
self.assertIsNone(pace(5, None))
|
|
|
|
def test_a_quarter_of_an_hour_gives_the_pace(self):
|
|
self.assertEqual(pace(5, 0.25), 20.0)
|
|
self.assertEqual(pace(1.5, 0.5), 3.0)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|