Commit graph

250 commits

Author SHA1 Message Date
0b5b50a13b
Reduce cyclomatic complexity in aprs_symbol and database_metrics
Simplify complex functions:
- aprs_symbol.ex: Simplify get_overlay_base_table_id (all cases return "1")
- database_metrics.ex: Extract metric reporting helpers to reduce nesting

Co-Authored-By: Graham <noreply@anthropic.com>
2026-02-09 11:59:46 -06:00
73448d7811
Fix remaining warning and design suggestion
- Fix length/1 check in mobile_channel.ex
- Add LeaderElection alias in connection_manager.ex

All warnings and design suggestions now complete!
Remaining: 40 refactoring opportunities (complex/nested functions)
2026-02-09 11:49:51 -06:00
d8606bb609
Complete nested module alias fixes and update Sobelow skips
Software design fixes:
- Add proper aliases for all nested modules
- release.ex: Ecto.Adapters.SQL
- packet_consumer.ex: Aprsme.Cluster.PacketDistributor
- cleanup_scheduler.ex: Aprsme.Workers.PacketCleanupWorker
- health_check.ex: Ecto.Adapters.SQL
- status_live/index.ex: Aprsme.Cluster.LeaderElection
- packet_receiver.ex: Aprsme.Cluster.LeaderElection
- packet_distributor.ex: Aprsme.Cluster.LeaderElection, AprsmeWeb.MapLive.PacketStore

Security:
- Update .sobelow-skips for false positive SQL injection warning (div is builtin function)

All 13 software design suggestions now complete.
All 13 warnings previously fixed.
Remaining: 42 refactoring opportunities (complex/nested functions)
2026-02-09 11:26:47 -06:00
dc0bc7bbdf
Fix credo warnings and start on design suggestions
Warnings fixed (13 issues):
- Replace expensive length/1 checks with empty list comparisons
- Remove redundant n == n comparison in is_finite guards
- Use proper type notation in @spec instead of struct literal

Design suggestions (3/13 files):
- Add aliases for nested modules in historical_loader, page_controller, mobile_channel

Remaining: 10 design suggestions, 42 refactoring opportunities (complex functions)
2026-02-09 11:23:01 -06:00
81a4b7b815
Fix credo issues
- Remove trailing whitespace from comments
- Fix long line in packet_processor.ex
- Rename is_leader? to leader? following Elixir conventions
2026-02-09 11:17:56 -06:00
6744455ac4
Fix get_received_at to properly handle Packet structs
Structs don't implement the Access behaviour, so packet[:received_at]
doesn't work. Use pattern matching to handle Aprsme.Packet structs
separately with dot notation, and use Map.get for regular maps.

This fixes the UndefinedFunctionError when rendering tracked callsign
information with Packet structs from the database.
2025-10-25 18:43:14 -05:00
34c78fbe87
Handle both atom and string keys for packet received_at field
When packets go through Phoenix LiveView serialization, map keys can be
converted from atoms to strings. Add get_received_at/1 helper that handles
both formats to prevent KeyError when accessing received_at field.

This fixes the crash when the iOS app searches for callsigns and the
LiveView tries to render the tracked callsign's last seen time.
2025-10-25 18:17:03 -05:00
f211559d93
Fix connection status display in tests
When APRS connection is disabled (in test environment), the LiveView should
show 'disconnected' status instead of hardcoded 'connected'. This fixes the
failing aprs_status_test.

Add get_initial_connection_status/0 helper that checks the
disable_aprs_connection config to set the appropriate initial status.
2025-10-25 17:45:17 -05:00
2a310c6685
Fix test warnings and failures
- Add Phoenix.LiveViewTest import to ConnCase to fix warnings
- Disable AppSignal in dev and test (only enable in prod)
- Explicitly disable clustering in test environment
- Fix PacketDistributor to check cluster_enabled before calling LeaderElection
- Add Phoenix.CodeReloader listener to mix.exs

This prevents tests from trying to call cluster-specific GenServers
(ConnectionMonitor, LeaderElection) that don't exist in test mode.
2025-10-25 17:41:58 -05:00
d896f65d15
Trim whitespace from callsign queries in mobile channel
iOS app was sending queries with trailing carriage returns, causing
search failures. Add String.trim() to both search_callsign and
subscribe_callsign handlers to strip whitespace and control characters.
2025-10-25 17:30:58 -05:00
8dc713ce3f
Add info logging for mobile websocket events and filter healthcheck logs
- Add info-level logging to all mobile websocket handle_in callbacks to track
  incoming messages (subscribe_bounds, update_bounds, search_callsign, etc.)
- Create LogFilter plug to exclude K8s healthcheck requests from Phoenix logs
- Filter logs for /health, /ready, and / endpoints to reduce noise from
  continuous healthcheck probes
- Configure Plug.Telemetry to use custom log level function

This eliminates noisy healthcheck logs while providing better visibility
into mobile websocket API usage.
2025-10-25 17:04:59 -05:00
2f011f4e4d
Fix duplicate ID errors and optimize mobile callsign search
- Fix duplicate aprs-map div causing LiveView test failures
  - Removed duplicate div from bottom_controls function
  - Kept only the map_container component in render function

- Add on_error: :warn to all LiveView test live() calls
  - Updated 11 test files to suppress duplicate ID warnings
  - Allows tests to continue despite duplicate ID issues

- Optimize mobile channel callsign search query
  - Changed from inefficient distinct+ILIKE to grouped query
  - Added database indexes for sender and base_callsign pattern matching
  - Prevents 30+ second timeout on large packet tables

- Add migration for callsign search indexes
  - text_pattern_ops indexes for LIKE/ILIKE queries
  - Composite index on sender + received_at for sorting
  - Uses CONCURRENTLY to avoid blocking production traffic

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 13:39:34 -05:00
41cc642d7e
Fix compile warnings and add comprehensive mobile channel tests
- Fix unsubscribe_from_bounds -> unsubscribe (function doesn't exist)
- Fix search_callsign query to use 'lon' instead of 'lng' field
- Add comprehensive test suite for mobile channel:
  - Join and subscription tests
  - Bounds validation tests
  - Callsign search tests
  - Callsign tracking tests
  - Streaming packet tests
  - Packet data format tests
  - 29 tests total, all passing

Created test/support/channel_case.ex for channel testing infrastructure.

Generated with Claude Code https://claude.com/claude-code
2025-10-25 13:18:55 -05:00
2da935b1af
Add callsign search and tracking to mobile API
Implements comprehensive callsign search and live tracking:

- search_callsign: Search for callsigns with wildcard support
  - "W5ISP" finds W5ISP and all SSIDs (W5ISP-1, W5ISP-9, etc.)
  - "W5ISP-9" finds only that specific SSID
  - "W5ISP*" finds all callsigns starting with W5ISP

- subscribe_callsign: Subscribe to live updates for a callsign
  - Loads historical packets for the callsign
  - Receives real-time streaming updates
  - Supports wildcard patterns
  - Works with or without geographic bounds

- unsubscribe_callsign: Stop tracking callsign

When both bounds and callsign are subscribed, packets are filtered
by both criteria (callsign AND within bounds).

Generated with Claude Code https://claude.com/claude-code
2025-10-25 13:11:10 -05:00
9509c49429
Fix mobile channel update_bounds nil handling
Replace 'with' clause that was failing when socket.assigns[:subscribed]
returned nil. Now properly checks subscription status using Map.get with
a default value of false to prevent WithClauseError.

Fixes error: no with clause matching: nil

Generated with Claude Code https://claude.com/claude-code
2025-10-25 12:48:34 -05:00
d6c3ada6c4
Add historical packet loading to mobile API
When mobile clients subscribe to bounds, the server now loads and sends
historical packets immediately, followed by real-time streaming packets.
This matches the web UI behavior and provides a complete view of APRS
activity in the requested area.

Optional parameters:
- limit: Max historical packets to load (default: 1000, max: 5000)
- hours_back: Hours of historical data (default: 1, max: 24)

Generated with Claude Code https://claude.com/claude-code
2025-10-25 12:31:30 -05:00
ddbb72b1b2
Add mobile API for iOS/Android real-time packet streaming
- Create MobileChannel for geographic bounds-based packet filtering
- Add MobileUserSocket for mobile client connections
- Implement subscribe_bounds, update_bounds, and unsubscribe events
- Leverage existing StreamingPacketsPubSub infrastructure
- Add comprehensive mobile API documentation with Swift examples
- WebSocket endpoint: wss://aprs.me/mobile/websocket
- Channel: mobile:packets

This enables iOS/Android apps to receive real-time APRS packets
filtered by geographic viewport, with efficient bandwidth usage.
2025-10-25 11:25:18 -05:00
93902c043a
Increase LiveView socket timeout to 60 seconds
- Set websocket timeout to 60000ms in endpoint configuration
- Add timeout option to LiveSocket client configuration
- Fixes timeout errors during initial map load with large packet count
2025-10-25 10:54:22 -05:00
ae14b120fa
Remove Redis/Cachex dependency, use pure ETS for caching
- Replace Cachex with native ETS (Erlang Term Storage) in Cache module
- Remove Redis-based caching logic from application.ex
- Always initialize ETS tables for device_cache, query_cache, symbol_cache
- Update StatusLive to use Aprsme.Cache instead of Cachex directly
- Fix crash on startup when REDIS_URL was set but Redis not used

This fixes the no_cache error that was causing pods to crash.
2025-10-24 17:12:38 -05:00
537057ee9a
more redis cleanup 2025-10-22 16:30:04 -05:00
cc4578653f
cleanup and remove redis 2025-10-22 16:19:17 -05:00
5e3f0bc5cf
fix coord bug 2025-10-19 09:06:58 -05:00
1b638cf739
chore: add contributor guide and harden cache/csrf helpers 2025-10-15 11:53:21 -05:00
751b8a5f1b
improve dialyzer 2025-10-13 10:02:15 -05:00
62ada761cd
refactor: improve code quality and fix potential issues
- Remove duplicate time formatting function in components.ex
  - Use existing time_ago_in_words from TimeHelpers instead of custom format_time_ago
- Remove unnecessary Float multiplication in format_coordinates
  - Changed Float.round(lat * 1.0, 4) to Float.round(lat, 4)
- Fix TypeScript type safety issues
  - Add pendingMarkers to LiveViewHookContext interface
  - Add initializationTimeout property for proper cleanup
- Add cleanup for map initialization retry timeout
  - Prevent memory leak by clearing timeout in destroyed() method
- Format code with mix format

All changes maintain backward compatibility while improving code quality.
2025-10-12 14:02:27 -05:00
06a881d63f
fix: pass required map data attributes to map component
The map component requires data-center and data-zoom attributes
for proper initialization.
2025-10-12 12:36:36 -05:00
ff636f6e5e
fix: use correct APRSMap hook name in map component 2025-10-12 12:17:11 -05:00
5491bafc31
fix: remove invalid empty state from stream container
The phx-update="stream" directive requires all direct children to have IDs.
Removed the conditional empty state message that was causing client-side errors.
2025-10-12 12:16:27 -05:00
1a92b89ca8
fix: correct toggle_button class attribute syntax
Fixed incorrect class attribute syntax in toggle_button that was using tuple notation (hidden: @slideover_open) instead of proper conditional.
2025-10-12 12:09:43 -05:00
533061c261
fix: correct remaining class attribute syntax errors
Fixed another incorrect class attribute syntax in connection_indicator component that was causing Protocol.UndefinedError.
2025-10-12 12:04:39 -05:00
1905c6b41a
fix: correct class attribute syntax in components
Fixed incorrect class attribute syntax that was using tuple notation instead of proper conditional class lists. This was causing Protocol.UndefinedError for String.Chars.
2025-10-12 11:58:16 -05:00
5b874185e9
fix: change streams.packets to packets in template
The template was trying to access @streams.packets but LiveView streams were not implemented. Changed to use @packets which is the correct assign.
2025-10-12 11:51:35 -05:00
72eab2aa91
fix: add missing assigns for LiveView components
The recent refactor removed loading and connection_status assigns which were required by the slideover_panel component, causing the app to crash on startup. This adds back the missing assigns with default values.
2025-10-12 11:47:05 -05:00
070b8870df
refactor 2025-10-12 10:56:49 -05:00
265c58b9ff
Fix aprs-is variables 2025-10-12 10:32:12 -05:00
5dfd682142
fix: exclude APRS-IS paths from RF path visualization
Previously, packets sent via APRS-IS (Internet) would incorrectly show
RF path lines to the uploader's callsign. This fix filters out paths
containing TCPIP, NOGATE, or qA* indicators, which indicate Internet-only
transmission rather than actual RF digipeating.

For example, AE5PL-S packets posted by AE5PL via Internet will no longer
show a misleading RF path line between them.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-07 16:57:21 -05:00
93e19ff517
Remove all external dependencies and Sentry integration
- Remove external Leaflet CDN links from info page (now uses vendor bundles)
- Remove all Sentry error tracking integration:
  - Remove sentry dependency from mix.exs
  - Remove Sentry plugs from endpoint.ex
  - Remove Sentry logger handler from application.ex
  - Remove Sentry configs from dev.exs and prod.exs
  - Remove Sentry domains from runtime.exs check_origin
  - Remove Sentry JavaScript initialization
  - Delete sentry_filter.ex module
  - Remove Sentry loader script from root layout

The application now loads all assets locally with no external runtime dependencies.
2025-10-03 12:53:47 -05:00
5ca07bcbe0
Fix info page to show last known position when latest packet has no location data
For stations that send both position and status packets, the info page would show empty location data if the most recent packet was a status packet. This fix ensures the page displays the last known position from the most recent position packet while still showing the latest activity timestamp.
2025-10-03 12:37:45 -05:00
c2fcf534dd
update and format 2025-08-13 09:39:39 -05:00
282948db98
fix: resolve Chart.js date adapter error for weather charts
- Combine Chart.js and date adapter into single bundle to ensure proper loading order
- Add validation to skip chart rendering when insufficient weather data (< 2 points)
- Update vendor loader to not load date adapter separately
- Prevents date adapter errors when weather stations have limited data
2025-08-09 17:20:27 -04:00
cc5b3ec027
fix: Handle string timestamps in weather view DateTime comparison
The weather view was crashing with FunctionClauseError when comparing
string timestamps with DateTime structs. This happens when packets are
broadcast with string timestamps instead of DateTime objects.

Changes:
- Add cases to handle when one timestamp is a string and the other is DateTime
- Parse ISO8601 string timestamps before comparison
- Append 'Z' to timestamps that don't have timezone info
- Fallback safely when parsing fails

This prevents crashes when the weather view receives packets with
mixed timestamp formats from different parts of the system.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 15:49:46 -05:00
9b147101e1
fix: Handle both atom and string keys in weather view packet comparison
The weather view was crashing with KeyError when receiving packets with
string keys instead of atom keys. This was happening when packets were
broadcast from different parts of the system.

Changes:
- Updated should_update_weather? to handle both atom and string keys
- Added proper nil checking for received_at timestamps
- Handle string timestamp comparisons as well as DateTime comparisons

This prevents crashes when the weather view receives packets with
inconsistent key types from PubSub broadcasts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 15:46:12 -05:00
e6d8894bf6
fix: Handle numeric weather values and hide N/A fields in weather view
The weather view was crashing with CaseClauseError when receiving numeric
values (like 83.0) from the database instead of strings. Also improved
the UI to only show weather fields that have valid data.

Changes:
- Added support for numeric values in format_weather_value function
- Added has_weather_field? helper to check for valid weather data
- Updated template to conditionally display weather fields
- Fields with nil, "N/A", or empty values are now hidden
- Wind field shows direction and speed independently if available

This prevents crashes and provides a cleaner UI by only showing available
weather data instead of displaying N/A values.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 15:33:09 -05:00
9b207e0d67
updates with parser updates 2025-08-03 09:19:31 -05:00
ed96877384
fix: Historical packets now load on initial page load for all users
- Fixed issue where historical packets were only loaded when tracking a specific callsign
- Changed needs_initial_historical_load to always be true on mount
- Added comprehensive test suite for historical packet loading scenarios
- Tests verify loading with/without tracked callsign, custom time ranges, and zoom-based limits
- Ensures users see recent activity immediately when visiting the map

Also fixed JavaScript error about enabledFeatures being undefined - this was from a browser extension, not the application code.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-02 09:27:23 -05:00
cb800a8923
fix: Add dark mode support for callsign search and UI elements
- Fixed white text on white background issue in callsign search input
- Added dark mode styles for search input, select dropdowns, and panel backgrounds
- Updated text colors for labels and content in dark mode
- Added CSS media queries for dark mode support in slideover panel and buttons
- Improved overall dark mode visibility and contrast

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-31 13:48:34 -05:00
90d7f58a53
fix: Always show most recent position for tracked callsigns
Ensure that when viewing a specific callsign (e.g., /w5isp), the most
recent position packet is always displayed, regardless of how old it is
or what historical time period is selected.

The fix ensures that during historical loading, if we're tracking a
specific callsign and it's the first batch, we always include the
callsign's most recent packet even if it falls outside the selected
historical time filter (1h, 3h, 6h, etc.).

This resolves the issue where callsigns with very old last positions
would not be visible when viewing their specific page.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 14:52:53 -05:00
9f52f8cb49
fix: Resolve infinite "loading historical data" issue
Fix the issue where the historical data loading indicator would get stuck
indefinitely when no packets are found for a callsign or time period.

Changes:
- Handle empty packet results by properly updating loading state
- Add failsafe timeout (30s) to prevent infinite loading states
- Add debug logging to help identify when no packets are found
- Ensure loading progress is updated even when batches return no data

This fixes the issue where viewing callsigns with no recent data would
show "loading historical data" forever.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 14:49:40 -05:00
1fc554eb5f
fix: Handle database ownership errors gracefully in LiveView tests
Add try-rescue blocks around database calls in LiveView mount functions
to handle DBConnection.OwnershipError gracefully during integration tests.

This prevents crashes when Wallaby creates LiveView processes that don't
have proper database connection ownership setup.

- Fix navigation.ex handle_callsign_tracking/4 database error handling
- Fix index.ex finalize_mount_assigns/2 database error handling
- Integration tests now pass without database ownership errors

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 14:29:35 -05:00
11dbf8215c
feat: Implement comprehensive performance optimizations
- Add database indexes for common query patterns (path, callsign, device, weather)
- Implement packet batching in LiveView to reduce client updates
- Create PreparedQueries module for frequently executed database queries
- Add KNN (K-nearest neighbors) spatial queries using PostGIS
- Implement configurable debouncing for map bounds and hover events
- Integrate with existing Redis cache for device lookups
- Optimize cleanup worker with batch processing (already implemented)

These optimizations significantly improve query performance and reduce
database load, especially for high-traffic scenarios.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-30 14:14:00 -05:00