fix: Números shows no pace for under a quarter of an hour in Imprimindo
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>
This commit is contained in:
Cauê Faleiros
2026-11-16 14:10:29 -03:00
parent 4f584fed8a
commit 66bc2b9b03
3 changed files with 28 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ from decimal import Decimal
from fastapi import APIRouter, Depends, HTTPException, Query from fastapi import APIRouter, Depends, HTTPException, Query
from ... import machines, payments, unpaid from ... import machines, payments, unpaid
from ...machine_stats import pace
from ...cart_pricing import designer_hours from ...cart_pricing import designer_hours
from ...core import db from ...core import db
from ...core.auth import operator from ...core.auth import operator
@@ -336,7 +337,7 @@ def machine_output(c, start, end):
made = float(sum(row['metres'] for row in mine)) made = float(sum(row['metres'] for row in mine))
result.append({'id': m['id'], 'name': m['name'], 'active': m['active'], 'orders': len(mine), result.append({'id': m['id'], 'name': m['name'], 'active': m['active'], 'orders': len(mine),
'metres': made, 'printing_hours': round(hours_in, 2), 'metres': made, 'printing_hours': round(hours_in, 2),
'metres_per_hour': round(made / hours_in, 1) if hours_in > 0 else None, 'metres_per_hour': pace(made, hours_in),
'last_finished': last[m['id']].isoformat() if m['id'] in last else None, 'last_finished': last[m['id']].isoformat() if m['id'] in last else None,
'now': {state: m['states'].get(state, 0) for state in ('tra', 'imp')}}) 'now': {state: m['states'].get(state, 0) for state in ('tra', 'imp')}})
loose = [row for row in done if row['machine_id'] is None] loose = [row for row in done if row['machine_id'] is None]

View File

@@ -41,6 +41,17 @@ INK_ITEMS = tuple(item for item in SUPPLIES if item.startswith('ink_'))
# Average month, for the monthly contribution since installation. # Average month, for the monthly contribution since installation.
_MONTH_SECONDS = Decimal('30.4375') * 86400 _MONTH_SECONDS = Decimal('30.4375') * 86400
# Below a quarter of an hour in Imprimindo the pace is noise: an order moved
# through in seconds made a machine show 110671,5 m/h (16/11). No pace then.
MIN_PACE_HOURS = 0.25
def pace(metres, hours):
"""Metres per hour, one decimal; None below MIN_PACE_HOURS of printing."""
if not hours or float(hours) < MIN_PACE_HOURS:
return None
return round(float(metres) / float(hours), 1)
def month_bounds(month): def month_bounds(month):
"""'2026-11' (None: the current month, local) -> (first day, first day of """'2026-11' (None: the current month, local) -> (first day, first day of
@@ -79,8 +90,7 @@ def ratios(printed, hours_running=None, supplies_cents=0, parts_cents=0, rolls=N
return int((Decimal(cents) / printed).quantize(Decimal('1'), rounding=ROUND_HALF_UP)) return int((Decimal(cents) / printed).quantize(Decimal('1'), rounding=ROUND_HALF_UP))
result = { result = {
'metres_per_hour': (round(float(printed) / float(hours_running), 1) 'metres_per_hour': pace(printed, hours_running),
if hours_running else None),
'metres_per_roll': round(float(printed / Decimal(str(rolls))), 1) if rolls else None, 'metres_per_roll': round(float(printed / Decimal(str(rolls))), 1) if rolls else None,
'ink_per_100m': { 'ink_per_100m': {
item: (None if quantity is None or not printed item: (None if quantity is None or not printed

View File

@@ -3,7 +3,7 @@ import unittest
from datetime import datetime, timedelta from datetime import datetime, timedelta
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
from app.machine_stats import month_bounds, ratios from app.machine_stats import month_bounds, pace, ratios
SAO_PAULO = ZoneInfo('America/Sao_Paulo') SAO_PAULO = ZoneInfo('America/Sao_Paulo')
@@ -74,5 +74,18 @@ class RatiosTest(unittest.TestCase):
self.assertIsNone(value['payback_months']) 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__': if __name__ == '__main__':
unittest.main() unittest.main()