Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #288 from HumanSignal/fb-LEAP-1063
Browse files Browse the repository at this point in the history
feat: LEAP-1063: Add history field support
  • Loading branch information
triklozoid authored May 22, 2024
2 parents 4ff246b + 83f38d6 commit 1abb242
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions label_studio_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def get_data(task, outputs, annotation):
'created_at': annotation.get('created_at'),
'updated_at': annotation.get('updated_at'),
'lead_time': annotation.get('lead_time'),
'history': annotation.get('history'),
}

def _check_format(self, fmt):
Expand Down
6 changes: 6 additions & 0 deletions label_studio_converter/exports/csv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def prepare_annotation(item):
if 'agreement' in item:
record['agreement'] = item['agreement']

if 'history' in item and item['history']:
record['history'] = json.dumps(item['history'], ensure_ascii=False)

return record


Expand All @@ -94,4 +97,7 @@ def prepare_annotation_keys(item):
if 'agreement' in item:
record.add('agreement')

if 'history' in item and item['history']:
record.add('history')

return record
99 changes: 99 additions & 0 deletions tests/data/test_export_csv/csv_test_history.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[
{
"id": 6141,
"annotations": [
{
"id": 18047,
"completed_by": {
"id": 14,
"email": "[email protected]",
"first_name": "",
"last_name": ""
},
"result": [
{
"id": "d1uGfhDvN6",
"type": "choices",
"value": {
"choices": [
"Positive"
]
},
"origin": "manual",
"to_name": "text",
"from_name": "sentiment"
}
],
"reviews": [],
"history": [
{
"id": 18070,
"comment": null,
"organization_id": 12,
"project_id": 24,
"annotation_id": 18047,
"draft_id": null,
"review_id": null,
"task_id": 6141,
"result": [
{
"id": "d1uGfhDvN6",
"type": "choices",
"value": {
"choices": [
"Positive"
]
},
"origin": "manual",
"to_name": "text",
"from_name": "sentiment"
}
],
"action": "submitted",
"created_at": "2024-05-15T12:09:17.000572Z",
"created_by": 14,
"comment_id": null
}
],
"was_cancelled": false,
"ground_truth": false,
"created_at": "2024-05-15T12:09:16.789536Z",
"updated_at": "2024-05-15T12:09:16.789563Z",
"draft_created_at": null,
"lead_time": 1.849,
"prediction": {},
"result_count": 0,
"unique_id": "de253957-8959-4e6f-9022-30d08bbea9f3",
"import_id": null,
"last_action": "submitted",
"task": 6141,
"project": 24,
"updated_by": 14,
"parent_prediction": null,
"parent_annotation": null,
"last_created_by": 14
}
],
"file_upload": "de982d35-text_data10.json",
"drafts": [],
"predictions": [],
"agreement": 100,
"data": {
"text": "Calif. wildfires signal the arrival of a planetary fire age https://t.co/Vvo9noqQfA"
},
"meta": {},
"created_at": "2024-05-15T12:08:36.422297Z",
"updated_at": "2024-05-15T12:09:16.934164Z",
"inner_id": 1,
"total_annotations": 1,
"cancelled_annotations": 0,
"total_predictions": 0,
"comment_count": 0,
"unresolved_comment_count": 0,
"last_comment_updated_at": null,
"project": 24,
"updated_by": 14,
"comment_authors": []
}
]

11 changes: 11 additions & 0 deletions tests/test_export_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ def test_csv_export_complex_fields_with_json():
json.loads(df.iloc[0].iswcs_1)

assert open(result_csv).read() == open(assert_csv).read()


def test_csv_history():
converter = Converter({}, '/tmp')
output_dir = '/tmp/lsc-pytest'
result_csv = output_dir + '/result.csv'
input_data = os.path.abspath(os.path.dirname(__file__)) + '/data/test_export_csv/csv_test_history.json'
sep = '\t'
converter.convert_to_csv(input_data, output_dir, sep=sep, header=True, is_dir=False)
df = read_csv(result_csv, sep=sep)
assert 'history' in df.columns, "'history' column is not in the CSV"

0 comments on commit 1abb242

Please sign in to comment.