Pipeline controller: plan 2 (hard +, error +50 %), backlog throttle, 2 trajectory workers, stop rules, summaries every 50; budget reserve

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Kral
2026-10-05 13:35:54 +02:00
parent 1c4667a0fc
commit 13360292dd
781 changed files with 50211 additions and 22 deletions

View File

@@ -0,0 +1,88 @@
CLASS {{p}}roast_merger DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES:
ty_batch_id TYPE c LENGTH 10,
ty_plant TYPE c LENGTH 4,
ty_lot_id TYPE c LENGTH 8,
ty_weight TYPE p LENGTH 7 DECIMALS 2,
BEGIN OF ty_batch,
batch_id TYPE ty_batch_id,
plant TYPE ty_plant,
lot_id TYPE ty_lot_id,
roast_date TYPE d,
roasted_kg TYPE ty_weight,
END OF ty_batch,
tt_batches TYPE STANDARD TABLE OF ty_batch WITH EMPTY KEY,
BEGIN OF ty_lot_total,
lot_id TYPE ty_lot_id,
batch_count TYPE i,
total_kg TYPE ty_weight,
last_date TYPE d,
END OF ty_lot_total,
tt_lot_totals TYPE STANDARD TABLE OF ty_lot_total WITH EMPTY KEY.
METHODS merge
IMPORTING it_plant_a TYPE tt_batches
it_plant_b TYPE tt_batches
RETURNING VALUE(rt_totals) TYPE tt_lot_totals.
PRIVATE SECTION.
TYPES tt_unique TYPE HASHED TABLE OF ty_batch WITH UNIQUE KEY batch_id.
METHODS add_batches
IMPORTING it_batches TYPE tt_batches
CHANGING ct_unique TYPE tt_unique.
METHODS build_totals
IMPORTING it_unique TYPE tt_unique
RETURNING VALUE(rt_totals) TYPE tt_lot_totals.
ENDCLASS.
CLASS {{p}}roast_merger IMPLEMENTATION.
METHOD merge.
DATA lt_unique TYPE tt_unique.
add_batches( EXPORTING it_batches = it_plant_a
CHANGING ct_unique = lt_unique ).
add_batches( EXPORTING it_batches = it_plant_b
CHANGING ct_unique = lt_unique ).
rt_totals = build_totals( lt_unique ).
ENDMETHOD.
METHOD add_batches.
LOOP AT it_batches INTO DATA(ls_batch).
IF ls_batch-batch_id IS INITIAL OR ls_batch-roasted_kg <= 0.
CONTINUE.
ENDIF.
READ TABLE ct_unique WITH TABLE KEY batch_id = ls_batch-batch_id
ASSIGNING FIELD-SYMBOL(<ls_kept>).
IF sy-subrc <> 0.
INSERT ls_batch INTO TABLE ct_unique.
ELSEIF ls_batch-roasted_kg > <ls_kept>-roasted_kg.
<ls_kept> = ls_batch.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD build_totals.
DATA lt_totals TYPE SORTED TABLE OF ty_lot_total WITH UNIQUE KEY lot_id.
LOOP AT it_unique INTO DATA(ls_batch).
READ TABLE lt_totals WITH TABLE KEY lot_id = ls_batch-lot_id
ASSIGNING FIELD-SYMBOL(<ls_total>).
IF sy-subrc <> 0.
INSERT VALUE #( lot_id = ls_batch-lot_id
batch_count = 1
total_kg = ls_batch-roasted_kg
last_date = ls_batch-roast_date )
INTO TABLE lt_totals.
CONTINUE.
ENDIF.
<ls_total>-batch_count = <ls_total>-batch_count + 1.
<ls_total>-total_kg = <ls_total>-total_kg + ls_batch-roasted_kg.
IF ls_batch-roast_date > <ls_total>-last_date.
<ls_total>-last_date = ls_batch-roast_date.
ENDIF.
ENDLOOP.
rt_totals = lt_totals.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,147 @@
CLASS ltc_roast_merger DEFINITION FINAL FOR TESTING
DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}roast_merger.
METHODS setup.
METHODS weight_of
IMPORTING iv_text TYPE string
RETURNING VALUE(rv_weight) TYPE {{p}}roast_merger=>ty_weight.
METHODS total_of
IMPORTING it_totals TYPE {{p}}roast_merger=>tt_lot_totals
iv_lot TYPE {{p}}roast_merger=>ty_lot_id
RETURNING VALUE(rs_total) TYPE {{p}}roast_merger=>ty_lot_total.
METHODS merges_two_plants FOR TESTING.
METHODS keeps_larger_weight FOR TESTING.
METHODS ignores_invalid FOR TESTING.
METHODS sorts_by_lot FOR TESTING.
METHODS empty_input FOR TESTING.
METHODS last_date_is_latest FOR TESTING.
METHODS single_batch FOR TESTING.
ENDCLASS.
CLASS ltc_roast_merger IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}roast_merger( ).
ENDMETHOD.
METHOD weight_of.
rv_weight = iv_text.
ENDMETHOD.
METHOD total_of.
READ TABLE it_totals WITH KEY lot_id = iv_lot INTO rs_total.
ENDMETHOD.
METHOD merges_two_plants.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240110' roasted_kg = '100.00' )
( batch_id = 'B2' plant = 'P001' lot_id = 'LOT002'
roast_date = '20240111' roasted_kg = '50.00' ) ).
DATA(lt_b) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B3' plant = 'P002' lot_id = 'LOT002'
roast_date = '20240112' roasted_kg = '25.00' ) ).
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 2 ).
DATA(ls_lot2) = total_of( it_totals = lt_totals iv_lot = 'LOT002' ).
cl_abap_unit_assert=>assert_equals( act = ls_lot2-batch_count exp = 2 ).
cl_abap_unit_assert=>assert_equals( act = ls_lot2-total_kg exp = weight_of( '75.00' ) ).
cl_abap_unit_assert=>assert_equals( act = ls_lot2-last_date exp = '20240112' ).
ENDMETHOD.
METHOD keeps_larger_weight.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240101' roasted_kg = '40.00' ) ).
DATA(lt_b) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P002' lot_id = 'LOT001'
roast_date = '20240102' roasted_kg = '60.00' ) ).
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 1 ).
DATA(ls_lot) = total_of( it_totals = lt_totals iv_lot = 'LOT001' ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-batch_count exp = 1 ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-total_kg exp = weight_of( '60.00' ) ).
ENDMETHOD.
METHOD ignores_invalid.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = '' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240101' roasted_kg = '50.00' )
( batch_id = 'B2' plant = 'P001' lot_id = 'LOT002'
roast_date = '20240102' roasted_kg = '0.00' )
( batch_id = 'B3' plant = 'P001' lot_id = 'LOT002'
roast_date = '20240103' roasted_kg = '10.00' ) ).
DATA lt_b TYPE {{p}}roast_merger=>tt_batches.
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 1 ).
DATA(ls_lot) = total_of( it_totals = lt_totals iv_lot = 'LOT002' ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-batch_count exp = 1 ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-total_kg exp = weight_of( '10.00' ) ).
ENDMETHOD.
METHOD sorts_by_lot.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P001' lot_id = 'LOT300'
roast_date = '20240101' roasted_kg = '10.00' )
( batch_id = 'B2' plant = 'P001' lot_id = 'LOT100'
roast_date = '20240102' roasted_kg = '20.00' ) ).
DATA(lt_b) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B3' plant = 'P002' lot_id = 'LOT200'
roast_date = '20240103' roasted_kg = '30.00' ) ).
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 3 ).
cl_abap_unit_assert=>assert_equals( act = lt_totals[ 1 ]-lot_id exp = 'LOT100' ).
cl_abap_unit_assert=>assert_equals( act = lt_totals[ 2 ]-lot_id exp = 'LOT200' ).
cl_abap_unit_assert=>assert_equals( act = lt_totals[ 3 ]-lot_id exp = 'LOT300' ).
ENDMETHOD.
METHOD empty_input.
DATA lt_empty TYPE {{p}}roast_merger=>tt_batches.
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_empty it_plant_b = lt_empty ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 0 ).
ENDMETHOD.
METHOD last_date_is_latest.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240120' roasted_kg = '10.00' )
( batch_id = 'B2' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240105' roasted_kg = '10.00' )
( batch_id = 'B3' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240131' roasted_kg = '10.00' ) ).
DATA lt_b TYPE {{p}}roast_merger=>tt_batches.
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
DATA(ls_lot) = total_of( it_totals = lt_totals iv_lot = 'LOT001' ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-last_date exp = '20240131' ).
ENDMETHOD.
METHOD single_batch.
DATA(lt_a) = VALUE {{p}}roast_merger=>tt_batches(
( batch_id = 'B1' plant = 'P001' lot_id = 'LOT001'
roast_date = '20240107' roasted_kg = '12.50' ) ).
DATA lt_b TYPE {{p}}roast_merger=>tt_batches.
DATA(lt_totals) = mo_cut->merge( it_plant_a = lt_a it_plant_b = lt_b ).
cl_abap_unit_assert=>assert_equals( act = lines( lt_totals ) exp = 1 ).
DATA(ls_lot) = total_of( it_totals = lt_totals iv_lot = 'LOT001' ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-batch_count exp = 1 ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-total_kg exp = weight_of( '12.50' ) ).
cl_abap_unit_assert=>assert_equals( act = ls_lot-last_date exp = '20240107' ).
ENDMETHOD.
ENDCLASS.