Skip to content

Commit

Permalink
incorporating the ability to filter with a date range?
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Sep 1, 2022
1 parent 4821a1c commit 2377ae3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/pg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ def reset_job_order(self):
if not failed:
self.conn.commit()

def get_terria_map_catalog_data(self, grid_type, event_type, instance_name, run_date, limit):
def get_terria_map_catalog_data(self, grid_type, event_type, instance_name, run_date, end_date, limit):
"""
gets the catalog data for the terria map UI
:return:
"""

# create the sql
sql: str = f'SELECT public.get_terria_data_json(_grid_type:={grid_type}, _event_type:={event_type}, _instance_name:={instance_name}, _run_date:={run_date}, _limit:={limit})'
sql: str = f'SELECT public.get_terria_data_json(_grid_type:={grid_type}, _event_type:={event_type}, _instance_name:={instance_name}, _run_date:={run_date}, _end_date:={end_date}, _limit:={limit})'

# get the data
return self.exec_sql(sql)[0][0]
Expand Down
18 changes: 12 additions & 6 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from src.pg_utils import PGUtils

# set the app version
APP_VERSION = 'v0.0.15'
APP_VERSION = 'v0.0.16'

# get the log level and directory from the environment.
# level comes from the container dockerfile, path comes from the k8s secrets
Expand Down Expand Up @@ -311,15 +311,17 @@ async def get_terria_map_catalog_data(grid_type: Union[str, None] = Query(defaul
event_type: Union[str, None] = Query(default=None),
instance_name: Union[str, None] = Query(default=None),
run_date: Union[str, None] = Query(default=None),
limit: Union[int, None] = Query(default=2)) -> json:
end_date: Union[str, None] = Query(default=None),
limit: Union[int, None] = Query(default=4)) -> json:
"""
Gets the json formatted terria map UI catalog data.
<br/>Note: Leave filtering params empty if not desired.
<br/>&nbsp;&nbsp;&nbsp;grid_type: Filter by the name of the ASGS grid
<br/>&nbsp;&nbsp;&nbsp;event_type: Filter by the event type
<br/>&nbsp;&nbsp;&nbsp;instance_name: Filter by the name of the ASGS instance
<br/>&nbsp;&nbsp;&nbsp;run_date: Filter by the run date in the form of yyyy-mm-dd
<br/>&nbsp;&nbsp;&nbsp;limit: Limit the number of catalog records returned (default is 2)
<br/>&nbsp;&nbsp;&nbsp;end_date: Filter by the data between the run date and end date
<br/>&nbsp;&nbsp;&nbsp;limit: Limit the number of catalog records returned (default is 4)
"""

# init the returned html status code
Expand All @@ -334,9 +336,10 @@ async def get_terria_map_catalog_data(grid_type: Union[str, None] = Query(defaul
event_type = 'null' if not event_type else f"'{event_type}'"
instance_name = 'null' if not instance_name else f"'{instance_name}'"
run_date = 'null' if not run_date else f"'{run_date}'"
end_date = 'null' if not end_date else f"'{end_date}'"

# try to make the call for records
ret_val = pg_db.get_terria_map_catalog_data(grid_type, event_type, instance_name, run_date, limit)
ret_val = pg_db.get_terria_map_catalog_data(grid_type, event_type, instance_name, run_date, end_date, limit)
except Exception as e:
# return a failure message
ret_val = f'Exception detected trying to get the terria map catalog data.'
Expand All @@ -357,7 +360,8 @@ async def get_terria_map_catalog_data_file(file_name: Union[str, None] = Query(d
event_type: Union[str, None] = Query(default=None),
instance_name: Union[str, None] = Query(default=None),
run_date: Union[str, None] = Query(default=None),
limit: Union[int, None] = Query(default=2)) -> FileResponse:
end_date: Union[str, None] = Query(default=None),
limit: Union[int, None] = Query(default=4)) -> FileResponse:
"""
Returns the json formatted terria map UI catalog data in a file specified.
<br/>Note: Leave filtering params empty if not desired.
Expand All @@ -366,6 +370,7 @@ async def get_terria_map_catalog_data_file(file_name: Union[str, None] = Query(d
<br/>&nbsp;&nbsp;&nbsp;event_type: Filter by the event type
<br/>&nbsp;&nbsp;&nbsp;instance_name: Filter by the name of the ASGS instance
<br/>&nbsp;&nbsp;&nbsp;run_date: Filter by the run date in the form of yyyy-mm-dd
<br/>&nbsp;&nbsp;&nbsp;end_date: Filter by the data between the run date and end date
<br/>&nbsp;&nbsp;&nbsp;limit: Limit the number of catalog records returned (default is 2)
"""
# init the returned html status code
Expand All @@ -379,13 +384,14 @@ async def get_terria_map_catalog_data_file(file_name: Union[str, None] = Query(d
event_type = 'null' if not event_type else f"'{event_type}'"
instance_name = 'null' if not instance_name else f"'{instance_name}'"
run_date = 'null' if not run_date else f"'{run_date}'"
end_date = 'null' if not end_date else f"'{end_date}'"

try:
# create the postgres access object
pg_db = PGUtils(apsviz_dbname, apsviz_username, apsviz_password)

# try to make the call for records
ret_val = pg_db.get_terria_map_catalog_data(grid_type, event_type, instance_name, run_date, limit)
ret_val = pg_db.get_terria_map_catalog_data(grid_type, event_type, instance_name, run_date, end_date, limit)

# write out the data to a file
with open(file_path, 'w') as fp:
Expand Down

0 comments on commit 2377ae3

Please sign in to comment.