fix: Add missing field removals for dao, itemname, and coordinate conversion
Production logs showed additional fields causing insertion failures: - dao: DAO extension data - itemname: Item name field - longitude/latitude: Parser uses these but our schema uses lon/lat Added conversion step to map latitude->lat and longitude->lon before processing. This ensures packets can be properly saved to the database. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
584402274c
commit
b63c3c547d
1 changed files with 27 additions and 0 deletions
|
|
@ -308,6 +308,7 @@ defmodule Aprsme.PacketConsumer do
|
|||
|
||||
# Apply the same processing as the original store_packet function
|
||||
attrs
|
||||
|> convert_coordinate_field_names()
|
||||
|> normalize_packet_attrs()
|
||||
|> set_received_at()
|
||||
|> patch_lat_lon_from_data_extended()
|
||||
|
|
@ -383,6 +384,15 @@ defmodule Aprsme.PacketConsumer do
|
|||
|> Map.delete("gpsfixstatus")
|
||||
|> Map.delete(:raw_weather_data)
|
||||
|> Map.delete("raw_weather_data")
|
||||
# Additional fields found in production logs
|
||||
|> Map.delete(:dao)
|
||||
|> Map.delete("dao")
|
||||
|> Map.delete(:longitude)
|
||||
|> Map.delete("longitude")
|
||||
|> Map.delete(:latitude)
|
||||
|> Map.delete("latitude")
|
||||
|> Map.delete(:itemname)
|
||||
|> Map.delete("itemname")
|
||||
end
|
||||
|
||||
# Helper functions for coordinate validation and point creation
|
||||
|
|
@ -414,6 +424,23 @@ defmodule Aprsme.PacketConsumer do
|
|||
defp valid_packet?(%{sender: sender}) when is_binary(sender) and byte_size(sender) > 0, do: true
|
||||
defp valid_packet?(_), do: false
|
||||
|
||||
# Convert latitude/longitude to lat/lon if present at top level
|
||||
defp convert_coordinate_field_names(attrs) do
|
||||
attrs
|
||||
|> then(fn a ->
|
||||
case Map.get(a, :latitude) do
|
||||
nil -> a
|
||||
lat -> a |> Map.put(:lat, lat) |> Map.delete(:latitude)
|
||||
end
|
||||
end)
|
||||
|> then(fn a ->
|
||||
case Map.get(a, :longitude) do
|
||||
nil -> a
|
||||
lon -> a |> Map.put(:lon, lon) |> Map.delete(:longitude)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
# Helper functions copied from Packets module for consistency
|
||||
defp normalize_packet_attrs(attrs) do
|
||||
attrs
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue