Skip to content

Commit

Permalink
update project.py when only node changes are made #123
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Apr 15, 2021
1 parent 62f4f56 commit c29d78d
Showing 1 changed file with 43 additions and 35 deletions.
78 changes: 43 additions & 35 deletions lasso/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,48 @@ def _consolidate_actions(log, base, key_list):
log_df["OPERATION_final"] = log_df.apply(lambda x: _final_op(x), axis=1)
return log_df[changeable_col + ["OPERATION_final"]]

delete_link_dict = None
add_link_dict = None
change_link_dict_list = []

if len(link_changes_df) != 0:
link_changes_df = _consolidate_actions(
link_changes_df, self.base_roadway_network.links_df, ["A", "B"]
)

# process deletions
delete_link_dict = _process_deletions(link_changes_df)

# process additions
add_link_dict = _process_link_additions(
link_changes_df, limit_variables_to_existing_network
)

# process changes
WranglerLogger.debug("Processing changes")
WranglerLogger.debug(link_changes_df)
changeable_col = list(
(
set(link_changes_df.columns)
& set(self.base_roadway_network.links_df.columns)
)
- set(Project.STATIC_VALUES)
)

cols_in_changes_not_in_net = list(
set(link_changes_df.columns)
- set(self.base_roadway_network.links_df.columns)
)

if cols_in_changes_not_in_net:
WranglerLogger.warning(
"The following attributes are specified in the changes but do not exist in the base network: {}".format(
cols_in_changes_not_in_net
)
)

change_link_dict_list = _process_link_changes(link_changes_df, changeable_col)

if len(node_changes_df) != 0:
node_changes_df = _consolidate_actions(
node_changes_df, self.base_roadway_network.nodes_df, ["model_node_id"]
Expand All @@ -802,43 +839,14 @@ def _consolidate_actions(log, base, key_list):
WranglerLogger.error(msg)
raise ValueError(msg)
node_add_df = node_changes_df[node_changes_df.OPERATION_final == "A"]
else:
node_add_df = pd.DataFrame()

# process deletions
delete_link_dict = _process_deletions(link_changes_df)

# process additions
add_link_dict = _process_link_additions(
link_changes_df, limit_variables_to_existing_network
)
if len(_process_node_additions(node_add_df)):
add_link_dict["nodes"] = _process_node_additions(node_add_df)

# process changes
WranglerLogger.debug("Processing changes")
WranglerLogger.debug(link_changes_df)
changeable_col = list(
(
set(link_changes_df.columns)
& set(self.base_roadway_network.links_df.columns)
)
- set(Project.STATIC_VALUES)
)

cols_in_changes_not_in_net = list(
set(link_changes_df.columns)
- set(self.base_roadway_network.links_df.columns)
)

if cols_in_changes_not_in_net:
WranglerLogger.warning(
"The following attributes are specified in the changes but do not exist in the base network: {}".format(
cols_in_changes_not_in_net
)
)
if add_link_dict:
add_link_dict["nodes"] = _process_node_additions(node_add_df)
else:
add_link_dict = {"category": "Add New Roadway", "nodes": _process_node_additions(node_add_df)}

change_link_dict_list = _process_link_changes(link_changes_df, changeable_col)
else:
None

# combine together

Expand Down

0 comments on commit c29d78d

Please sign in to comment.