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

minor changes in main.py to prevent errors #32

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions fastapi_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ async def simulation_results(request: Request):
return templates.TemplateResponse("simulation-results.html", {"request": request})


@app.get("/get_demand_coverage_data")
@app.get("/get_demand_coverage_data/")
async def get_demand_coverage_data():

return json.loads(pd.read_csv(full_path_demand_coverage).to_json())
Expand Down Expand Up @@ -431,15 +431,18 @@ def database_add(add_nodes: bool, add_links: bool, inlet: dict):
df = pd.DataFrame.from_dict(nodes).round(decimals=6)

# the existing database
df_existing = pd.read_csv(full_path_nodes)

# Remove all existing poles and the power house.
df_existing = df_existing[
(df_existing["node_type"] != "pole")
& (df_existing["node_type"] != "power-house")
]
if os.path.exists(full_path_nodes):
df_existing = pd.read_csv(full_path_nodes)

# Remove all existing poles and the power house.
df_existing = df_existing[
(df_existing["node_type"] != "pole")
& (df_existing["node_type"] != "power-house")
]
else:
df_existing = pd.DataFrame()

# Aappend the existing database with the new nodes and remove
# Aappend the existing database with the new nodes and remove
# duplicates (only when both lat and lon are identical).
df_total = df_existing.append(df).drop_duplicates(
subset=["latitude", "longitude", "node_type"], inplace=False
Expand All @@ -452,9 +455,10 @@ def database_add(add_nodes: bool, add_links: bool, inlet: dict):
# already existing links and all existing poles must be removed.
if df["node_type"].str.contains("consumer").sum() > 0:
# Remove existing links.
df_links = pd.read_csv(full_path_links)
df_links.drop(labels=df_links.index, axis=0, inplace=True)
df_links.to_csv(full_path_links, index=False, header=df_links.head)
if os.path.exists(full_path_links):
df_links = pd.read_csv(full_path_links)
df_links.drop(labels=df_links.index, axis=0, inplace=True)
df_links.to_csv(full_path_links, index=False, header=df_links.head)

# defining the precision of data
df_total.latitude = df_total.latitude.map(lambda x: "%.6f" % x)
Expand Down Expand Up @@ -501,7 +505,7 @@ async def database_read(nodes_or_links: str):
return links_list


@app.get("/load_results")
@app.get("/load_results/")
async def load_results():

results = {}
Expand Down Expand Up @@ -697,7 +701,7 @@ async def save_previous_data(
df.to_csv(full_path_stored_inputs, index=False)


@app.get("/get_optimal_capacities")
@app.get("/get_optimal_capacities/")
async def get_optimal_capacities():

optimal_capacities = {}
Expand All @@ -716,7 +720,7 @@ async def get_optimal_capacities():
return optimal_capacities


@app.get("/get_lcoe_breakdown")
@app.get("/get_lcoe_breakdown/")
async def get_lcoe_breakdown():

lcoe_breakdown = {}
Expand All @@ -732,7 +736,7 @@ async def get_lcoe_breakdown():
return lcoe_breakdown


@app.get("/get_data_for_sankey_diagram")
@app.get("/get_data_for_sankey_diagram/")
async def get_data_for_sankey_diagram():

sankey_data = {}
Expand All @@ -756,19 +760,19 @@ async def get_data_for_sankey_diagram():
return sankey_data


@app.get("/get_data_for_energy_flows")
@app.get("/get_data_for_energy_flows/")
async def get_data_for_energy_flows():

return json.loads(pd.read_csv(full_path_energy_flows).to_json())


@app.get("/get_data_for_duration_curves")
@app.get("/get_data_for_duration_curves/")
async def get_data_for_duration_curves():

return json.loads(pd.read_csv(full_path_duration_curves).to_json())


@app.get("/get_co2_emissions_data")
@app.get("/get_co2_emissions_data/")
async def get_co2_emissions_data():

return json.loads(pd.read_csv(full_path_co2_emissions).to_json())
Expand Down Expand Up @@ -1255,7 +1259,7 @@ async def optimize_grid():
)


@app.post("/optimize_energy_system")
@app.post("/optimize_energy_system/")
async def optimize_energy_system(
optimize_energy_system_request: models.OptimizeEnergySystemRequest,
):
Expand Down