Skip to content

Commit

Permalink
fixing spelling mistakes and punctuation in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Feb 14, 2024
1 parent 5331ea0 commit a006366
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class PGImplementation(PGUtilsMultiConnect):
"""
Class that contains DB calls for the ui data component.
Note this class inherits from the PGUtilsMultiConnect class
Note this class inherited from the PGUtilsMultiConnect class
which has all the connection and cursor handling.
"""

def __init__(self, db_names: tuple, _logger=None, _auto_commit=True):
# if a reference to a logger passed in use it
# if this has a reference to a logger passed in use it
if _logger is not None:
# get a handle to a logger
self.logger = _logger
Expand Down Expand Up @@ -90,7 +90,7 @@ def get_terria_map_workbench_data(self, **kwargs):
# interrogate the results we are looking to get this down to the latest relevant tropical run
# or the latest synoptic run catalog member.

# is there a tropical run and is it too old to display
# is there a tropical run and is it too old to display?
if item['met_class'] == 'tropical':
# get the number of days from the last tropical run to now
insertion_date = dateutil.parser.parse(item['insertion_date'])
Expand Down Expand Up @@ -173,7 +173,7 @@ def get_terria_map_catalog_data(self, **kwargs):
# merge the pulldown data to the catalog list
ret_val.update({'pulldown_data': pulldown_data})

# if there is new workbench data add it in now
# if there is new workbench data, add it in now
if len(workbench_data) > 0:
# merge the workbench data to the catalog list
ret_val.update({'workbench': workbench_data['workbench']})
Expand All @@ -191,7 +191,7 @@ def get_workbench_data(self, **kwargs):
# init the return
ret_val: dict = {}

# are we using the new catalog workbench retrieval
# are we using the new catalog workbench retrieval?
if kwargs['use_new_wb']:
# create the param list
params: list = ['insertion_date', 'met_class', 'physical_location', 'ensemble_name', 'project_code']
Expand Down Expand Up @@ -309,11 +309,11 @@ def get_station_data(self, **kwargs) -> str:
# get nowcast data
nowcast_data = self.get_nowcast_station_data(kwargs['station_name'], start_date, end_date, nowcast_source, kwargs['instance_name'])

# If nowcast data exists merge it with obs data
# If nowcast data exists, merge it with obs data
if not nowcast_data.empty:
# check if obs_data is empty
if not obs_data.empty:
# check if obs_data.coloumns id bouy. If it is search for wave_height, else search for water_level
# check if obs_data.columns id buoy. If it is search for wave_height, else search for water_level
if 'ocean_buoy_wave_height' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'wave_height' in s][0]
else:
Expand All @@ -322,30 +322,30 @@ def get_station_data(self, **kwargs) -> str:
# Merge nowcast_data with obs_data
obs_data = obs_data.merge(nowcast_data, on='time_stamp', how='outer')
else:
# if obs data is empty just nowcast data become obs_data, and observation_name is None
# if obs data is empty, just nowcast data become obs_data, and observation_name is None
obs_data = nowcast_data
observation_name = None
else:
# if nowcast data is empty check if obs_data is also empty
# if nowcast data is empty, check if obs_data is also empty
if not obs_data.empty:
# check if obs_data.coloumns id bouy. If it is search for wave_height, else search for water_level
# check if obs_data.columns id buoy. If it is search for wave_height, else search for water_level
if 'ocean_buoy_wave_height' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'wave_height' in s][0]
else:
observation_name = [s for s in obs_data.columns.values if 'water_level' in s][0]
else:
# if obs_data is empty observation_name is None
# if obs_data is empty, observation_name is None
observation_name = None

# replace any None values with np.nan, in both DataFrames
forecast_data.fillna(value=np.nan)
obs_data.fillna(value=np.nan)

# replace any -99999 values with np.nan, in both DataFrames
fcols = forecast_data.columns.tolist()
forecast_data[fcols] = forecast_data[fcols].replace([-99999], np.nan)
ocols = obs_data.columns.tolist()
obs_data[ocols] = obs_data[ocols].replace([-99999], np.nan)
f_cols = forecast_data.columns.tolist()
forecast_data[f_cols] = forecast_data[f_cols].replace([-99999], np.nan)
o_cols = obs_data.columns.tolist()
obs_data[o_cols] = obs_data[o_cols].replace([-99999], np.nan)

# convert all values after the time mark to nan, in obs data, except in the time_stamp and tidal_predictions columns
for col in obs_data.columns:
Expand Down Expand Up @@ -382,12 +382,12 @@ def get_station_data(self, **kwargs) -> str:
station_df.rename(columns={'time_stamp': 'time', nowcast_column_name: 'APS Nowcast', 'tidal_predictions': 'NOAA Tidal Predictions'},
inplace=True)
else:
# else check if observation_name has a vaule and rename the columns
# else check if observation_name has a value and rename the columns
if observation_name:
station_df.rename(columns={'time_stamp': 'time', observation_name: 'Observations', 'tidal_predictions': 'NOAA Tidal Predictions'},
inplace=True)
else:
# else if observation name is None, just rename tidal_predictions
# else if observation name is None rename tidal_predictions
station_df.rename(columns={'time_stamp': 'time', 'tidal_predictions': 'NOAA Tidal Predictions'}, inplace=True)

# return the data to the caller
Expand All @@ -413,7 +413,7 @@ def get_forecast_station_data(self, station_name, time_mark, data_source, instan
# get the info
station_data = self.exec_sql('apsviz_gauges', sql)

# was it successful
# was it successful?
if station_data != -1:
# convert query output to Pandas dataframe
ret_val = pd.DataFrame.from_dict(station_data, orient='columns')
Expand All @@ -429,7 +429,7 @@ def get_nowcast_station_data(self, station_name, start_date, end_date, data_sour
:param station_name:
:param start_date:
:param end_data:
:param end_date:
:param data_source:
:param instance_name:
:return:
Expand All @@ -444,7 +444,7 @@ def get_nowcast_station_data(self, station_name, start_date, end_date, data_sour
# get the info
station_data = self.exec_sql('apsviz_gauges', sql)

# was it successful
# was it successful?
if station_data != -1:
# convert query output to Pandas dataframe
ret_val = pd.DataFrame.from_dict(station_data, orient='columns')
Expand All @@ -461,7 +461,6 @@ def get_obs_station_data(self, station_name, start_date, end_date) -> pd.DataFra
:param station_name:
:param start_date:
:param end_date:
:param nowcast_source:
:return:
"""
# init the return value:
Expand All @@ -474,7 +473,7 @@ def get_obs_station_data(self, station_name, start_date, end_date) -> pd.DataFra
# get the info
station_data = self.exec_sql('apsviz_gauges', sql)

# was it successful
# was it successful?
if station_data != -1:
# convert query output to Pandas dataframe
ret_val = pd.DataFrame.from_dict(station_data, orient='columns')
Expand Down

0 comments on commit a006366

Please sign in to comment.