Commit 34a64d24 authored by Timm Schoening's avatar Timm Schoening
Browse files

foo

parent a5da5d52
......@@ -9,10 +9,30 @@ import json
import yaml
import datetime
# TODO: iFDO Connector
def uploadiFDOToUnderway(ifdo_path:str,platform:str,user:str,api_url:str = miqtv.apis['osis_underway']):
""" Takes an iFDO and send its image coordinates the OSIS underway database
Does no sanity checks at all. Currently only works for images."""
positions = miqtg.Positions()
events = {}
with open(ifdo_path,"r") as ifdo_file:
ifdo = yaml.safe_load(ifdo_file)
for img in ifdo['image-set-items']:
item = ifdo['image-set-items'][img]
utc = int(datetime.datetime.strptime(item['image-datetime']+"+0000",miqtv.date_formats['mariqt']+"%z").timestamp())
positions.setVals(utc,item['image-latitude'],item['image-longitude'],item['image-depth'])
events[utc] = img
con = MarIQTConnector(api_url,platform,user,'MarIQTImages')
con.set_positions(positions,events)
con.do_import()
def uploadEventListToUnderway(csv_path:str,platform:str,user:str,api_url:str = miqtv.apis['osis_underway']):
""" Takes a CSV file with utc,lat,lon,dep columns and send the coordinates to the OSIS underway database"""
positions = miqtn.readAllPositionsFromFilePath(csv_path,{'utc':'Date Time','lon':'Longitude','lat':'Latitude','dep':'Depth'},miqtv.date_formats['dship'])
tmp_events = miqtf.tabFileData(csv_path,['Date Time','Event'],key_col = 'Date Time')
......@@ -54,12 +74,9 @@ class MarIQTConnector(OsisUnderwayConnector):
return self.positions
def set_positions(self, positions:miqtg.Positions, payloads:list = []):
use_payload = False
if len(payloads) > 0 and len(payloads) != positions.len():
raise Exception("Positions and payload lengths do not match!")
else:
use_payload = True
self.positions = []
......@@ -70,8 +87,9 @@ class MarIQTConnector(OsisUnderwayConnector):
# Get the time in the correct format
utc_str = datetime.datetime.fromtimestamp(pos.utc,tz=datetime.timezone.utc).strftime(miqtv.date_formats['underway'])
if use_payload:
if utc in payloads:
payload = payloads[utc]
self.positions.append({'latitude':pos.lat, 'longitude':pos.lon, 'obs_timestamp':utc_str, 'platform':self.platform, 'payload': {'data': {'event':payload},'data_format': "string"}})
else:
self.positions.append({'latitude':pos.lat, 'longitude':pos.lon, 'obs_timestamp':utc_str, 'platform':self.platform})
payload = []
payload['depth'] = pos.dep
self.positions.append({'latitude':pos.lat, 'longitude':pos.lon, 'obs_timestamp':utc_str, 'platform':self.platform, 'payload': {'data': payload,'data_format': "json"}})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment