Skip to content

Commit

Permalink
adding method to pull instance names for the pull down, tidying up
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Oct 25, 2024
1 parent b74d567 commit b95157f
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pytz
import pandas as pd
import numpy as np
from enum import Enum, EnumType

from src.common.pg_utils_multi import PGUtilsMultiConnect
from src.common.logger import LoggingUtil
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_map_workbench_data(self, **kwargs):
# init the run id
run_id: str = ''

# create the sql to get the latest runs for the workbench lookup
# create the SQL to get the latest runs for the workbench lookup
sql: str = f"SELECT public.get_latest_runs(_insertion_date:={kwargs['insertion_date']}, _met_class:={kwargs['met_class']}, " \
f"_physical_location:={kwargs['physical_location']}, _ensemble_name:={kwargs['ensemble_name']}, " \
f"_instance_name:={kwargs['instance_name']}, _project_code:={kwargs['project_code']})"
Expand Down Expand Up @@ -141,7 +142,7 @@ def get_map_catalog_data(self, **kwargs):
# get the new workbench data
workbench_data: dict = self.get_workbench_data(**kwargs)

# init the workbench sql statement storage
# init the workbench SQL statement storage
wb_sql: str = ""

# should we continue?
Expand All @@ -159,7 +160,7 @@ def get_map_catalog_data(self, **kwargs):
else:
sp_name: str = 'public.get_terria_data_json'

# create the sql
# create the SQL
sql: str = f"SELECT {sp_name}(_grid_type:={kwargs['grid_type']}, _event_type:={kwargs['event_type']}, " \
f"_instance_name:={kwargs['instance_name']}, _run_date:={kwargs['run_date']}, _end_date:={kwargs['end_date']}, " \
f"_limit:={kwargs['limit']}, _met_class:={kwargs['met_class']}, " \
Expand Down Expand Up @@ -273,7 +274,7 @@ def get_catalog_member_records(self, **kwargs) -> dict:
# init the return
ret_val: dict = {}

# create the sql
# create the SQL
sql: str = f"SELECT public.get_catalog_member_records(_run_id := {kwargs['run_id']}, _project_code := {kwargs['project_code']}, " \
f"_filter_event_type := {kwargs['filter_event_type']}, _limit := {kwargs['limit']});"

Expand Down Expand Up @@ -521,3 +522,34 @@ def get_obs_station_data(self, station_name, start_date, end_date) -> pd.DataFra

# Return Pandas dataframe
return ret_val

def get_instance_names(self, name: str, project_code: str = None) -> EnumType:
"""
Gets an Enum list of instance names for the UI pulldown
:param name:
:param project_code:
:return:
"""
# init the return value:
ret_val = None

# prep the param for the SP
if project_code is None:
project_code = 'null'
else:
project_code = f"'{project_code}'"

# build the query
sql = f"SELECT * FROM get_instance_names(_project_code := {project_code});"

# get the info
enum_data = self.exec_sql('apsviz', sql)

# was it successful?
if enum_data != -1:
# convert query output to Pandas dataframe
ret_val = Enum(name, enum_data)

# Return Pandas dataframe
return ret_val

0 comments on commit b95157f

Please sign in to comment.