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

feat: LEAP-773: Export was_cancelled=true annotations to CSV #279

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 0 additions & 126 deletions label_studio_converter/cli.py

This file was deleted.

13 changes: 9 additions & 4 deletions label_studio_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(
output_tags=None,
upload_dir=None,
download_resources=True,
include_cancelled_annotations=False
):
"""Initialize Label Studio Converter for Exports

Expand All @@ -160,11 +161,13 @@ def __init__(
:param output_tags: it will be calculated automatically, contains label names
:param upload_dir: upload root directory with files that were imported using LS GUI
:param download_resources: if True, LS will try to download images, audio, etc and include them to export
:param include_cancelled_annotations: If True, was_cancelled annotation will be added to export
"""
self.project_dir = project_dir
self.upload_dir = upload_dir
self.download_resources = download_resources
self._schema = None
self.include_cancelled_annotations = include_cancelled_annotations

if isinstance(config, dict):
self._schema = config
Expand Down Expand Up @@ -422,10 +425,11 @@ def annotation_result_from_task(self, task):
yield data

# skip cancelled annotations
cancelled = lambda x: not (
x.get('skipped', False) or x.get('was_cancelled', False)
)
annotations = list(filter(cancelled, annotations))
if not self.include_cancelled_annotations:
cancelled = lambda x: not (
x.get('skipped', False) or x.get('was_cancelled', False)
)
annotations = list(filter(cancelled, annotations))
if not annotations:
return None

Expand Down Expand Up @@ -465,6 +469,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'),
'was_cancelled': annotation.get('was_cancelled'),
}

def _check_format(self, fmt):
Expand Down
3 changes: 2 additions & 1 deletion label_studio_converter/exports/csv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def convert(item_iterator, input_data, output_dir, **kwargs):
output_file = os.path.join(output_dir, 'result.csv')

# these keys are always presented
keys = {'annotator', 'annotation_id', 'created_at', 'updated_at', 'lead_time'}
keys = {'annotator', 'annotation_id', 'created_at', 'updated_at', 'lead_time', 'was_cancelled'}

# make 2 passes: the first pass is to get keys, otherwise we can't write csv without headers
logger.debug('Prepare column names for CSV ...')
Expand Down Expand Up @@ -76,6 +76,7 @@ def prepare_annotation(item):
record['created_at'] = item['created_at']
record['updated_at'] = item['updated_at']
record['lead_time'] = item['lead_time']
record['was_cancelled'] = item['was_cancelled']

if 'agreement' in item:
record['agreement'] = item['agreement']
Expand Down
13 changes: 12 additions & 1 deletion label_studio_converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def get_export_args(parser):
default=True,
help='Set this flag if your annotations are in one JSON file instead of multiple JSON files from directory',
)
parser.add_argument(
'--include-cancelled-annotations',
dest='include_cancelled_annotations',
help='Include cancelled annotations in the export to other formats',
default=False,
action='store_true',
)


def get_all_args():
Expand Down Expand Up @@ -103,7 +110,11 @@ def get_all_args():


def export(args):
c = Converter(args.config, project_dir=args.project_dir)
c = Converter(
args.config,
project_dir=args.project_dir,
include_cancelled_annotations=args.include_cancelled_annotations
)

if args.format == Format.JSON:
c.convert_to_json(args.input, args.output)
Expand Down
Loading