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

Refactor of the save/edit/delete enz. functions for all tabs #367

2 changes: 1 addition & 1 deletion docs/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Create a warning .
Cross reference to another page or figure:
(remove quotation marks)

"[Write here the text wou want to see]"("add the reference")
"[Write here the text you want to see]"("add the reference")

### Cross reference page
"[Setup Guide]"(/3_setup_guide/index.qmd)"
Expand Down
10 changes: 5 additions & 5 deletions flood_adapt/api/benefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@

def get_benefits(database: IDatabase) -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return database.get_benefits()
return database.benefits.list_objects()


def get_benefit(name: str, database: IDatabase) -> IBenefit:
return database.get_benefit(name)
return database.benefits.get(name)


def create_benefit(attrs: dict[str, Any], database: IDatabase) -> IBenefit:
return Benefit.load_dict(attrs, database.input_path)


def save_benefit(benefit: IBenefit, database: IDatabase) -> None:
database.save_benefit(benefit)
database.benefits.save(benefit)


def edit_benefit(benefit: IBenefit, database: IDatabase) -> None:
database.edit_benefit(benefit)
database.benefits.edit(benefit)


def delete_benefit(name: str, database: IDatabase) -> None:
database.delete_benefit(name)
database.benefits.delete(name)


def check_benefit_scenarios(benefit: IBenefit, database: IDatabase) -> pd.DataFrame:
Expand Down
64 changes: 6 additions & 58 deletions flood_adapt/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

def get_events(database: IDatabase) -> dict[str, Any]:
# use PyQt table / sorting and filtering either with PyQt table or in the API
return database.get_events()
return database.events.list_objects()


def get_event(name: str, database: IDatabase) -> IEvent:
return database.get_event(name)
return database.events.get(name)


def get_event_mode(name: str, database: IDatabase) -> str:
Expand Down Expand Up @@ -100,7 +100,7 @@ def create_historical_hurricane_event(attrs: dict[str, Any]) -> IHistoricalHurri


def save_event_toml(event: IEvent, database: IDatabase) -> None:
database.save_event(event)
database.events.save(event)


def save_timeseries_csv(
Expand All @@ -110,17 +110,17 @@ def save_timeseries_csv(


def edit_event(event: IEvent, database: IDatabase) -> None:
database.edit_event(event)
database.events.edit(event)


def delete_event(name: str, database: IDatabase) -> None:
database.delete_event(name)
database.events.delete(name)


def copy_event(
old_name: str, database: IDatabase, new_name: str, new_description: str
) -> None:
database.copy_event(old_name, new_name, new_description)
database.events.copy(old_name, new_name, new_description)


def download_wl_data(
Expand Down Expand Up @@ -163,55 +163,3 @@ def plot_wind(

def save_cyclone_track(event: IEvent, track: TropicalCyclone, database: IDatabase):
database.write_cyc(event, track)


# def get_event(name: str) -> dict(): # get attributes
# pass


# # on click add event
# def create_new_event(template: str) -> dict(): # get attributes
# pass


# def set_event(event: dict): # set attributes
# pass


# # in event pop-up window on click OK
# def save_event(name: str):
# pass


# # on click hurricane:
# def get_hurricane_tracks():
# pass


# # on click historical from nearshore:
# def create_historical_nearshore_event() -> (
# dict()
# ): # gives back empty object to populate pop-up window, different options for discharge are in the class #TODO: ask Julian
# pass


# # on click plot water level boundary
# def get_waterlevel_timeseries(event: dict) -> dict():
# pass


# # on click plot rainfall
# def get_rainfall_timeseries(event: dict):
# pass


# # on click delete event
# def check_delete_event() -> (
# bool
# ): # , str: # str contains full error message, empty if False
# pass


# # on click copy event
# def copy_event(name_orig: str, name_copy: str):
# pass
12 changes: 6 additions & 6 deletions flood_adapt/api/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@


def get_measures(database: IDatabase) -> dict[str, Any]:
return database.get_measures()
return database.measures.list_objects()


def get_measure(name: str, database: IDatabase) -> IMeasure:
return database.get_measure(name)
return database.measures.get(name)


def create_measure(
Expand Down Expand Up @@ -64,21 +64,21 @@ def create_measure(


def save_measure(measure: IMeasure, database: IDatabase) -> None:
database.save_measure(measure)
database.measures.save(measure)


def edit_measure(measure: IMeasure, database: IDatabase) -> None:
database.edit_measure(measure)
database.measures.edit(measure)


def delete_measure(name: str, database: IDatabase) -> None:
database.delete_measure(name)
database.measures.delete(name)


def copy_measure(
old_name: str, database: IDatabase, new_name: str, new_description: str
) -> None:
database.copy_measure(old_name, new_name, new_description)
database.measures.copy(old_name, new_name, new_description)


# Green infrastructure
Expand Down
4 changes: 2 additions & 2 deletions flood_adapt/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_obs_point_timeseries(name: str, database: IDatabase) -> gpd.GeoDataFrame
The HTML strings of the water level timeseries
"""
# Get the direct_impacts objects from the scenario
hazard = database.get_scenario(name).direct_impacts.hazard
hazard = database.scenarios.get(name).direct_impacts.hazard

# Check if the scenario has run
if not hazard.has_run_check():
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_infographic(name: str, database: IDatabase) -> str:
The HTML string of the infographic.
"""
# Get the direct_impacts objects from the scenario
impact = database.get_scenario(name).direct_impacts
impact = database.scenarios.get(name).direct_impacts

# Check if the scenario has run
if not impact.has_run_check():
Expand Down
47 changes: 6 additions & 41 deletions flood_adapt/api/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@

def get_projections(database: IDatabase) -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return database.get_projections()
return database.projections.list_objects()


def get_projection(name: str, database: IDatabase) -> IProjection:
return database.get_projection(name)
return database.projections.get(name)


def create_projection(attrs: dict[str, Any]) -> IProjection:
return Projection.load_dict(attrs)


def save_projection(projection: IProjection, database: IDatabase) -> None:
database.save_projection(projection)
database.projections.save(projection)


def edit_projection(projection: IProjection, database: IDatabase) -> None:
database.edit_projection(projection)
database.projections.edit(projection)


def delete_projection(name: str, database: IDatabase) -> None:
database.delete_projection(name)
database.projections.delete(name)


def copy_projection(
old_name: str, database: IDatabase, new_name: str, new_description: str
) -> None:
database.copy_projection(old_name, new_name, new_description)
database.projections.copy(old_name, new_name, new_description)


def get_slr_scn_names(database: IDatabase) -> list:
Expand All @@ -46,38 +46,3 @@ def interp_slr(database: IDatabase, slr_scenario: str, year: float) -> float:

def plot_slr_scenarios(database: IDatabase) -> str:
return database.plot_slr_scenarios()


# # on click add projection
# def create_new_projection(template: str) -> dict(): # get attributes
# pass


# def set_projection(event: dict): # set attributes
# pass


# # on click edit projection
# def get_projection(name: str) -> dict(): # get attributes
# # incl physical and spcio-economic
# pass


# def set_projection(event: dict): # set attributes
# pass


# # on click copy projection
# # get_projection
# # set_projection


# # on click delete projection
# def remove_projection(name: str) -> dict(): # get attributes
# # remove object from database object and toml file, both socio-economic and physical
# pass


# # in projection pop-up window on click OK
# def save_projection(name: str):
# pass
10 changes: 5 additions & 5 deletions flood_adapt/api/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

def get_scenarios(database: IDatabase) -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return database.get_scenarios()
return database.scenarios.list_objects()


def get_scenario(name: str, database: IDatabase) -> IScenario:
return database.get_scenario(name)
return database.scenarios.get(name)


def create_scenario(attrs: dict[str, Any], database: IDatabase) -> IScenario:
Expand All @@ -34,18 +34,18 @@ def save_scenario(scenario: IScenario, database: IDatabase) -> (bool, str):
The error message if the scenario was not saved successfully.
"""
try:
database.save_scenario(scenario)
database.scenarios.save(scenario)
return True, ""
except Exception as e:
return False, str(e)


def edit_scenario(scenario: IScenario, database: IDatabase) -> None:
database.edit_scenario(scenario)
database.scenarios.edit(scenario)


def delete_scenario(name: str, database: IDatabase) -> None:
database.delete_scenario(name)
database.scenarios.delete(name)


def run_scenario(name: Union[str, list[str]], database: IDatabase) -> None:
Expand Down
8 changes: 4 additions & 4 deletions flood_adapt/api/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

def get_strategies(database: IDatabase) -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return database.get_strategies()
return database.strategies.list_objects()


def get_strategy(name: str, database: IDatabase) -> IStrategy:
return database.get_strategy(name)
return database.strategies.get(name)


def create_strategy(attrs: dict[str, Any], database: IDatabase) -> IStrategy:
return Strategy.load_dict(attrs, database.input_path)


def save_strategy(strategy: IStrategy, database: IDatabase) -> None:
database.save_strategy(strategy)
database.strategies.save(strategy)


def delete_strategy(name: str, database: IDatabase) -> None:
database.delete_strategy(name)
database.strategies.delete(name)
Loading
Loading