Skip to content

Commit a926768

Browse files
committed
feat: add scene_id column and fix choice_kdma_association formatting
- Add scene_id column after scenario_id, extracted from full_state.meta_info - Fix choice_kdma_association to format dictionary as string (e.g., "affiliation:0.0,medical:0.991304348") - Reorder choice_kdma_association column to be after state_description for better logical grouping
1 parent 5d38414 commit a926768

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

align_browser/csv_exporter.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ def format_kdma_config(kdma_values: List[Dict[str, Any]]) -> str:
2424
return ",".join(kdma_strings)
2525

2626

27+
def extract_scene_id(item: InputOutputItem) -> str:
28+
"""Extract the scene_id from an input/output item."""
29+
if not item.input.full_state:
30+
return ""
31+
32+
meta_info = item.input.full_state.get("meta_info", {})
33+
return meta_info.get("scene_id", "")
34+
35+
2736
def extract_choice_text(item: InputOutputItem) -> str:
2837
"""Extract the human-readable choice text from an input/output item."""
2938
if not item.output or "choice" not in item.output:
@@ -55,7 +64,16 @@ def extract_choice_kdma(item: InputOutputItem) -> str:
5564
return ""
5665

5766
selected_choice = choices[choice_index]
58-
return selected_choice.get("kdma_association", "")
67+
kdma_association = selected_choice.get("kdma_association", "")
68+
69+
# Format the KDMA association dictionary as a string
70+
if isinstance(kdma_association, dict) and kdma_association:
71+
kdma_strings = []
72+
for kdma_name, value in kdma_association.items():
73+
kdma_strings.append(f"{kdma_name}:{value}")
74+
return ",".join(kdma_strings)
75+
76+
return str(kdma_association) if kdma_association else ""
5977

6078

6179
def extract_justification(item: InputOutputItem) -> str:
@@ -180,6 +198,7 @@ def experiment_to_csv_rows(
180198
"kdma_config": kdma_config,
181199
"alignment_target_id": alignment_target_id,
182200
"scenario_id": item.input.scenario_id,
201+
"scene_id": extract_scene_id(item),
183202
"state_description": item.input.state
184203
if hasattr(item.input, "state")
185204
else "",
@@ -215,9 +234,10 @@ def write_experiments_to_csv(
215234
"kdma_config",
216235
"alignment_target_id",
217236
"scenario_id",
237+
"scene_id",
218238
"state_description",
219-
"choice_text",
220239
"choice_kdma_association",
240+
"choice_text",
221241
"choice_info",
222242
"justification",
223243
"decision_time_s",

0 commit comments

Comments
 (0)