depot.api.private.shrink¶
Shrink Areas and electrified terminus Stations to peak observed concurrency.
Internal helpers for eflips.depot.api.shrink_to_peak_usage(). Operates on
events already persisted to the database (run after
eflips.depot.api.add_evaluation_to_database()).
Functions¶
|
Count the maximum number of simultaneously-active events. |
|
Round |
|
Shrink every |
|
Shrink electrified opportunity-charging Stations to peak observed usage. |
Module Contents¶
- depot.api.private.shrink._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.- Parameters:
events (Iterable[eflips.model.Event])
resolution (datetime.timedelta)
- Return type:
int
- depot.api.private.shrink._round_capacity_for_area_type(peak, area)¶
Round
peakUP to the next valid capacity forarea.area_type.Preserves the CHECK constraint defined on
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)
- Parameters:
peak (int)
area (eflips.model.Area)
- Return type:
int
- depot.api.private.shrink._shrink_areas_to_peak(scenario, session, resolution)¶
Shrink every
Areainscenarioto its peak observed usage.Areas whose peak concurrency is zero are deleted along with their
AssocAreaProcessrows. If we somehow compute a zero peak while events still reference the area we raiseRuntimeErrorrather than silently delete persisted state.- Parameters:
scenario (eflips.model.Scenario)
session (sqlalchemy.orm.Session)
resolution (datetime.timedelta)
- Return type:
None
- depot.api.private.shrink._shrink_stations_to_peak(scenario, session, resolution)¶
Shrink electrified opportunity-charging Stations to peak observed usage.
Only Stations with
is_electrified=Trueandcharge_type=ChargeType.OPPORTUNITYare considered. If peak > 0 we updateamount_charging_placesand recomputepower_total. If peak == 0 we un-electrify the station, atomically nulling all electrification fields to keep the CHECK constraint satisfied.- Parameters:
scenario (eflips.model.Scenario)
session (sqlalchemy.orm.Session)
resolution (datetime.timedelta)
- Return type:
None