diff --git a/cwms/ratings/ratings.py b/cwms/ratings/ratings.py index 757a653e..9aaa02a7 100644 --- a/cwms/ratings/ratings.py +++ b/cwms/ratings/ratings.py @@ -222,6 +222,7 @@ def rating_simple_df_to_json( effective_date: datetime, transition_start_date: Optional[datetime] = None, description: Optional[str] = None, + active: Optional[bool] = True, ) -> JSON: """This function converts a dataframe to a json dictionary in the correct format to be posted using the store_ratings function. Can only be used for simple ratings with a indenpendant and 1 dependant variable. @@ -255,6 +256,8 @@ def rating_simple_df_to_json( The transitional start date of the rating curve to be stored description: str Optional = None a description to be added to the rating curve + active: Boolean Optional = True + store the rating as active as True of False Returns: JSON @@ -288,7 +291,7 @@ def rating_simple_df_to_json( "transition-start-date": ( transition_start_date.isoformat() if transition_start_date else None ), - "active": True, + "active": active, "description": description, "rating-points": {"point": points_json}, } diff --git a/cwms/ratings/ratings_spec.py b/cwms/ratings/ratings_spec.py index db99a1f4..684bbdb6 100644 --- a/cwms/ratings/ratings_spec.py +++ b/cwms/ratings/ratings_spec.py @@ -103,6 +103,56 @@ def delete_rating_spec(rating_id: str, office_id: str, delete_method: str) -> No return api.delete(endpoint, params) +def rating_spec_df_to_xml(data: pd.DataFrame) -> str: + """ + Converts a dataframe containing rating specification parameters + into xml to be stored into the database. + + Parameters + ---------- + data : pd_dataframe + pandas dataframe that contrains rating specification paramters + should follow same formate the is returned from get_rating_spec function + Returns + ------- + str: xml that can be used in store_rating_spec function + """ + + spec_xml = f""" + + {data.loc[0,'rating-id']} + {data.loc[0,'template-id']} + {data.loc[0,'location-id']} + {data.loc[0,'version']} + {data.loc[0,'source-agency']} + {data.loc[0,'in-range-method']} + {data.loc[0,'out-range-low-method']} + {data.loc[0,'out-range-high-method']} + {str(data.loc[0,'active']).lower()} + {str(data.loc[0,'auto-update']).lower()} + {str(data.loc[0,'auto-activate']).lower()} + {str(data.loc[0,'auto-migrate-extension']).lower()} + """ + + ind_rouding = data.loc[0, "independent-rounding-specs"] + if isinstance(ind_rouding, list): + i = 1 + for rounding in ind_rouding: + spec_xml = ( + spec_xml + + f"""\n {rounding['value']}""" + ) + i = i + 1 + spec_xml2 = f"""\n + {data.loc[0,'dependent-rounding-spec']} + {data.loc[0,'description']} + """ + + spec_xml = spec_xml + spec_xml2 + + return spec_xml + + def store_rating_spec(data: str, fail_if_exists: Optional[bool] = True) -> None: """ This method is used to store a new rating spec. diff --git a/pyproject.toml b/pyproject.toml index 19dffd47..72b7c057 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,8 @@ [tool.poetry] name = "cwms-python" -version = "0.5.3" + +version = "0.5.4" + packages = [ { include = "cwms" }, ]