Skip to content

Commit f84399e

Browse files
committed
consolidate actions, create tp attr before network change eval
1 parent e6f5d08 commit f84399e

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

examples/settings/log_to_net.csv

+1
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ USECLASS_AM,useclass_AM
7878
USECLASS_MD,useclass_MD
7979
USECLASS_PM,useclass_PM
8080
USECLASS_EV,useclass_EV
81+
LANES,lanes

lasso/project.py

+39-6
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,10 @@ def split_log(x):
495495
.rename("operation_history")
496496
.reset_index()
497497
)
498-
action_history_df["operation_final"] = action_history_df.apply(lambda x: Project._final_op(x), axis=1)
499-
498+
500499
link_df = pd.merge(link_df, action_history_df, on=['A', 'B'], how="left")
500+
link_df.drop_duplicates(subset=['A', 'B'], keep="last", inplace=True)
501+
link_df["operation_final"] = link_df.apply(lambda x: Project._final_op(x), axis=1)
501502

502503
if len(node_df) > 0:
503504
action_history_df = (
@@ -506,9 +507,10 @@ def split_log(x):
506507
.rename("operation_history")
507508
.reset_index()
508509
)
509-
action_history_df["operation_final"] = action_history_df.apply(lambda x: Project._final_op(x), axis=1)
510-
511-
node_df = pd.merge(node_df, action_history_df, on='N', how="left")
510+
511+
node_df = pd.merge(node_df, action_history_df, on=['N'], how="left")
512+
node_df.drop_duplicates(subset=['N'], keep="last", inplace=True)
513+
node_df["operation_final"] = node_df.apply(lambda x: Project._final_op(x), axis=1)
512514

513515
WranglerLogger.info(
514516
"Processed {} Node lines and {} Link lines".format(
@@ -1080,8 +1082,39 @@ def _process_link_additions(
10801082

10811083
for x in add_col:
10821084
cube_add_df[x] = cube_add_df[x].astype(self.base_roadway_network.links_df[x].dtype)
1085+
1086+
add_col_final = add_col.copy()
1087+
# properties that are split by time period and category
1088+
for c in add_col:
1089+
if "_" not in c:
1090+
continue
1091+
# WranglerLogger.debug("Processing Column: {}".format(c))
1092+
(
1093+
p_base_name,
1094+
p_time_period,
1095+
p_category,
1096+
managed_lane,
1097+
) = column_name_to_parts(c, self.parameters)
1098+
1099+
if p_base_name not in self.parameters.properties_to_split.keys():
1100+
continue
1101+
1102+
if (p_base_name in cube_add_df.columns):
1103+
if cube_add_df[p_base_name].equals(cube_add_df[c]):
1104+
add_col_final.remove(c)
1105+
continue
1106+
else:
1107+
msg = "Detected different changes for split-property variables on regular roadway links: "
1108+
msg += "conflicting \"{}\" values \"{}\", \"{}\"".format(p_base_name, cube_add_df[p_base_name], cube_add_df[c])
1109+
WranglerLogger.error(msg)
1110+
raise ValueError(msg)
1111+
1112+
else:
1113+
cube_add_df[p_base_name] = cube_add_df[c]
1114+
add_col_final.remove(c)
1115+
add_col_final.append(p_base_name)
10831116

1084-
add_link_properties = cube_add_df[add_col].to_dict("records")
1117+
add_link_properties = cube_add_df[add_col_final].to_dict("records")
10851118

10861119
# WranglerLogger.debug("Add Link Properties: {}".format(add_link_properties))
10871120
WranglerLogger.debug("{} Links Added".format(len(add_link_properties)))

0 commit comments

Comments
 (0)