Skip to content

Commit a1f00c0

Browse files
authored
Post all measurement types in ocsm (#53)
* Post all measurement types in ocsm * Use oa ads variable for internal routing * Strip trailist '/' in urls
1 parent 4c82f38 commit a1f00c0

5 files changed

Lines changed: 20 additions & 17 deletions

File tree

.env.example

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ JWT_SIGNING_KEY=c2bab29d257f0ffc52d9ac677d4ff6d1d9d5e92e3d3939d3f4cwc
2020
JWT_ALG=HS256
2121
JWT_CRYPT_CONTEXT_SCHEME=bcrypt
2222

23-
# FARM CALENDAR
23+
# FARM CALENDAR JOBS
2424
PUSH_THI_TO_FARMCALENDAR=True
25-
FARM_CALENDAR_URL=http://farmcalendar:8002
26-
27-
# TASKS
25+
PUSH_FF_TO_FARMCALENDAR=
26+
PUSH_SPRAY_F_TO_FARMCALENDAR=
2827
INTERVAL_THI_TO_FARMCALENDAR=8
28+
29+
# OA ADS ROUTING
30+
GATEKEEPER_URL=
31+
GATEKEEPER_FARM_CALENDAR_API=

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ services:
2929
WEATHER_SRV_GATEKEEPER_PASSWORD: ${GATEKEEPER_SUPERUSER_PASSWORD}
3030
# FARM CALENDAR
3131
PUSH_THI_TO_FARMCALENDAR: ${PUSH_THI_TO_FARMCALENDAR}
32-
FARM_CALENDAR_URL: ${FARM_CALENDAR_URL}
32+
GATEKEEPER_FARM_CALENDAR_API: ${GATEKEEPER_FARM_CALENDAR_API}
3333
INTERVAL_THI_TO_FARMCALENDAR: ${INTERVAL_THI_TO_FARMCALENDAR}
3434
volumes:
3535
- ./data:/data:rw

src/core/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
EXTRA_ALLOWED_HOSTS = os.environ.get('EXTRA_ALLOWED_HOSTS', "*").replace(' ', '').split(',')
2121

2222
# GATEKEEPER
23-
GATEKEEPER_URL = os.environ.get('GATEKEEPER_URL', '')
23+
GATEKEEPER_URL = os.environ.get('GATEKEEPER_URL', '').rstrip('/')
2424
WEATHER_SRV_GATEKEEPER_USER = os.environ.get('WEATHER_SRV_GATEKEEPER_USER', '')
2525
WEATHER_SRV_GATEKEEPER_PASSWORD = os.environ.get('WEATHER_SRV_GATEKEEPER_PASSWORD', '')
2626

@@ -31,7 +31,7 @@
3131
PUSH_THI_TO_FARMCALENDAR=os.environ.get('PUSH_THI_TO_FARMCALENDAR', '')
3232
PUSH_FLIGHT_FORECAST_TO_FARMCALENDAR=os.environ.get('PUSH_FLIGHT_FORECAST_TO_FARMCALENDAR', '')
3333
PUSH_SPRAY_F_TO_FARMCALENDAR=os.environ.get('PUSH_SPRAY_F_TO_FARMCALENDAR', '')
34-
FARM_CALENDAR_URL = os.environ.get('FARM_CALENDAR_URL', 'http://farmcalendar:8002')
34+
GATEKEEPER_FARM_CALENDAR_API = os.environ.get('GATEKEEPER_FARM_CALENDAR_API', 'http://farmcalendar:8002/api/v1/').rstrip('/')
3535

3636
# TASKS
3737
INTERVAL_THI_TO_FARMCALENDAR = os.environ.get('INTERVAL_HOURS_THI_TO_FARMCALENDAR', 8)

src/external_services/interoperability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class InteroperabilitySchema:
3939
"numericValue": 22.53,
4040
"unit": "qudt:DEG_C"
4141
}
42-
}
42+
}
4343

4444
collection_schema = {
4545
'@id': "",
@@ -162,7 +162,7 @@ def predictions_to_jsonld(cls, predictions: List[Prediction], spatial_entity: Po
162162
"unit": property_schema[p.measurement_type]["unit"]
163163
}
164164

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

src/services/farmcalendar_service.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class FarmCalendarServiceClient(MicroserviceClient):
2222

2323
def __init__(self, app: FastAPI):
24-
super().__init__(base_url=config.FARM_CALENDAR_URL, service_name="Farm Calendar", app=app)
24+
super().__init__(base_url=config.GATEKEEPER_FARM_CALENDAR_API, service_name="Farm Calendar", app=app)
2525

2626
@backoff.on_exception(
2727
backoff.expo,
@@ -32,14 +32,14 @@ def __init__(self, app: FastAPI):
3232
max_tries=3
3333
)
3434
async def fetch_or_create_activity_type(self, activity_type: str, description: str) -> str:
35-
act_jsonld = await self.get(f'/api/v1/FarmCalendarActivityTypes/?name={activity_type}')
35+
act_jsonld = await self.get(f'/FarmCalendarActivityTypes/?name={activity_type}')
3636

3737
if not self._get_activity_type_id(act_jsonld):
3838
json_payload = {
3939
"name": activity_type,
4040
"description": description,
4141
}
42-
act_jsonld = await self.post('/api/v1/FarmCalendarActivityTypes/', json=json_payload)
42+
act_jsonld = await self.post('/FarmCalendarActivityTypes/', json=json_payload)
4343

4444
return self._get_activity_type_id(act_jsonld)
4545

@@ -78,7 +78,7 @@ def _get_activity_type_id(self, jsonld: dict) -> Optional[str]:
7878
max_tries=3
7979
)
8080
async def fetch_locations(self):
81-
response = await self.get('/api/v1/FarmParcels/')
81+
response = await self.get('/FarmParcels/')
8282

8383
locations = []
8484
for parcel in response.get("@graph", []):
@@ -116,7 +116,7 @@ async def fetch_and_cache_locations(self):
116116
max_tries=3
117117
)
118118
async def fetch_uavs(self):
119-
response = await self.get(f'/api/v1/AgriculturalMachines/')
119+
response = await self.get(f'/AgriculturalMachines/')
120120
uavmodels = [ uav.get("model") for uav in response.get("@graph", []) if uav.get("model", None)]
121121
return uavmodels
122122

@@ -155,7 +155,7 @@ async def send_thi(self, lat, lon):
155155
)
156156
json_payload = observation.model_dump(by_alias=True, exclude_none=True)
157157
logger.debug(json_payload)
158-
await self.post('/api/v1/Observations/', json=json_payload)
158+
await self.post('/Observations/', json=json_payload)
159159

160160
# Async function to post Flight Forecast data with JWT authentication
161161
@backoff.on_exception(
@@ -189,7 +189,7 @@ async def send_flight_forecast(self, lat, lon, uavmodels):
189189
)
190190
json_payload = observation.model_dump(by_alias=True, exclude_none=True)
191191
logger.debug(json_payload)
192-
await self.post('/api/v1/Observations/', json=json_payload)
192+
await self.post('/Observations/', json=json_payload)
193193

194194
# Async function to post spray conditions Forecast data with JWT authentication
195195
@backoff.on_exception(
@@ -224,4 +224,4 @@ async def send_spray_forecast(self, lat, lon):
224224

225225
json_payload = observation.model_dump(by_alias=True, exclude_none=True)
226226
logger.debug(json_payload)
227-
await self.post('/api/v1/Observations/', json=json_payload)
227+
await self.post('/Observations/', json=json_payload)

0 commit comments

Comments
 (0)