feat: Números measures the site and the Prumo (0.12)

The browser records page load, upload speed and bytes, Prumo's check and
the loose-art montage; the quote keeps them and Números shows average and
p95 per period. Print generation and the payment-to-card time come from
the database. The upload bar already estimates its remaining time.
This commit is contained in:
Cauê Faleiros
2026-11-06 11:09:36 -03:00
parent 945c9e366a
commit 6351a094f4
11 changed files with 170 additions and 3 deletions

35
tests/test_speed.py Normal file
View File

@@ -0,0 +1,35 @@
"""Números' speed block: average and p95, in the units the PDF asks for."""
import unittest
from app.api.operator import speed_figures
class SpeedFiguresTests(unittest.TestCase):
def test_formats_seconds_and_upload_speed(self):
site = {'page_avg': 1500, 'page_p95': 3000, 'page_n': 4,
'upload_avg': 2.5, 'upload_p95': 1.5, 'upload_n': 4,
'analysis_avg': 12000, 'analysis_p95': 20000, 'analysis_n': 3,
'montage_avg': 8000, 'montage_p95': 9000, 'montage_n': 2}
generation = {'per10_avg': 90, 'per10_p95': 120, 'per10_n': 5}
card = {'avg_s': 0.4, 'p95_s': 0.9, 'n': 2}
rows = {row['key']: row for row in speed_figures(site, generation, card)}
self.assertEqual(rows['page']['average'], 1.5)
self.assertEqual(rows['page']['p95'], 3.0)
self.assertEqual(rows['upload']['unit'], 'MB/s')
self.assertEqual(rows['analysis']['average'], 12.0)
self.assertEqual(rows['montage']['p95'], 9.0)
self.assertEqual(rows['print']['average'], 90)
self.assertEqual(rows['card']['samples'], 2)
def test_missing_samples_stay_empty(self):
empty = {key: None for key in ('page_avg', 'page_p95', 'page_n', 'upload_avg', 'upload_p95',
'upload_n', 'analysis_avg', 'analysis_p95', 'analysis_n',
'montage_avg', 'montage_p95', 'montage_n')}
generation = {'per10_avg': None, 'per10_p95': None, 'per10_n': 0}
card = {'avg_s': None, 'p95_s': None, 'n': 0}
rows = speed_figures(empty, generation, card)
self.assertTrue(all(row['average'] is None and row['samples'] == 0 for row in rows))
if __name__ == '__main__':
unittest.main()