Skip to content

FEAT:🌙 Prefer remote stands overnight for configured airfields#1814

Open
MrAdder wants to merge 12 commits intoVATSIM-UK:mainfrom
MrAdder:issue-1762
Open

FEAT:🌙 Prefer remote stands overnight for configured airfields#1814
MrAdder wants to merge 12 commits intoVATSIM-UK:mainfrom
MrAdder:issue-1762

Conversation

@MrAdder
Copy link
Contributor

@MrAdder MrAdder commented Feb 23, 2026

✨ Summary

This PR adds an optional overnight bias to stand allocation for selected arrival airfields.
When enabled, and during a configured night window (Europe/London), the allocator will prefer stands explicitly marked as overnight-remote via a new stands.overnight_remote_preferred flag.

✅ Default behaviour remains unchanged because the feature is disabled by default.


🔧 What changed

🛬 Allocation ordering update

  • Updates nightTimeRemoteStandOrderCondition() to:
    • Use planned_destairport (normalised to uppercase) for airfield matching
    • Respect stands.night_remote_stand_weighting.enabled + airfields
    • Apply only during configured night window (start_hourend_hour, supports midnight crossing)
    • Prefer stands where stands.overnight_remote_preferred = 1

Ordering fragment added (prepended when active):

CASE WHEN stands.overnight_remote_preferred = 1 THEN 0 ELSE 1 END ASC

🧱 Schema change (new column)

  • Adds stands.overnight_remote_preferred boolean column:
    • default: false
    • indexed for filtering/sorting/perf
    • migration: 2026_02_25_000001_add_overnight_remote_preferred_to_stands.php

🧩 Model / factory updates

  • Stand model:
    • adds overnight_remote_preferred to $fillable
    • casts to boolean
  • StandFactory default:
    • sets overnight_remote_preferred => false

🖥️ Admin UI (Filament) updates

  • StandResource form:
    • adds a toggle for overnight_remote_preferred
  • StandResource table:
    • adds boolean column for overnight_remote_preferred

🌍 Config updates

  • Keeps stands.night_remote_stand_weighting feature flag + time window config
  • Removes remote_priority_threshold (no longer used)

Config still includes:

  • enabled (env: NIGHT_REMOTE_STAND_WEIGHTING_ENABLED, default false)
  • airfields
  • start_hour
  • end_hour

🧪 Tests

Adds/updates functional coverage to verify:

  • ✅ At night (23:00 Europe/London) and for configured airfields, a stand with overnight_remote_preferred=true is preferred
  • ✅ Outside the night window (12:00 Europe/London), allocation behaves normally

Tests use Carbon::setTestNow() and reset afterwards.


💡 Why

Some airfields prefer remote stands overnight (ops flow, noise/terminal constraints, overnight parking patterns).
This change makes that preference explicit and configurable per stand, rather than inferring “remote-ness” from assignment_priority.


🚀 Rollout / Ops notes

✅ Enable feature (optional)

NIGHT_REMOTE_STAND_WEIGHTING_ENABLED=true

✅ Mark stands to be preferred overnight

  • Set overnight_remote_preferred = true for relevant stands (via Filament UI or DB update)

✅ Limit scope per airfield

  • Add airfield ICAOs to stands.night_remote_stand_weighting.airfields

⚠️ Risk / Impact

🟢 Low risk

  • Feature is opt-in via flag
  • Scoped by airfield + time window
  • Ordering is additive (prepended), existing logic remains intact

🧠 Considerations

  • Uses Europe/London timezone (DST-aware)
  • Requires stands to be explicitly flagged as overnight_remote_preferred

📋 Checklist

  • Feature flag defaulted OFF 📴
  • Migration added + indexed 🗄️
  • Model + factory updated 🧬
  • Filament form + table updated 🖥️
  • Tests updated/added 🧪
  • Backwards compatible by default ✅

Fixes #1762

full push of feature
Refactored nightTimeRemoteStandOrderCondition() to reduce return paths and satisfy the “max 3 returns” rule by consolidating guard conditions into booleans ($isEnabledForAirfield, $shouldApplyRemoteWeighting) before the final SQL fragment generation.
- Fixed the root cause of the failing night-weighting test by correcting the airfield lookup in nightTimeRemoteStandOrderCondition(): it now uses planned_destairport (which is populated on NetworkAircraft) instead of arrival_airfield (which was not), so the night remote weighting can actually activate.

- Made the airfield match case-insensitive by normalizing both the aircraft destination and configured airfield list to uppercase before comparison, preventing config/case mismatches from disabling the feature.
@19wintersp
Copy link
Contributor

Would it not be better to define a new property for stands indicating whether they are remote/preferred for overnight parking? Hijacking the assignment priority for this purpose seems a little perverse when it is also used (as I understand it) for marking stands as temporarily out-of-use, or for larger stands in mixed-size stand arrangements

@MrAdder
Copy link
Contributor Author

MrAdder commented Feb 24, 2026

Would it not be better to define a new property for stands indicating whether they are remote/preferred for overnight parking? Hijacking the assignment priority for this purpose seems a little perverse when it is also used (as I understand it) for marking stands as temporarily out-of-use, or for larger stands in mixed-size stand arrangements

I can implement that logic instead I just did it this way originally as it seemed logical with what was asked didn't think of this way round

Change to a more logical approach to the Night time stands
@MrAdder
Copy link
Contributor Author

MrAdder commented Feb 25, 2026

Updated PR Text in regards to changes

@MrAdder MrAdder changed the title 🌙 Prefer remote stands overnight for configured airfields (feature-flagged) 🌙 Prefer remote stands overnight for configured airfields Feb 25, 2026
@MrAdder MrAdder changed the title 🌙 Prefer remote stands overnight for configured airfields FEAT:🌙 Prefer remote stands overnight for configured airfields Feb 25, 2026
Copy link
Contributor

@kristiankunc kristiankunc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the env config, let!s just enable this out of the box.

Removed env config now enabled out of box
Removed redundant config fields
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More realism in night time stand allocation

4 participants