Extend shift reporting and downtime analytics
This commit is contained in:
1 parent
41a5ae7a63
commit
6e8eb6f50f
74 files changed
+5397
-238
No files matched your search
@@ -16,6 +16,7 @@ from production_analytics.calculations.material_consumption import (
|
||||
area_application_rate_kg_per_hour,
|
||||
)
|
||||
from production_analytics.enlyze.gateway import EnlyzeApiGateway, EnlyzeProductionRun
|
||||
from production_analytics.erp import ErpReadError
|
||||
from production_analytics.service.material_context import ErpNominalWidthProvider
|
||||
from production_analytics.service.material_polling import MaterialPollingService
|
||||
from production_analytics.service.material_state_store import JsonMaterialStateStore
|
||||
@@ -69,7 +70,7 @@ def test_missing_or_invalid_spreader_fails(bad):
|
||||
)
|
||||
|
||||
|
||||
def width_provider():
|
||||
def width_provider(fallback_nominal_width_m=None):
|
||||
erp = Mock()
|
||||
erp.get_current_workplace_status.return_value = SimpleNamespace(
|
||||
workplace='Bento 1', production_order='12026000814', article_number='180305',
|
||||
@@ -77,9 +78,111 @@ def width_provider():
|
||||
)
|
||||
return ErpNominalWidthProvider(
|
||||
erp, workplace='Bento 1', format_template='Bento 1-{production_order}',
|
||||
fallback_nominal_width_m=fallback_nominal_width_m,
|
||||
)
|
||||
|
||||
|
||||
def test_erp_width_takes_priority_over_fallback(caplog):
|
||||
provider = width_provider(5.0)
|
||||
provider.gateway.get_current_workplace_status.return_value.article_description = '4,00 x 40 m'
|
||||
assert provider('Bento 1-12026000814') == 4.0
|
||||
assert not caplog.records
|
||||
|
||||
|
||||
@pytest.mark.parametrize('fallback', [None, 5.0])
|
||||
def test_combined_order_width_fallback(fallback, caplog):
|
||||
provider = width_provider(fallback)
|
||||
order = 'Bento 1-12026001005-Bento 1-12026001014'
|
||||
if fallback is None:
|
||||
with pytest.raises(ValueError, match='ERP context does not match the production order'):
|
||||
provider(order)
|
||||
assert not caplog.records
|
||||
else:
|
||||
assert provider(order) == 5.0
|
||||
assert len(caplog.records) == 1
|
||||
assert caplog.records[0].levelname == 'WARNING'
|
||||
assert 'ERP nominal-width resolution failed' in caplog.text
|
||||
assert order in caplog.text
|
||||
assert 'fallback nominal width 5.0 m' in caplog.text
|
||||
|
||||
|
||||
def test_fallback_warns_once_per_order_per_provider(caplog):
|
||||
provider = width_provider(5.0)
|
||||
first_order = 'Bento 1-12026001005-Bento 1-12026001014'
|
||||
second_order = 'Bento 1-12026001015'
|
||||
for order in (first_order, first_order, second_order, second_order, first_order):
|
||||
assert provider(order) == 5.0
|
||||
assert len(caplog.records) == 2
|
||||
assert all(record.levelname == 'WARNING' for record in caplog.records)
|
||||
assert first_order in caplog.records[0].getMessage()
|
||||
assert second_order in caplog.records[1].getMessage()
|
||||
|
||||
# A fresh provider has its own warning history.
|
||||
assert width_provider(5.0)(first_order) == 5.0
|
||||
assert len(caplog.records) == 3
|
||||
|
||||
|
||||
def test_erp_resolution_still_runs_after_fallback(caplog):
|
||||
provider = width_provider(5.0)
|
||||
order = 'Bento 1-12026000814'
|
||||
status = provider.gateway.get_current_workplace_status.return_value
|
||||
status.article_description = None
|
||||
assert provider(order) == 5.0
|
||||
status.article_description = '4,00 x 40 m'
|
||||
assert provider(order) == 4.0
|
||||
status.article_description = None
|
||||
assert provider(order) == 5.0
|
||||
assert len(caplog.records) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize('failure', ['missing_status', 'missing_width', 'read_error'])
|
||||
@pytest.mark.parametrize('fallback', [None, 5.0])
|
||||
def test_other_erp_width_failures(failure, fallback):
|
||||
provider = width_provider(fallback)
|
||||
gateway = provider.gateway
|
||||
if failure == 'missing_status':
|
||||
gateway.get_current_workplace_status.return_value = None
|
||||
elif failure == 'missing_width':
|
||||
gateway.get_current_workplace_status.return_value.article_description = None
|
||||
else:
|
||||
gateway.get_current_workplace_status.side_effect = ErpReadError('ERP read failed')
|
||||
if fallback is None:
|
||||
with pytest.raises(ErpReadError if failure == 'read_error' else ValueError):
|
||||
provider('Bento 1-12026000814')
|
||||
else:
|
||||
assert provider('Bento 1-12026000814') == 5.0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', [0, -1, float('nan'), float('inf'), -float('inf'),
|
||||
True, '5.0', None, [], {}])
|
||||
def test_invalid_fallback_configuration(tmp_path, value):
|
||||
with open('config/bento1-material-consumption.yaml') as stream:
|
||||
document = yaml.safe_load(stream)
|
||||
document['calculations'][0]['fallback_nominal_width_m'] = value
|
||||
path = tmp_path / 'config.yaml'
|
||||
path.write_text(yaml.safe_dump(document))
|
||||
with pytest.raises(CalculationConfigError, match='fallback_nominal_width_m'):
|
||||
load_material_calculation(path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('path', [
|
||||
'config/bento1-material-consumption.yaml',
|
||||
'config/bento1-spreader3-material-consumption.yaml',
|
||||
])
|
||||
def test_bento_fallback_configuration(path):
|
||||
assert load_material_calculation(path).fallback_nominal_width_m == 5.0
|
||||
|
||||
|
||||
def test_direct_mass_rate_rejects_width_fallback(tmp_path):
|
||||
with open('config/k7-material-consumption.yaml') as stream:
|
||||
document = yaml.safe_load(stream)
|
||||
document['calculations'][0]['fallback_nominal_width_m'] = 5.0
|
||||
path = tmp_path / 'config.yaml'
|
||||
path.write_text(yaml.safe_dump(document))
|
||||
with pytest.raises(CalculationConfigError, match='width-based source mode'):
|
||||
load_material_calculation(path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('configured,returned', [
|
||||
('Bento 1', 'BENTO 1'),
|
||||
('Bento 1', ' \tBENTO 1\n'),
|
||||
@@ -195,6 +298,7 @@ def test_bento_rpm_bootstrap_and_persistent_resume(tmp_path, inter_run_gap_secon
|
||||
def test_k7_config_defaults_remain_direct():
|
||||
config = load_material_calculation('config/k7-material-consumption.yaml')
|
||||
assert config.source_mode == 'direct_mass_rate'
|
||||
assert config.fallback_nominal_width_m is None
|
||||
assert config.rotational_speed_signal_refs == ()
|
||||
assert config.application_signal_refs == ()
|
||||
assert config.gate_threshold == 0.5
|
||||
|
||||
Reference in new issue
Block a user