Skip to content

Push UAV forecast to farmcalendar #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 28, 2025
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.vscode
node_modules
.env
.env.development
.env.*
*.sqlite*
db
__pycache__
Expand All @@ -18,6 +18,7 @@ mypy_report
/data
*.vim
scripts
*.json

# Ignore compiled protobuf files
*_pb2.py
Expand Down
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
- lat: float
- lon: float
- uavmodels: Optional list of UAV models to include in the forecast (eg. Mavic Pro)
- status_filter: Optional list of status conditions to filter results (eg. OK, NOT OK, Marginally OK)
- status_filter: Optional list of status conditions to filter results (eg. OK, NOT OK, MARGINAL)

**Response**
```
Expand Down
5 changes: 3 additions & 2 deletions src/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def __init__(self, *args, **kwargs):
self.setup_routes()
self.setup_openapi()
self.setup_middlewares()
if config.PUSH_THI_TO_FARMCALENDAR:
self.setup_fc_jobs()
self.setup_fc_jobs()


def setup_dao(self):
Expand Down Expand Up @@ -147,7 +146,9 @@ def setup_fc_jobs(self):
async def start_scheduler(app: Application):
app.state.fc_client = FarmCalendarServiceClient(app)
await app.state.fc_client.fetch_and_cache_locations()
await app.state.fc_client.fetch_and_cache_uavs()
await app.state.fc_client.fetch_or_create_thi_activity_type()
await app.state.fc_client.fetch_or_create_flight_forecast_activity_type()

scheduler.start_scheduler(app)

Expand Down
1 change: 1 addition & 0 deletions src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# FARM CALENDAR
PUSH_THI_TO_FARMCALENDAR=os.environ.get('PUSH_THI_TO_FARMCALENDAR', '')
PUSH_FLIGHT_FORECAST_TO_FARMCALENDAR=os.environ.get('PUSH_FLIGHT_FORECAST_TO_FARMCALENDAR')
FARM_CALENDAR_URL = os.environ.get('FARM_CALENDAR_URL', 'http://farmcalendar:8002')

# TASKS
Expand Down
2 changes: 1 addition & 1 deletion src/core/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def find_point(self, lat: float, lon: float) -> Optional[Point]:

# Creates a new Point object with the given latitude and longitude.
# The point is saved to the database and returned.
async def create_point(self, lat: float, lon: float) -> Point:
async def find_or_create_point(self, lat: float, lon: float) -> Point:
point = await self.find_point(lat, lon)
if point:
return point
Expand Down
10 changes: 10 additions & 0 deletions src/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class UAVModelNotFoundError(Exception):
def __init__(self, uav_model: str):
self.message = f"UAV model '{uav_model}' not found"
super().__init__(self.message)


class InvalidWeatherDataError(Exception):
def __init__(self):
self.message = "Invalid weather data received from OpenWeatherMap"
super().__init__(self.message)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from typing import List
from collections import defaultdict
from typing import List

from src import utils
from src.models.point import Point
Expand All @@ -10,7 +10,7 @@

logger = logging.getLogger(__name__)

# TODO: Re-Implement this class using OCSM

class InteroperabilitySchema:

context_schema = [
Expand Down Expand Up @@ -56,7 +56,7 @@ class InteroperabilitySchema:
'@graph': []
}

property_schema = { # TODO add these to data_specifications objects on defaults.json
property_schema = {
'ambient_temperature': {
'measurement': 'Temperature',
'unit': 'qudt:DEG_C',
Expand All @@ -81,7 +81,6 @@ class InteroperabilitySchema:

@classmethod
def weather_data_to_jsonld(cls, wdata: WeatherData, point: Point) -> dict:
property_schema = cls.property_schema
semantic_data = utils.deepcopy_dict(cls.schema)

collection_schema = utils.deepcopy_dict(cls.collection_schema)
Expand Down Expand Up @@ -145,7 +144,8 @@ def predictions_to_jsonld(cls, predictions: List[Prediction], spatial_entity: Po

collection_schema["hasMember"].append(item_schema)
semantic_data['@graph'].append(collection_schema)
except Exception as e:
except Exception as e: # pylint: disable=W0718:broad-exception-caught
logger.exception(e)
else:
return semantic_data

Loading