depot.api.private.shrink ======================== .. py:module:: depot.api.private.shrink .. autoapi-nested-parse:: Shrink Areas and electrified terminus Stations to peak observed concurrency. Internal helpers for :func:`eflips.depot.api.shrink_to_peak_usage`. Operates on events already persisted to the database (run after :func:`eflips.depot.api.add_evaluation_to_database`). Functions --------- .. autoapisummary:: depot.api.private.shrink._compute_peak_concurrency depot.api.private.shrink._round_capacity_for_area_type depot.api.private.shrink._shrink_areas_to_peak depot.api.private.shrink._shrink_stations_to_peak Module Contents --------------- .. py:function:: _compute_peak_concurrency(events, resolution) Count the maximum number of simultaneously-active events. Each event occupies time blocks ``[floor(start/res), max(start+1, ceil(end/res)))`` relative to the earliest start. Back-to-back events at a block boundary do not overlap; sub-resolution events still count as one block. .. py:function:: _round_capacity_for_area_type(peak, area) Round ``peak`` UP to the next valid capacity for ``area.area_type``. Preserves the CHECK constraint defined on :class:`eflips.model.Area`: - DIRECT_ONESIDE: any positive int - DIRECT_TWOSIDE: capacity must be even - LINE: capacity must be a multiple of ``row_count`` (which is preserved) .. py:function:: _shrink_areas_to_peak(scenario, session, resolution) Shrink every :class:`Area` in ``scenario`` to its peak observed usage. Areas whose peak concurrency is zero are deleted along with their :class:`AssocAreaProcess` rows. If we somehow compute a zero peak while events still reference the area we raise :class:`RuntimeError` rather than silently delete persisted state. .. py:function:: _shrink_stations_to_peak(scenario, session, resolution) Shrink electrified opportunity-charging Stations to peak observed usage. Only Stations with ``is_electrified=True`` and ``charge_type=ChargeType.OPPORTUNITY`` are considered. If peak > 0 we update ``amount_charging_places`` and recompute ``power_total``. If peak == 0 we un-electrify the station, atomically nulling all electrification fields to keep the CHECK constraint satisfied.