Skip to content

Commit

Permalink
code changes based on new network wrangler
Browse files Browse the repository at this point in the history
  • Loading branch information
yueshuaing committed Oct 29, 2024
1 parent 11324a6 commit aaecd3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 16 additions & 15 deletions methods_add_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from numpy import True_
import pandas as pd
from typing import Tuple
from network_wrangler import ProjectCard
from projectcard import ProjectCard
from projectcard import write_card


def add_cards_to_registry(
Expand Down Expand Up @@ -30,8 +31,8 @@ def add_cards_to_registry(
for card, filename in card_file_list:
if card.project not in input_df["project_added"].values:
for change_index, change_dict in enumerate(card.changes):
if change_dict.get("category", "Missing") == "Add New Roadway":
if "nodes" in change_dict:
if "roadway_addition" in change_dict:
if "nodes" in change_dict["roadway_addition"]:
node_df, node_update, card = _update_registry(
"nodes",
out_df,
Expand All @@ -52,10 +53,10 @@ def add_cards_to_registry(
)

if node_df is not None:
out_df = out_df.append(node_df, ignore_index=True)
out_df = pd.concat([out_df, node_df], ignore_index=True)

out_df = (
out_df.append(link_df, ignore_index=True)
pd.concat([out_df, link_df], ignore_index=True)
.drop_duplicates()
.reset_index(drop=True)
)
Expand All @@ -66,7 +67,7 @@ def add_cards_to_registry(
card.__dict__.pop("file")
if "valid" in card.__dict__:
card.__dict__.pop("valid")
card.write(filename=filename)
write_card(filename=filename)

return out_df

Expand Down Expand Up @@ -238,7 +239,7 @@ def _update_registry(

subject_df = input_df[input_df["type"] == subject_word]

for subject_index, subject in enumerate(card.changes[change_index][nodes_or_links]):
for subject_index, subject in enumerate(card.changes[change_index]["roadway_addition"][nodes_or_links]):
new_id = subject[subject_id_word]

_is_id_in_allowable_range(subject_word, card.project, new_id, range_in_use)
Expand All @@ -251,7 +252,7 @@ def _update_registry(
"project_added": [card.project],
}
)
subject_df = subject_df.append(updates_df)
subject_df = pd.concat([subject_df, updates_df])
else:
number = _find_available_id(
subject_word,
Expand All @@ -260,23 +261,23 @@ def _update_registry(
range_in_use,
subject_df,
)
card.changes[change_index][nodes_or_links][subject_index][
card.changes[change_index]["roadway_addition"][nodes_or_links][subject_index][
subject_id_word
] = number
if nodes_or_links == "nodes":
for i in range(0, len(card.changes[change_index]["links"])):
if card.changes[change_index]["links"][i]["A"] == new_id:
card.changes[change_index]["links"][i]["A"] = number
if card.changes[change_index]["links"][i]["B"] == new_id:
card.changes[change_index]["links"][i]["B"] = number
for i in range(0, len(card.changes[change_index]["roadway_addition"]["links"])):
if card.changes[change_index]["roadway_addition"]["links"][i]["A"] == new_id:
card.changes[change_index]["roadway_addition"]["links"][i]["A"] = number
if card.changes[change_index]["roadway_addition"]["links"][i]["B"] == new_id:
card.changes[change_index]["roadway_addition"]["links"][i]["B"] = number
updates_df = pd.DataFrame(
{
"type": subject_word,
"id": [number],
"project_added": [card.project],
}
)
subject_df = subject_df.append(updates_df)
subject_df = pd.concat([subject_df, updates_df])
write_updated_card = True

return subject_df, write_updated_card, card
4 changes: 2 additions & 2 deletions methods_io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from network_wrangler import ProjectCard
from projectcard import read_card

CARD_DIR = os.path.join(".", "projects")

Expand All @@ -22,7 +22,7 @@ def read_project_cards(card_dir: str = CARD_DIR) -> list:
name, extension = os.path.splitext(filename)
if extension in [".yml", ".yaml"]:
card_file = os.path.join(dirpath, filename)
card = ProjectCard.read(card_file, validate=False)
card = read_card(card_file, validate=False)
card_file_list.append((card, card_file))

return card_file_list

0 comments on commit aaecd3c

Please sign in to comment.