Spaces:
Sleeping
Sleeping
refactored project structure. renamed scheduler dir to src
Browse files- docs/README.md +29 -0
- docs/control.md +23 -0
- docs/core.md +71 -0
- docs/dashboard.md +47 -0
- docs/data.md +34 -0
- docs/metrics.md +14 -0
- docs/monitoring.md +24 -0
- docs/scheduler_flowchart.md +114 -0
- docs/simulation.md +40 -0
- docs/utils.md +15 -0
- pyproject.toml +1 -1
docs/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Scheduler Documentation (Core Algorithm and Surrounding Modules)
|
| 2 |
+
|
| 3 |
+
This documentation explains the end‑to‑end flow for the scheduler and its supporting modules, and provides detailed per‑directory guides that document individual files. Start with the high‑level flowchart, then dive into the directory guides.
|
| 4 |
+
|
| 5 |
+
- High‑level flowchart: see `docs/scheduler_flowchart.md`
|
| 6 |
+
- Directory guides (each includes per‑file details):
|
| 7 |
+
- `docs/core.md` — core scheduler domain and algorithm
|
| 8 |
+
- `docs/simulation.md` — discrete‑event simulation and policies
|
| 9 |
+
- `docs/control.md` — manual overrides and explainability surfaces
|
| 10 |
+
- `docs/dashboard.md` — Streamlit dashboard and pages
|
| 11 |
+
- `docs/data.md` — data loaders, defaults and configuration
|
| 12 |
+
- `docs/metrics.md` — basic metrics utilities
|
| 13 |
+
- `docs/monitoring.md` — ripeness monitoring (not yet integrated)
|
| 14 |
+
- `docs/utils.md` — utilities (calendar)
|
| 15 |
+
|
| 16 |
+
Related (outside current scope but referenced):
|
| 17 |
+
- Outputs (cause lists, reports) live under `scheduler/output/` and `outputs/`.
|
| 18 |
+
|
| 19 |
+
#### Quick Start Reading Order
|
| 20 |
+
1) `scheduler_flowchart.md` (overview)
|
| 21 |
+
2) `core.md` (domain + algorithm)
|
| 22 |
+
3) `simulation.md` (how scenarios are evaluated at scale)
|
| 23 |
+
4) `control.md` (how human inputs override the algorithm)
|
| 24 |
+
5) `dashboard.md` (how the UI wires it together)
|
| 25 |
+
|
| 26 |
+
#### Definitions at a Glance
|
| 27 |
+
- Case ripeness: classification indicating whether a case is ready to be scheduled and with what priority. Implemented in `scheduler/core/ripeness.py`.
|
| 28 |
+
- Scheduling algorithm: orchestrates filtering, prioritization, overrides, and courtroom allocation. Implemented in `scheduler/core/algorithm.py`.
|
| 29 |
+
- Simulation: forward model to evaluate policy performance over time. Implemented in `scheduler/simulation/engine.py` and related modules.
|
docs/control.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Control Module — Overrides and Explainability
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/control/`
|
| 4 |
+
|
| 5 |
+
This package houses the manual control plane that allows judges or operators to override algorithmic decisions and to inspect the reasoning behind suggestions.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `overrides.py`
|
| 10 |
+
- Purpose: Define override types, manage override drafts per cause list, validate changes, and collect judge preferences and audit trails.
|
| 11 |
+
- Key elements:
|
| 12 |
+
- `OverrideType` (Enum): categories like ripeness override, capacity change, add/remove case.
|
| 13 |
+
- `Override`: a single change request with metadata; `to_dict()`, `to_readable_text()` helpers.
|
| 14 |
+
- `JudgePreferences`: persistent preferences per judge; `to_dict()`.
|
| 15 |
+
- `CauseListDraft`: a draft editable list for a given date/courtroom/judge; exposes `get_acceptance_rate()` and `get_modifications_summary()`.
|
| 16 |
+
- `OverrideValidator`: validates requested changes; surface `get_errors()`; targeted validate methods for each override kind (ripeness, capacity, add/remove case).
|
| 17 |
+
- `OverrideManager`: creates drafts, applies overrides, finalizes drafts, fetches preferences, produces statistics, and exports an audit trail.
|
| 18 |
+
- Interactions: Consumed by `core/algorithm.py` to apply judge preferences and manual modifications before final allocation.
|
| 19 |
+
|
| 20 |
+
- `explainability.py`
|
| 21 |
+
- Purpose: Human‑readable explanations for why cases were selected or not.
|
| 22 |
+
- Typical content: utilities that convert ripeness/eligibility checks and policy scores into readable reasons for UI display and audit logs.
|
| 23 |
+
- Interactions: Used by dashboard pages and potentially during `SchedulingAlgorithm.schedule_day` explanation generation.
|
docs/core.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Core Module — Domain and Scheduling Algorithm
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/core/`
|
| 4 |
+
|
| 5 |
+
This package defines the domain objects (cases, hearings, courtrooms, judges), the ripeness classifier, policy interfaces, and the main scheduling algorithm that orchestrates daily scheduling.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `algorithm.py`
|
| 10 |
+
- Purpose: Implements the daily scheduling pipeline.
|
| 11 |
+
- Key classes:
|
| 12 |
+
- `SchedulingResult`: Aggregates scheduled cases, unscheduled reasons, applied overrides, and explanations.
|
| 13 |
+
- `SchedulingAlgorithm`: Orchestrates the day’s scheduling.
|
| 14 |
+
- `schedule_day(cases, courtrooms, current_date, overrides, preferences, max_explanations_unscheduled)`
|
| 15 |
+
- Flow:
|
| 16 |
+
1) Compute judge preference overrides (if provided).
|
| 17 |
+
2) Filter by ripeness (via `RipenessClassifier`), tracking unscheduled reasons for unripe cases.
|
| 18 |
+
3) Filter eligibility (age gaps, disposed, same‑day constraints) and compute priority.
|
| 19 |
+
4) Apply manual overrides (add/remove cases; capacity changes).
|
| 20 |
+
5) Allocate cases to courtrooms (via allocator interface used in simulation layer).
|
| 21 |
+
6) Generate explanations for unscheduled cases (up to cap) and successful allocations.
|
| 22 |
+
- Inputs: list of `Case`, list of `Courtroom`, `date`, optional `Override` list, optional `JudgePreferences`.
|
| 23 |
+
- Outputs: `SchedulingResult` with scheduled list and explanations.
|
| 24 |
+
- Internal helpers: `_filter_by_ripeness`, `_filter_eligible`, `_get_preference_overrides`, `_apply_manual_overrides`, `_allocate_cases`, `_clear_temporary_case_flags`.
|
| 25 |
+
- Interactions: `core.ripeness`, `control.overrides`, `simulation.allocator`.
|
| 26 |
+
|
| 27 |
+
- `case.py`
|
| 28 |
+
- Purpose: Core case model and priority logic.
|
| 29 |
+
- Key classes:
|
| 30 |
+
- `CaseStatus`: Enum of lifecycle statuses.
|
| 31 |
+
- `Case`: Fields describe type, stage, history, last hearing, etc.
|
| 32 |
+
- Selected methods: `progress_to_stage`, `record_hearing`, `update_age`, `compute_readiness_score`, `is_ready_for_scheduling`, `needs_alert`, `get_priority_score`, `mark_unripe`, `mark_ripe`, `mark_scheduled`, `is_disposed`, `to_dict`.
|
| 33 |
+
- Interactions: Used by ripeness classifier, scheduler, and simulation.
|
| 34 |
+
|
| 35 |
+
- `courtroom.py`
|
| 36 |
+
- Purpose: Represents courtroom capacity and scheduling slots.
|
| 37 |
+
- Typical members: courtroom identifier, capacity/availability for a given `date`.
|
| 38 |
+
- Interactions: Allocator consumes courtroom capacity when placing cases.
|
| 39 |
+
|
| 40 |
+
- `hearing.py`
|
| 41 |
+
- Purpose: Hearing record representation (date, outcome, adjournment, etc.).
|
| 42 |
+
- Interactions: Case history and scheduler eligibility checks (min gap, outcomes).
|
| 43 |
+
|
| 44 |
+
- `judge.py`
|
| 45 |
+
- Purpose: Judge metadata and optional preference hooks.
|
| 46 |
+
- Interactions: `control.overrides.JudgePreferences` integrates with algorithm preference overrides.
|
| 47 |
+
|
| 48 |
+
- `policy.py`
|
| 49 |
+
- Purpose: Defines the scheduling policy interface and default implementations for prioritization heuristics.
|
| 50 |
+
- Interactions: Injected into `SchedulingAlgorithm` to determine case ordering.
|
| 51 |
+
|
| 52 |
+
- `ripeness.py`
|
| 53 |
+
- Purpose: Ripeness classifier and thresholds.
|
| 54 |
+
- Key elements:
|
| 55 |
+
- `RipenessStatus` enum with helpers `is_ripe()` and `is_unripe()`.
|
| 56 |
+
- `RipenessClassifier` with methods:
|
| 57 |
+
- `classify(case, current_date)`: returns `RipenessStatus` and sets reasons.
|
| 58 |
+
- `get_ripeness_priority(case, current_date)`: numeric priority for scheduling.
|
| 59 |
+
- `is_schedulable(case, current_date)`: boolean gate for eligibility.
|
| 60 |
+
- `get_ripeness_reason(status)`: human‑readable reason strings.
|
| 61 |
+
- `estimate_ripening_time(case, current_date)`: expected time until ready.
|
| 62 |
+
- `set_thresholds(new_thresholds)`, `get_current_thresholds()`.
|
| 63 |
+
- Interactions: Used both by `algorithm.py` and the simulation engine.
|
| 64 |
+
|
| 65 |
+
#### Core flow (within `SchedulingAlgorithm.schedule_day`)
|
| 66 |
+
1) Collect inputs (cases, courtrooms, date, optional overrides/preferences).
|
| 67 |
+
2) Ripeness filter: mark unripe with reasons; compute ripeness‑based priority.
|
| 68 |
+
3) Eligibility filter: ensure min gap since last hearing, exclude disposed, enforce capacity constraints.
|
| 69 |
+
4) Apply overrides (manual changes and judge preferences).
|
| 70 |
+
5) Allocate to courtrooms; finalize schedule.
|
| 71 |
+
6) Produce explanations and a `SchedulingResult`.
|
docs/dashboard.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Dashboard Module — Streamlit App and Pages
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/dashboard/`
|
| 4 |
+
|
| 5 |
+
The dashboard provides a Streamlit UI to explore data, inspect the ripeness classifier, run simulations, configure overrides, and view analytics/reports.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `app.py`
|
| 10 |
+
- Purpose: Streamlit entrypoint that initializes navigation, shared state, and page routing.
|
| 11 |
+
- Interactions: Uses helpers under `dashboard/utils/` to load data and run simulations; mounts pages under `dashboard/pages/`.
|
| 12 |
+
|
| 13 |
+
- `__init__.py`
|
| 14 |
+
- Purpose: Package initialization for the dashboard module.
|
| 15 |
+
|
| 16 |
+
- `pages/1_Data_And_Insights.py`
|
| 17 |
+
- Purpose: Data loading, cleaning summaries, EDA‑style insights and figures.
|
| 18 |
+
- Inputs: parquet/CSV datasets and computed reports in `reports/figures/*`.
|
| 19 |
+
|
| 20 |
+
- `pages/2_Ripeness_Classifier.py`
|
| 21 |
+
- Purpose: Visualize and test `core.ripeness.RipenessClassifier` on sample cases; display reasons and thresholds.
|
| 22 |
+
- Interactions: Can call into `RipenessClassifier.get_current_thresholds()` and `classify()`.
|
| 23 |
+
|
| 24 |
+
- `pages/3_Simulation_Workflow.py`
|
| 25 |
+
- Purpose: Configure and run simulation scenarios; display outputs (events, metrics, summaries).
|
| 26 |
+
- Interactions: `dashboard/utils/simulation_runner.py`; backend `scheduler/simulation/engine.py`.
|
| 27 |
+
|
| 28 |
+
- `pages/4_Cause_Lists_And_Overrides.py`
|
| 29 |
+
- Purpose: Generate draft cause lists for a date; review/apply overrides; export finalized lists.
|
| 30 |
+
- Interactions: `control/overrides.py` for `OverrideManager` and `CauseListDraft`.
|
| 31 |
+
|
| 32 |
+
- `pages/6_Analytics_And_Reports.py`
|
| 33 |
+
- Purpose: Aggregate analytics, charts, and report downloads; links to `reports/figures/*` and `outputs/simulation_runs/*`.
|
| 34 |
+
|
| 35 |
+
- `utils/__init__.py`
|
| 36 |
+
- Purpose: Package initialization for dashboard utilities.
|
| 37 |
+
|
| 38 |
+
- `utils/data_loader.py`
|
| 39 |
+
- Purpose: Load datasets and parameter files for use in the UI; cache artifacts for responsiveness.
|
| 40 |
+
- Inputs: `Data/`, `reports/figures/*/params/*.csv`, and defaults in `scheduler/data/defaults/*`.
|
| 41 |
+
|
| 42 |
+
- `utils/simulation_runner.py`
|
| 43 |
+
- Purpose: Convenience layer to assemble `CourtSimConfig`, run the simulation, and collect outputs for display/download.
|
| 44 |
+
- Interactions: `scheduler/simulation/engine.py` and policy modules.
|
| 45 |
+
|
| 46 |
+
- `utils/ui_input_parser.py`
|
| 47 |
+
- Purpose: Parse and validate user inputs from Streamlit widgets into typed configs/overrides.
|
docs/data.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Data Module — Parameters, Defaults, and Case Generation
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/data/`
|
| 4 |
+
|
| 5 |
+
This package is responsible for loading configuration/parameters, exposing default parameter tables, and (optionally) generating synthetic cases. These inputs are used by both the core scheduler and the simulation engine.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `config.py`
|
| 10 |
+
- Purpose: Data/config structures and helpers to read configuration (e.g., TOML under `configs/`).
|
| 11 |
+
- Typical contents: typed config models, IO utilities to load/validate values, and a central place to map file paths to parameter tables.
|
| 12 |
+
- Interactions: Consumed by dashboard utilities, simulation runner, and EDA.
|
| 13 |
+
|
| 14 |
+
- `param_loader.py`
|
| 15 |
+
- Purpose: Load parameter tables required by the scheduler and simulation from CSV/JSON defaults or project artifacts.
|
| 16 |
+
- Inputs (defaults): files under `scheduler/data/defaults/`, including:
|
| 17 |
+
- `adjournment_proxies.csv` — signals/statistics used to approximate adjournment likelihood.
|
| 18 |
+
- `case_type_summary.csv` — frequencies and basic properties by case type.
|
| 19 |
+
- `court_capacity_global.json` — nominal/maximum capacity settings.
|
| 20 |
+
- `stage_duration.csv` — typical durations per stage.
|
| 21 |
+
- `stage_transition_entropy.csv` — transition uncertainty by stage.
|
| 22 |
+
- `stage_transition_probs.csv` — Markov transition probabilities between stages.
|
| 23 |
+
- Outputs: in‑memory DataFrames/objects consumed by `core` and `simulation`.
|
| 24 |
+
|
| 25 |
+
- `case_generator.py`
|
| 26 |
+
- Purpose: Produce synthetic cases consistent with the parameter distributions for use in simulations or demos.
|
| 27 |
+
- Interactions: Reads parameters via `param_loader.py`; emits `core/Case` instances ready for ripeness evaluation and scheduling.
|
| 28 |
+
|
| 29 |
+
- `__init__.py`
|
| 30 |
+
- Purpose: Package initialization; may expose convenience imports for loader/generator utilities.
|
| 31 |
+
|
| 32 |
+
#### Data sources
|
| 33 |
+
- Project data: `Data/*.parquet` and derived artifacts in `reports/figures/*` (e.g., cleaned parquet, params CSVs).
|
| 34 |
+
- Defaults: `scheduler/data/defaults/*` bundled with the package as fallback/configuration baselines.
|
docs/metrics.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Metrics Module — Basic Metrics Utilities
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/metrics/`
|
| 4 |
+
|
| 5 |
+
This package provides lightweight metrics helpers used by simulation runs and analyses.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `basic.py`
|
| 10 |
+
- Purpose: Compute aggregate metrics from simulation or scheduling outputs (e.g., throughput, utilization, wait times, adjournment rates).
|
| 11 |
+
- Typical usage: Imported by simulation/reporting code to summarize daily/event logs into CSVs found under `outputs/simulation_runs/*/metrics.csv`.
|
| 12 |
+
|
| 13 |
+
- `__init__.py`
|
| 14 |
+
- Purpose: Package initialization; may re‑export common helpers.
|
docs/monitoring.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Monitoring Module — Ripeness Tracking and Calibration
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/monitoring/`
|
| 4 |
+
|
| 5 |
+
This package provides components to track ripeness prediction outcomes and calibrate thresholds based on observed accuracy. It is currently not wired into the main scheduling flow but is designed for future integration.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `ripeness_metrics.py`
|
| 10 |
+
- Purpose: Record per‑case ripeness predictions and later outcomes to compute accuracy statistics and error types.
|
| 11 |
+
- Key elements:
|
| 12 |
+
- `RipenessPrediction` (dataclass): captures `case_id`, `predicted_status`, `prediction_date`, and later the `actual_outcome`, `was_adjourned`, and `outcome_date`.
|
| 13 |
+
- `RipenessMetrics`:
|
| 14 |
+
- `record_prediction(case_id, predicted_status, prediction_date)` — log a prediction when the classifier is invoked.
|
| 15 |
+
- `record_outcome(case_id, actual_outcome, was_adjourned, outcome_date)` — attach ground truth when available.
|
| 16 |
+
- Export utilities to summarize false positives/negatives and overall accuracy; convenience frame exports via pandas.
|
| 17 |
+
- Interactions: Expects callers (e.g., the scheduler) to log predictions and later outcomes; can write CSV summaries for analysis.
|
| 18 |
+
|
| 19 |
+
- `ripeness_calibrator.py`
|
| 20 |
+
- Purpose: Use aggregated metrics to suggest or set revised ripeness thresholds that improve real‑world performance.
|
| 21 |
+
- Typical responsibilities: fit threshold adjustments to minimize misclassification costs; produce human‑readable calibration reports and recommended parameter deltas consumable by `core/ripeness.py` via `RipenessClassifier.set_thresholds()`.
|
| 22 |
+
|
| 23 |
+
- `__init__.py`
|
| 24 |
+
- Purpose: Package initialization; may expose convenience imports for metrics/calibration.
|
docs/scheduler_flowchart.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Scheduler End-to-End Flowchart
|
| 2 |
+
|
| 3 |
+
This document shows the high-level flow across modules using Mermaid. It covers input data preparation, ripeness classification, scheduling, overrides, allocation, outputs, and optional simulation and dashboard flows.
|
| 4 |
+
|
| 5 |
+
```mermaid
|
| 6 |
+
flowchart TD
|
| 7 |
+
|
| 8 |
+
%% Inputs
|
| 9 |
+
subgraph Data_Layer
|
| 10 |
+
DCFG[configs/*.toml]
|
| 11 |
+
DLOAD[scheduler/data/param_loader.py<br/>scheduler/data/config.py]
|
| 12 |
+
DDEFS[scheduler/data/defaults/*]
|
| 13 |
+
DCASES[Data/cases.parquet<br/>reports/figures/*/cases_clean.parquet]
|
| 14 |
+
DHEAR[Data/hearings.parquet<br/>reports/figures/*/hearings_clean.parquet]
|
| 15 |
+
end
|
| 16 |
+
|
| 17 |
+
%% Core Domain
|
| 18 |
+
subgraph Core_Domain
|
| 19 |
+
CASE[scheduler/core/case.py]
|
| 20 |
+
RIPEN[scheduler/core/ripeness.py]
|
| 21 |
+
HEAR[scheduler/core/hearing.py]
|
| 22 |
+
ROOM[scheduler/core/courtroom.py]
|
| 23 |
+
JUDGE[scheduler/core/judge.py]
|
| 24 |
+
POLICY[scheduler/core/policy.py]
|
| 25 |
+
ALGO[scheduler/core/algorithm.py]
|
| 26 |
+
end
|
| 27 |
+
|
| 28 |
+
%% Control
|
| 29 |
+
subgraph Control_and_Overrides
|
| 30 |
+
OV[scheduler/control/overrides.py]
|
| 31 |
+
EXP[scheduler/control/explainability.py]
|
| 32 |
+
end
|
| 33 |
+
|
| 34 |
+
%% Allocation/Simulation
|
| 35 |
+
subgraph Simulation_Engine
|
| 36 |
+
SIM[scheduler/simulation/engine.py]
|
| 37 |
+
ALLOC[scheduler/simulation/allocator.py]
|
| 38 |
+
POLS[scheduler/simulation/policies/*]
|
| 39 |
+
end
|
| 40 |
+
|
| 41 |
+
%% UI
|
| 42 |
+
subgraph Dashboard_UI
|
| 43 |
+
APP[scheduler/dashboard/app.py]
|
| 44 |
+
PAGES[scheduler/dashboard/pages/*]
|
| 45 |
+
DUTIL[scheduler/dashboard/utils/*]
|
| 46 |
+
end
|
| 47 |
+
|
| 48 |
+
%% Metrics and Monitoring
|
| 49 |
+
subgraph Metrics_and_Monitoring
|
| 50 |
+
MET[scheduler/metrics/basic.py]
|
| 51 |
+
MONCAL[scheduler/monitoring/ripeness_calibrator.py]
|
| 52 |
+
MONMET[scheduler/monitoring/ripeness_metrics.py]
|
| 53 |
+
end
|
| 54 |
+
|
| 55 |
+
%% Outputs
|
| 56 |
+
subgraph Outputs
|
| 57 |
+
OUTCL[scheduler/output/cause_list.py]
|
| 58 |
+
OUTFILES[outputs/simulation_runs/*<br/>reports/*]
|
| 59 |
+
end
|
| 60 |
+
|
| 61 |
+
%% Data flow
|
| 62 |
+
DCFG --> DLOAD
|
| 63 |
+
DDEFS --> DLOAD
|
| 64 |
+
DCASES --> DLOAD
|
| 65 |
+
DHEAR --> DLOAD
|
| 66 |
+
|
| 67 |
+
DLOAD --> CASE
|
| 68 |
+
CASE --> RIPEN
|
| 69 |
+
RIPEN --> ALGO
|
| 70 |
+
HEAR --> ALGO
|
| 71 |
+
ROOM --> ALGO
|
| 72 |
+
JUDGE --> ALGO
|
| 73 |
+
POLICY --> ALGO
|
| 74 |
+
|
| 75 |
+
%% Scheduling path for a real day
|
| 76 |
+
ALGO -->|filters by ripeness| RIPEN
|
| 77 |
+
ALGO -->|eligibility and priority| CASE
|
| 78 |
+
ALGO -->|manual overrides| OV
|
| 79 |
+
ALGO -->|explanations| EXP
|
| 80 |
+
ALGO -->|allocation| ALLOC
|
| 81 |
+
ALLOC --> OUTCL
|
| 82 |
+
OUTCL --> OUTFILES
|
| 83 |
+
|
| 84 |
+
%% Simulation path (optional)
|
| 85 |
+
DLOAD --> SIM
|
| 86 |
+
SIM --> RIPEN
|
| 87 |
+
SIM --> POLS
|
| 88 |
+
SIM --> ALLOC
|
| 89 |
+
SIM --> MET
|
| 90 |
+
SIM --> OUTFILES
|
| 91 |
+
|
| 92 |
+
%% Dashboard path
|
| 93 |
+
DUTIL --> APP
|
| 94 |
+
APP --> PAGES
|
| 95 |
+
PAGES --> ALGO
|
| 96 |
+
PAGES --> SIM
|
| 97 |
+
PAGES --> OUTFILES
|
| 98 |
+
PAGES --> EXP
|
| 99 |
+
PAGES --> OV
|
| 100 |
+
|
| 101 |
+
%% Monitoring (future integration)
|
| 102 |
+
ALGO -. record predictions .-> MONMET
|
| 103 |
+
MONMET -. calibrate thresholds .-> MONCAL
|
| 104 |
+
MONCAL -. update ripeness thresholds .-> RIPEN
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
#### Narrative
|
| 108 |
+
1) Data layer assembles parameters and input datasets via `param_loader.py` and `config.py`, pulling defaults from `scheduler/data/defaults/*` and optionally real case/hearing data.
|
| 109 |
+
2) Core domain models (`case.py`, `hearing.py`, `courtroom.py`, `judge.py`) define the state. Ripeness (`ripeness.py`) classifies cases as ripe/unripe and provides reasons and thresholds.
|
| 110 |
+
3) The scheduling algorithm (`algorithm.py`) orchestrates: ripeness filtering, priority computation, manual overrides, and courtroom allocation. Explanations are available through `control/explainability.py`.
|
| 111 |
+
4) Allocations produce cause lists (`output/cause_list.py`) and artifacts.
|
| 112 |
+
5) The simulation engine (`simulation/engine.py`) uses the same domain and policies to stress‑test scheduling strategies at scale, producing metrics and reports.
|
| 113 |
+
6) The dashboard (`scheduler/dashboard/*`) provides a UI to run data explorations, inspect ripeness, run simulations, and export cause lists.
|
| 114 |
+
7) Monitoring components track classification accuracy and enable future threshold calibration; currently not wired into the live flow.
|
docs/simulation.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Simulation Module — Engine, Allocator, and Policies
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/simulation/`
|
| 4 |
+
|
| 5 |
+
This package provides a discrete‑event simulation of the court scheduling system. It generates synthetic case flows (or consumes real‑like parameters), evaluates scheduling/ripeness policies, and produces quantitative outputs and reports.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `engine.py`
|
| 10 |
+
- Purpose: Main simulation loop and state transition engine.
|
| 11 |
+
- Key classes:
|
| 12 |
+
- `CourtSimConfig`: Parameters (capacity, stage transition matrices, adjournment params, filings, horizon, etc.).
|
| 13 |
+
- `CourtSimResult`: Aggregated outputs produced by a run.
|
| 14 |
+
- `CourtSim`: The engine orchestrating daily cycles:
|
| 15 |
+
- `_init_stage_ready()`: initializes stage readiness from configuration.
|
| 16 |
+
- `_evaluate_ripeness(current)`: classify cases using `core.ripeness.RipenessClassifier`.
|
| 17 |
+
- `_choose_cases_for_day(current)`: select candidates (potentially via policies/priority).
|
| 18 |
+
- `_file_new_cases(current, n)`: generate new cases based on expected filings.
|
| 19 |
+
- `_day_process(current)`: core daily loop combining filings, ripeness, scheduling, hearings, adjournments, and disposals.
|
| 20 |
+
- `run()`: iterate over the configured horizon; write metrics and event logs.
|
| 21 |
+
- Interactions: Uses domain models in `scheduler/core/*`, policies in `scheduler/simulation/policies/*`, and allocator.
|
| 22 |
+
|
| 23 |
+
- `allocator.py`
|
| 24 |
+
- Purpose: Allocate prioritized cases to available courtroom capacity.
|
| 25 |
+
- Typical responsibilities: respect per‑courtroom limits, avoid duplicate bookings, ensure eligibility constraints.
|
| 26 |
+
- Interactions: Invoked by both the simulation engine and the core scheduling algorithm.
|
| 27 |
+
|
| 28 |
+
- `policies/`
|
| 29 |
+
- Purpose: Pluggable case selection strategies.
|
| 30 |
+
- Files:
|
| 31 |
+
- `age.py`: age‑based prioritization (older cases first, possibly weighted).
|
| 32 |
+
- `fifo.py`: first‑in first‑out ordering respecting readiness.
|
| 33 |
+
- `readiness.py`: prioritization by computed readiness or ripeness score.
|
| 34 |
+
- Interface: Each policy exposes a common callable/signature expected by `engine.py` and the core algorithm’s policy abstraction (`core/policy.py`).
|
| 35 |
+
|
| 36 |
+
#### Simulation flow (high level)
|
| 37 |
+
1) Initialize `CourtSimConfig` from data defaults and parameters.
|
| 38 |
+
2) Seed a case population and stage readiness.
|
| 39 |
+
3) For each simulated day: file new cases, evaluate ripeness, select cases, allocate to courtrooms, conduct hearings, sample adjournments/next stages/disposals.
|
| 40 |
+
4) Persist daily summaries, metrics, and event logs to `outputs/simulation_runs/<version_timestamp>/`.
|
docs/utils.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Utils Module — Calendar Utilities
|
| 2 |
+
|
| 3 |
+
Directory: `scheduler/utils/`
|
| 4 |
+
|
| 5 |
+
Utility functions that support scheduling and simulation. Currently focused on court calendar handling.
|
| 6 |
+
|
| 7 |
+
#### Files overview
|
| 8 |
+
|
| 9 |
+
- `calendar.py`
|
| 10 |
+
- Purpose: Calendar/date helpers used by the scheduler and simulation.
|
| 11 |
+
- Typical responsibilities: business day calculations, holiday/weekend handling, date ranges for scheduling windows, and formatting for outputs.
|
| 12 |
+
- Interactions: Imported where date arithmetic and calendar rules are required (e.g., selecting valid hearing days).
|
| 13 |
+
|
| 14 |
+
- `__init__.py`
|
| 15 |
+
- Purpose: Package initialization.
|
pyproject.toml
CHANGED
|
@@ -54,7 +54,7 @@ court-scheduler = "cli.main:app"
|
|
| 54 |
include = [
|
| 55 |
"cli",
|
| 56 |
"eda",
|
| 57 |
-
"
|
| 58 |
]
|
| 59 |
exclude = [
|
| 60 |
"Data",
|
|
|
|
| 54 |
include = [
|
| 55 |
"cli",
|
| 56 |
"eda",
|
| 57 |
+
"src",
|
| 58 |
]
|
| 59 |
exclude = [
|
| 60 |
"Data",
|