This commit is contained in:
SpudGunMan
2025-10-28 22:14:34 -07:00
parent fc5476b5dd
commit 0cfe4a39ed
9 changed files with 39 additions and 21 deletions
+1 -11
View File
@@ -175,17 +175,7 @@ def getArtSciRepeaters(lat=0, lon=0):
return msg
def get_NOAAtide(lat=0, lon=0):
# Check if tidepredict (xtide) is enabled
if my_settings.useTidePredict:
try:
from modules import xtide
if xtide.is_enabled():
logger.debug("Location: Using tidepredict for global tide data")
return xtide.get_tide_predictions(lat, lon)
except Exception as e:
logger.warning(f"Location: Failed to use tidepredict, falling back to NOAA: {e}")
# Original NOAA implementation
# get tide data from NOAA for lat/lon
station_id = ""
location = lat,lon
if float(lat) == 0 and float(lon) == 0:
+4
View File
@@ -125,6 +125,10 @@ if coastalEnabled:
from modules.locationdata import * # from the spudgunman/meshing-around repo
trap_list = trap_list + ("mwx","tide",)
help_message = help_message + ", mwx, tide"
if useTidePredict:
from modules import xtide
trap_list = trap_list + ("tide",)
help_message = help_message + ", tide"
# BBS Configuration
if bbs_enabled:
+1 -1
View File
@@ -28,7 +28,7 @@ if os.path.isfile(checkall_path):
# List of module names to exclude
exclude = ['test_bot','udp', 'system', 'log', 'gpio', 'web',]
exclude = ['test_bot','udp', 'system', 'log', 'gpio', 'web','test_xtide',]
available_modules = [
m.name for m in pkgutil.iter_modules([modules_path])
if m.name not in exclude]
+135
View File
@@ -0,0 +1,135 @@
#!/usr/bin/env python3
"""
Test script for xtide module
Tests both NOAA (disabled) and tidepredict (when available) tide predictions
"""
import sys
import os
# Add parent directory to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_xtide_import():
"""Test that xtide module can be imported"""
print("Testing xtide module import...")
try:
from modules import xtide
print(f"✓ xtide module imported successfully")
print(f" - tidepredict available: {xtide.TIDEPREDICT_AVAILABLE}")
return True
except Exception as e:
print(f"✗ Failed to import xtide: {e}")
return False
def test_locationdata_import():
"""Test that modified locationdata can be imported"""
print("\nTesting locationdata module import...")
try:
from modules import locationdata
print(f"✓ locationdata module imported successfully")
return True
except Exception as e:
print(f"✗ Failed to import locationdata: {e}")
return False
def test_settings():
"""Test that settings has useTidePredict option"""
print("\nTesting settings configuration...")
try:
from modules import settings as my_settings
has_setting = hasattr(my_settings, 'useTidePredict')
print(f"✓ settings module loaded")
print(f" - useTidePredict setting available: {has_setting}")
if has_setting:
print(f" - useTidePredict value: {my_settings.useTidePredict}")
return True
except Exception as e:
print(f"✗ Failed to load settings: {e}")
return False
def test_noaa_fallback():
"""Test NOAA API fallback (without enabling tidepredict)"""
print("\nTesting NOAA API (default mode)...")
try:
from modules import locationdata
from modules import settings as my_settings
# Test with Seattle coordinates (should use NOAA)
lat = 47.6062
lon = -122.3321
print(f" Testing with Seattle coordinates: {lat}, {lon}")
print(f" useTidePredict = {my_settings.useTidePredict}")
# Note: This will fail if we can't reach NOAA, but that's expected
result = locationdata.get_NOAAtide(str(lat), str(lon))
if result and "Error" not in result:
print(f"✓ NOAA API returned data")
print(f" First 100 chars: {result[:100]}")
return True
else:
print(f"⚠ NOAA API returned: {result[:100]}")
return True # Still pass as network might not be available
except Exception as e:
print(f"⚠ NOAA test encountered expected issue: {e}")
return True # Expected in test environment
def test_parse_coords():
"""Test coordinate parsing function"""
print("\nTesting coordinate parsing...")
try:
from modules.xtide import parse_station_coords
test_cases = [
(("43-36S", "172-43E"), (-43.6, 172.71666666666667)),
(("02-45N", "072-21E"), (2.75, 72.35)),
(("02-45S", "072-21W"), (-2.75, -72.35)),
]
all_passed = True
for (lat_str, lon_str), (expected_lat, expected_lon) in test_cases:
result_lat, result_lon = parse_station_coords(lat_str, lon_str)
if abs(result_lat - expected_lat) < 0.01 and abs(result_lon - expected_lon) < 0.01:
print(f"{lat_str}, {lon_str} -> {result_lat:.2f}, {result_lon:.2f}")
else:
print(f"{lat_str}, {lon_str} -> expected {expected_lat}, {expected_lon}, got {result_lat}, {result_lon}")
all_passed = False
return all_passed
except Exception as e:
print(f"✗ Coordinate parsing test failed: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests"""
print("=" * 60)
print("xtide Module Test Suite")
print("=" * 60)
results = []
results.append(("Import xtide", test_xtide_import()))
results.append(("Import locationdata", test_locationdata_import()))
results.append(("Settings configuration", test_settings()))
results.append(("Parse coordinates", test_parse_coords()))
results.append(("NOAA fallback", test_noaa_fallback()))
print("\n" + "=" * 60)
print("Test Results Summary")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "✓ PASS" if result else "✗ FAIL"
print(f"{status}: {test_name}")
print(f"\n{passed}/{total} tests passed")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
+12
View File
@@ -94,6 +94,18 @@ The module couldn't find a nearby station. This may happen if:
- The station database hasn't been initialized
- Network issues prevented loading the station list
Tide Station Map
[https://uhslc.soest.hawaii.edu/network/](https://uhslc.soest.hawaii.edu/network/)
- click on Tide Guages
- Find yourself on the map
- Locate the closest Gauge and its name (typically the city name)
To manually download data for the station first location the needed station id
- `python -m tidepredict -l "Port Angeles"` finds a station
- `python -m tidepredict -l "Port Angeles" -genharm` downloads that datafile
## Data Source
Tide predictions are based on harmonic analysis of historical tide data from:
+3 -3
View File
@@ -13,7 +13,7 @@ try:
TIDEPREDICT_AVAILABLE = True
except ImportError:
TIDEPREDICT_AVAILABLE = False
logger.warning("xtide: tidepredict module not installed. Install with: pip install tidepredict")
logger.error("xtide: tidepredict module not installed. Install with: pip install tidepredict")
def get_nearest_station(lat, lon):
"""
@@ -114,7 +114,7 @@ def get_tide_predictions(lat=0, lon=0, days=1):
- Formatted string with tide predictions or error message
"""
if not TIDEPREDICT_AVAILABLE:
return "tidepredict library not installed"
return "module not installed, see logs for more ⚓️"
if float(lat) == 0 and float(lon) == 0:
return "No GPS data for tide prediction"
@@ -132,7 +132,7 @@ def get_tide_predictions(lat=0, lon=0, days=1):
# Check if harmonic data exists for this station
if station_code not in station_dict:
logger.warning(f"xtide: No harmonic data for {station_name}.")
logger.warning(f"xtide: No harmonic data. python -m tidepredict -l \"{station_name}\" -genharm")
return f"Tide data not available for {station_name}. Station database may need initialization."
# Reconstruct tide model