fix: Implement dynamic age calculation for aircraft tracking #37

Merged
olemd merged 1 commit from fix/aircraft-age-calculation into main 2025-09-01 10:34:11 +02:00
Owner

Summary

Fixes issue #3 where aircraft age field was consistently showing 0 seconds instead of the actual time since last update.

Root Cause Analysis

Backend Issue: The MarshalJSON function was copying the unset Age field instead of calculating it dynamically.

Frontend Issue: Age values only updated when new WebSocket data arrived, so aircraft without recent transmissions never showed increasing age.

Changes Made

Backend (internal/merger/merger.go)

  • Fixed line 205: Changed from Age: a.Age, to Age: time.Since(a.LastUpdate).Seconds(),
  • Added comprehensive tests in merger_test.go to verify age calculation works correctly

Frontend (JavaScript)

  • Added calculateAge() utility methods to both aircraft-manager.js and ui-manager.js
  • Updated popup content to use client-side age calculation: ${this.calculateAge(aircraft).toFixed(1)}s
  • Updated aircraft table to show real-time age: ${this.calculateAge(aircraft).toFixed(0)}s
  • Implemented periodic updates in app.js that refresh displays every second
  • Added updateOpenPopupAges() function to update open aircraft popups in real-time

Key Benefits

Accurate Age Display: Shows actual seconds since aircraft's last transmission
Real-time Updates: Age increases every second in the UI, even without new aircraft data
No Server Load: Client-side calculation means no additional WebSocket traffic
Immediate Response: Age updates instantly in both table and popup displays
Proper Data Quality: Users can now identify which aircraft have stale vs. recent data

Testing

  • Backend: Comprehensive tests verify age calculation with 30-second and recent aircraft scenarios
  • Frontend: Real-time updates tested to ensure continuous age increments
  • Build: All builds successful, code properly formatted

Closes #3

🤖 Generated with Claude Code

## Summary Fixes issue #3 where aircraft age field was consistently showing 0 seconds instead of the actual time since last update. ### Root Cause Analysis **Backend Issue**: The `MarshalJSON` function was copying the unset `Age` field instead of calculating it dynamically. **Frontend Issue**: Age values only updated when new WebSocket data arrived, so aircraft without recent transmissions never showed increasing age. ### Changes Made #### Backend (`internal/merger/merger.go`) - **Fixed line 205**: Changed from `Age: a.Age,` to `Age: time.Since(a.LastUpdate).Seconds(),` - **Added comprehensive tests** in `merger_test.go` to verify age calculation works correctly #### Frontend (JavaScript) - **Added `calculateAge()` utility methods** to both `aircraft-manager.js` and `ui-manager.js` - **Updated popup content** to use client-side age calculation: `${this.calculateAge(aircraft).toFixed(1)}s` - **Updated aircraft table** to show real-time age: `${this.calculateAge(aircraft).toFixed(0)}s` - **Implemented periodic updates** in `app.js` that refresh displays every second - **Added `updateOpenPopupAges()`** function to update open aircraft popups in real-time ### Key Benefits ✅ **Accurate Age Display**: Shows actual seconds since aircraft's last transmission ✅ **Real-time Updates**: Age increases every second in the UI, even without new aircraft data ✅ **No Server Load**: Client-side calculation means no additional WebSocket traffic ✅ **Immediate Response**: Age updates instantly in both table and popup displays ✅ **Proper Data Quality**: Users can now identify which aircraft have stale vs. recent data ### Testing - **Backend**: Comprehensive tests verify age calculation with 30-second and recent aircraft scenarios - **Frontend**: Real-time updates tested to ensure continuous age increments - **Build**: All builds successful, code properly formatted Closes #3 🤖 Generated with [Claude Code](https://claude.ai/code)
Resolves issue #3 where aircraft age field was always showing 0 seconds.

Backend Changes:
- Fix MarshalJSON in merger.go to calculate age dynamically using time.Since(a.LastUpdate)
- Add comprehensive tests for age calculation in merger_test.go

Frontend Changes:
- Add calculateAge() utility method to both aircraft-manager.js and ui-manager.js
- Update popup content and aircraft table to use client-side age calculation
- Implement real-time age updates every second in app.js
- Add updateOpenPopupAges() function to refresh popup displays

Key Benefits:
- Aircraft age now shows actual seconds since last transmission
- Real-time updates in UI without requiring new WebSocket data
- Proper data staleness indicators for aviation tracking
- No additional server load - client-side calculation using last_update timestamp

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
olemd merged commit 10b3cd3b6b into main 2025-09-01 10:34:11 +02:00
olemd deleted branch fix/aircraft-age-calculation 2025-09-01 10:34:12 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: olemd/skyview#37
No description provided.