1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-08-12 02:02:31 -04:00

Include haversine library

This patch changes the geopy to haversine library for logging
packet distances.  haversine is quite a bit lighter than geopy.
This commit is contained in:
Hemna 2024-12-10 17:59:11 -05:00
parent 3bba8a19da
commit bbdbb9aba1
4 changed files with 7 additions and 6 deletions

View File

@ -12,7 +12,7 @@ from dataclasses_json import (
) )
from loguru import logger from loguru import logger
from aprsd.utils import counter, trace from aprsd.utils import counter
# For mypy to be happy # For mypy to be happy
@ -129,7 +129,6 @@ class Packet:
msg = self._filter_for_send(self.raw).rstrip("\n") msg = self._filter_for_send(self.raw).rstrip("\n")
return msg return msg
@trace.trace
def prepare(self, create_msg_number=False) -> None: def prepare(self, create_msg_number=False) -> None:
"""Do stuff here that is needed prior to sending over the air.""" """Do stuff here that is needed prior to sending over the air."""
# now build the raw message for sending # now build the raw message for sending

View File

@ -1,7 +1,7 @@
import logging import logging
from typing import Optional from typing import Optional
from geopy.distance import geodesic from haversine import Unit, haversine
from loguru import logger from loguru import logger
from oslo_config import cfg from oslo_config import cfg
@ -145,8 +145,8 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
# is there distance information? # is there distance information?
if isinstance(packet, GPSPacket) and CONF.latitude and CONF.longitude: if isinstance(packet, GPSPacket) and CONF.latitude and CONF.longitude:
my_coords = (CONF.latitude, CONF.longitude) my_coords = (float(CONF.latitude), float(CONF.longitude))
packet_coords = (packet.latitude, packet.longitude) packet_coords = (float(packet.latitude), float(packet.longitude))
try: try:
bearing = utils.calculate_initial_compass_bearing(my_coords, packet_coords) bearing = utils.calculate_initial_compass_bearing(my_coords, packet_coords)
except Exception as e: except Exception as e:
@ -154,7 +154,7 @@ def log(packet, tx: Optional[bool] = False, header: Optional[bool] = True) -> No
bearing = 0 bearing = 0
logit.append( logit.append(
f" : <{DEGREES_COLOR}>{utils.degrees_to_cardinal(bearing, full_string=True)}</{DEGREES_COLOR}>" f" : <{DEGREES_COLOR}>{utils.degrees_to_cardinal(bearing, full_string=True)}</{DEGREES_COLOR}>"
f"<{DISTANCE_COLOR}>@{geodesic(my_coords, packet_coords).miles:.2f}miles</{DISTANCE_COLOR}>", f"<{DISTANCE_COLOR}>@{haversine(my_coords, packet_coords, unit=Unit.MILES):.2f}miles</{DISTANCE_COLOR}>",
) )
LOGU.opt(colors=True).info(" ".join(logit)) LOGU.opt(colors=True).info(" ".join(logit))

View File

@ -3,6 +3,7 @@ aprslib>=0.7.0
beautifulsoup4 beautifulsoup4
click click
dataclasses-json dataclasses-json
haversine
kiss3 kiss3
loguru loguru
oslo.config oslo.config

View File

@ -15,6 +15,7 @@ click==8.1.7 # via -r requirements.in
commonmark==0.9.1 # via rich commonmark==0.9.1 # via rich
dataclasses-json==0.6.7 # via -r requirements.in dataclasses-json==0.6.7 # via -r requirements.in
debtcollector==3.0.0 # via oslo-config debtcollector==3.0.0 # via oslo-config
haversine==2.9.0 # via -r requirements.in
idna==3.10 # via requests idna==3.10 # via requests
importlib-metadata==8.5.0 # via ax253, kiss3 importlib-metadata==8.5.0 # via ax253, kiss3
kiss3==8.0.0 # via -r requirements.in kiss3==8.0.0 # via -r requirements.in