Skip to content

Commit

Permalink
fix: modify the 9d5da vesion, delete the judgement of len(label_dict)
Browse files Browse the repository at this point in the history
  • Loading branch information
up-pika committed Mar 8, 2023
1 parent a3601ea commit cb97cd9
Showing 1 changed file with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,37 @@ def upgrade() -> None:
if label.get("key"):
label_dict[label.get("key")] = label.get("value")

# replace key with value in the sample of current task if label_dict is not null
if len(label_dict) > 0:
# get the sample data items of the task id
sample_items = session.execute(
f"SELECT id, data FROM task_sample WHERE task_id={task_id}"
)
for sample_item in sample_items:
sample_id = sample_item[0]
sample_data_item = json.loads(sample_item[1])
sample_annotated_result = json.loads(sample_data_item.get("result"))
if sample_annotated_result:
for sample_tool in sample_annotated_result.keys():
if sample_tool.endswith("Tool"):
for sample_tool_result in sample_annotated_result.get(
sample_tool
).get("result", []):
tool_label = sample_tool_result.get("attribute", "")
if tool_label in label_dict:
sample_tool_result["attribute"] = label_dict[
tool_label
]
sample_data_item["result"] = json.dumps(
sample_annotated_result, ensure_ascii=False
)
sample_annotated_item_str = json.dumps(
sample_data_item, ensure_ascii=False
)
op.execute(
update(task_sample)
.where(task_sample.id == sample_id)
.where(
task_sample.task_id == task_id,
)
.values({task_sample.data: sample_annotated_item_str})
)
# replace key with value in the sample of current task
# get the sample data items of the task id
sample_items = session.execute(
f"SELECT id, data FROM task_sample WHERE task_id={task_id}"
)
for sample_item in sample_items:
sample_id = sample_item[0]
sample_data_item = json.loads(sample_item[1])
sample_annotated_result = json.loads(sample_data_item.get("result"))
if sample_annotated_result:
for sample_tool in sample_annotated_result.keys():
if sample_tool.endswith("Tool"):
for sample_tool_result in sample_annotated_result.get(
sample_tool
).get("result", []):
tool_label = sample_tool_result.get("attribute", "")
if tool_label in label_dict:
sample_tool_result["attribute"] = label_dict[
tool_label
]
sample_data_item["result"] = json.dumps(
sample_annotated_result, ensure_ascii=False
)
sample_annotated_item_str = json.dumps(
sample_data_item, ensure_ascii=False
)
op.execute(
update(task_sample)
.where(task_sample.id == sample_id)
.values({task_sample.data: sample_annotated_item_str})
)


def downgrade() -> None:
Expand Down

0 comments on commit cb97cd9

Please sign in to comment.