Skip to content
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

feat/expand-notam-parser #254

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/core/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ def download_pickled_object_from_minio(id: UUID4, s3: Minio) -> Any:

def list_minio_objects(s3: Minio) -> Any:
"""Lists all objects in the specified bucket."""
logger.info("Minio objects:")

objects = s3.list_objects(settings.minio_bucket_name, recursive=True)
for obj in objects:
logger.info(f"{obj.bucket_name} {obj.object_name} {obj.last_modified} {obj.size}")
try:
objects = s3.list_objects(settings.minio_bucket_name, recursive=True)
logger.info("Minio objects:")
for obj in objects:
logger.info(f"{obj.bucket_name} {obj.object_name} {obj.last_modified} {obj.size}")
except: # pylint: disable=bare-except
logger.warning(f"unable to list minio objects for {settings.minio_bucket_name}")
4 changes: 4 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .core.config import settings, set_acronym_dictionary, get_label_dictionary, set_label_dictionary
from .core.errors import HTTPValidationError
from .core.logging import logger, LogConfig
from .core.minio import build_client, list_minio_objects
from .db.base import Base
from .db.session import SessionLocal
from .experimental_features_router import router as experimental_router
Expand Down Expand Up @@ -123,6 +124,9 @@ async def startup_event():
logger.info(f"label dictionary mismatch, updating: {label_dictionary}")
set_label_dictionary(label_dictionary)

# list minio objects during app startup
list_minio_objects(build_client())

# close the httpx client when app is shutdown
# see here: https://stackoverflow.com/questions/73721736/what-is-the-proper-way-to-make-downstream-https-requests-inside-of-uvicorn-fasta
@versioned_app.on_event('shutdown')
Expand Down
66 changes: 25 additions & 41 deletions app/mattermost/crud/crud_mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,66 +494,50 @@ def parse_props(jobj: dict):
def parse_props_notam(jobj: dict):
msg = '[%s] %s' % (jobj['title'], jobj['text'])

fld_list = ['ID', 'Type', 'From', 'To', 'Aerodrome', 'FIR', 'Subject', 'Condition', 'Traffic', 'Purpose', 'Scope', 'Area']
if jobj['fields'] is not None:
icao = ''
tov = ''
nstrs = []

for fld in jobj['fields']:
if fld['title'] == 'Location':
icao = fld['value']
if fld['title'] == 'Valid':
tov = fld['value']
msg = '[%s] %s (Location: %s, Time of Validity: %s)' % (jobj['title'],
jobj['text'],
icao,
tov)
if fld['title'] in fld_list:
nstrs.append('%s: %s' % (fld['title'], fld['value']))

if len(nstrs):
msg = '%s (%s)' % (msg, ', '.join(s for s in nstrs))

return msg


def parse_props_acars(jobj: dict, title: str):
msg = '[%s] %s' % (title, jobj['text'])

fld_list = ['Tail #', 'Mission #', 'Callsign']
if jobj['fields'] is not None:
tail_num = ''
msn_num = ''
callsign = ''
nstrs = []

for fld in jobj['fields']:
if fld['title'] == 'Tail #':
tail_num = fld['value']
if fld['title'] == 'Mission #':
msn_num = fld['value']
if fld['title'] == 'Callsign':
callsign = fld['value']
msg = '[%s] %s (Tail #: %s, Mission #: %s, Callsign: %s)' % (jobj['title'],
jobj['text'],
tail_num,
msn_num,
callsign)
if fld['title'] in fld_list:
nstrs.append('%s: %s' % (fld['title'], fld['value']))

if len(nstrs):
msg = '%s (%s)' % (msg, ', '.join(s for s in nstrs))

return msg


def parse_props_dataminr(jobj: dict):
msg = '%s' % jobj['title']

fld_list = ['Alert Type', 'Event Time', 'Event Location', 'Nearby Airfields']
if jobj['fields'] is not None:
alert_type = ''
event_time = ''
event_loc = ''
airfields = ''
nstrs = []

for fld in jobj['fields']:
if fld['title'] == 'Alert Type':
alert_type = fld['value']
if fld['title'] == 'Event Time':
event_time = fld['value']
if fld['title'] == 'Event Location':
event_loc = fld['value']
if fld['title'] == 'Nearby Airfields':
airfields = fld['value']
msg = '%s (Alert Type: %s, Event Time: %s, Event Location: %s, Nearby Airfields: %s)' % (jobj['title'],
alert_type,
event_time,
event_loc,
airfields)
if fld['title'] in fld_list:
nstrs.append('%s: %s' % (fld['title'], fld['value']))

if len(nstrs):
msg = '%s (%s)' % (msg, ', '.join(s for s in nstrs))

return msg

Expand Down
63 changes: 13 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ glibc = "0.6.1"
pillow = "10.3.0"
aiohttp = "3.9.5"
fonttools = "4.49.0"
sentence-transformers = "2.2.2"
sentence-transformers = "2.3.0"
ctransformers = "0.2.27"
packaging = "23.2"
langsmith = "0.1.50"
Expand Down
Loading