Skip to content

fix(backend): count night shifts in weekly hour cap - #201

Merged
Vhivi merged 6 commits into
mainfrom
fix/miscalculing-days-and-nights-hours
May 31, 2026
Merged

Vhivi merged 6 commits into
mainfrom
fix/miscalculing-days-and-nights-hours

Conversation

@Vhivi

@Vhivi Vhivi commented May 31, 2026

Copy link
Copy Markdown
Owner

Objective

Fix weekly worked-hours calculation so night shifts are included in the per-agent weekly cap, then make that cap configurable through solver.max_weekly_hours.

Breaking Change Notice

No API breaking change.

The default weekly cap remains 36h, preserving existing behavior. Schedules that previously exceeded the real weekly worked-hours cap because night shifts were not counted may now correctly become infeasible.

Scope

  • Count all configured worked vacations in the weekly hours cap, including Nuit.
  • Add configurable solver.max_weekly_hours, expressed in hours, with default 36.
  • Wire max_weekly_hours through solver config loading and SolverContext.
  • Update config schema and example config.
  • Clarify documentation for:
    • strict weekly worked-hours cap
    • paid-hour balance gaps (global_max_gap, period_max_gap)
  • Add regression tests for:
    • default 36h cap rejecting 2 Jour + 2 Nuit
    • configured 48h cap accepting the same worked week
    • schema validation for max_weekly_hours

Validation

  • backend/.venv/Scripts/python.exe -m pytest backend/tests/test_constraints.py -q
  • backend/.venv/Scripts/python.exe -m pytest backend/tests/test_dynamic_solver_config.py backend/tests/test_config_schema.py -q -k "not test_config_json_matches_schema"
  • backend/.venv/Scripts/python.exe -m pytest backend/tests -q

Results

  • Constraint tests pass: 10/10.
  • Dynamic solver config and schema tests pass when excluding local backend/config.json: 11 passed, 1 deselected.
  • Full backend suite: 86 passed, 1 failed.

The remaining failure is local-config related and out of scope: backend/config.json contains restriction_types_durations, a key used by another branch but not yet declared in this branch schema.

Risks and Mitigations

  • Risk: some schedules that were incorrectly feasible may now be rejected because night hours are counted.
  • Mitigation: the cap is configurable via solver.max_weekly_hours; default remains 36h.
  • Risk: future half-vacation behavior may require a higher cap such as 42h.
  • Mitigation: this PR prepares the configuration hook without introducing half-vacations yet.

@Vhivi Vhivi added this to the 4 - Tests et optimisation milestone May 31, 2026
@Vhivi Vhivi self-assigned this May 31, 2026
@Vhivi Vhivi added bug Something isn't working documentation Improvements or additions to documentation backend test optimization labels May 31, 2026
@Vhivi
Vhivi merged commit dcbbfd7 into main May 31, 2026
2 checks passed
@Vhivi
Vhivi deleted the fix/miscalculing-days-and-nights-hours branch May 31, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working documentation Improvements or additions to documentation optimization test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant