Пример #1
0
    def main(self):
        args = self.args
        project_id = args.project_id
        task_id_list = annofabcli.common.cli.get_list_from_args(args.task_id)

        dict_annotation_query = get_json_from_args(args.annotation_query)
        annotation_query_for_cli = AnnotationQueryForCli.from_dict(
            dict_annotation_query)
        try:
            annotation_query = self.facade.to_annotation_query_from_cli(
                project_id, annotation_query_for_cli)
        except ValueError as e:
            print(
                f"{self.COMMON_MESSAGE} argument '--annotation_query' の値が不正です。{e}",
                file=sys.stderr)
            return

        attributes_of_dict: List[Dict[str, Any]] = get_json_from_args(
            args.attributes)
        attributes_for_cli: List[AdditionalDataForCli] = [
            AdditionalDataForCli.from_dict(e) for e in attributes_of_dict
        ]
        try:
            attributes = self.facade.to_attributes_from_cli(
                project_id, annotation_query.label_id, attributes_for_cli)
        except ValueError as e:
            print(f"{self.COMMON_MESSAGE} argument '--attributes' の値が不正です。{e}",
                  file=sys.stderr)
            return

        if args.backup is None:
            print(
                "間違えてアノテーションを変更してしまっときに復元できるようにするため、'--backup'でバックアップ用のディレクトリを指定することを推奨します。",
                file=sys.stderr)
            if not self.confirm_processing(
                    "復元用のバックアップディレクトリが指定されていません。処理を続行しますか?"):
                return
            backup_dir = None
        else:
            backup_dir = Path(args.backup)

        self.change_annotation_attributes(
            project_id,
            task_id_list,
            annotation_query=annotation_query,
            attributes=attributes,
            force=args.force,
            change_by=ChangeBy(args.change_by),
            backup_dir=backup_dir,
        )
Пример #2
0
    def main(self):
        args = self.args
        project_id = args.project_id
        task_id_list = annofabcli.common.cli.get_list_from_args(args.task_id)
        dict_annotation_query = get_json_from_args(args.annotation_query)
        if dict_annotation_query is not None:
            annotation_query_for_cli = AnnotationQueryForCli.from_dict(dict_annotation_query)
            try:
                annotation_query = self.facade.to_annotation_query_from_cli(project_id, annotation_query_for_cli)
            except ValueError as e:
                print(f"'--annotation_queryの値が不正です。{e}", file=sys.stderr)
                return
        else:
            annotation_query = None

        if args.backup is None:
            print("間違えてアノテーションを削除してしまっときに復元できるようにするため、'--backup'でバックアップ用のディレクトリを指定することを推奨します。", file=sys.stderr)
            if not self.confirm_processing("復元用のバックアップディレクトリが指定されていません。処理を続行しますか?"):
                return
            backup_dir = None
        else:
            backup_dir = Path(args.backup)

        self.delete_annotation_for_task_list(
            project_id, task_id_list, annotation_query=annotation_query, backup_dir=backup_dir, force=args.force
        )
    def main(self):
        args = self.args
        project_id = args.project_id
        super().validate_project(
            project_id,
            [ProjectMemberRole.OWNER, ProjectMemberRole.TRAINING_DATA_USER])

        if args.task_json is not None:
            task_json_path = args.task_json
        else:
            wait_options = get_wait_options_from_args(
                get_json_from_args(args.wait_options), DEFAULT_WAIT_OPTIONS)
            cache_dir = annofabcli.utils.get_cache_dir()
            task_json_path = cache_dir / f"{project_id}-task.json"

            downloading_obj = DownloadingFile(self.service)
            downloading_obj.download_task_json(project_id,
                                               dest_path=str(task_json_path),
                                               is_latest=args.latest,
                                               wait_options=wait_options)

        with open(task_json_path, encoding="utf-8") as f:
            task_list = json.load(f)

        df = self.create_summary_df(project_id, task_list)
        if len(df) > 0:
            self.print_summarize_df(df)
        else:
            logger.error(f"出力対象データが0件のため、出力しません。")
Пример #4
0
    def main(self):
        args = self.args
        project_id = args.project_id
        super().validate_project(project_id, [ProjectMemberRole.OWNER, ProjectMemberRole.TRAINING_DATA_USER])

        if args.task_json is not None:
            task_json_path = args.task_json
        else:
            wait_options = get_wait_options_from_args(get_json_from_args(args.wait_options), DEFAULT_WAIT_OPTIONS)
            cache_dir = annofabcli.utils.get_cache_dir()
            task_json_path = cache_dir / f"{project_id}-task.json"

            downloading_obj = DownloadingFile(self.service)
            downloading_obj.download_task_json(
                project_id, dest_path=str(task_json_path), is_latest=args.latest, wait_options=wait_options
            )

        with open(task_json_path, encoding="utf-8") as f:
            task_list = json.load(f)

        main_obj = PrintDashBoardMain(self.service)

        dashboard_date = main_obj.create_dashboard_data(project_id, date=args.date, task_list=task_list)
        annofabcli.utils.print_according_to_format(
            dashboard_date.to_dict(),
            arg_format=FormatArgument(self.str_format),
            output=self.output,
        )
Пример #5
0
 def main(self):
     args = self.args
     project_id = args.project_id
     wait_options = get_wait_options_from_args(get_json_from_args(args.wait_options), DEFAULT_WAIT_OPTIONS)
     task_json_path = Path(args.task_json) if args.task_json is not None else None
     self.summarize_task_count(
         project_id, task_json_path=task_json_path, is_latest=args.latest, wait_options=wait_options
     )
Пример #6
0
    def main(self):
        args = self.args

        project_id = args.project_id
        super().validate_project(project_id, project_member_roles=None)

        if args.annotation is not None:
            annotation_path = Path(args.annotation)
        else:
            cache_dir = annofabcli.utils.get_cache_dir()
            annotation_path = cache_dir / f"annotation-{project_id}.zip"
            wait_options = get_wait_options_from_args(
                get_json_from_args(args.wait_options), DEFAULT_WAIT_OPTIONS)
            downloading_obj = DownloadingFile(self.service)
            downloading_obj.download_annotation_zip(
                project_id,
                dest_path=str(annotation_path),
                is_latest=args.latest,
                wait_options=wait_options,
            )

        task_id_set = set(
            annofabcli.common.cli.get_list_from_args(
                args.task_id)) if args.task_id is not None else None
        task_query = (TaskQuery.from_dict(
            annofabcli.common.cli.get_json_from_args(args.task_query))
                      if args.task_query is not None else None)

        group_by = GroupBy(args.group_by)
        if group_by == GroupBy.TASK_ID:
            self.list_annotation_count_by_task(
                project_id,
                annotation_path=annotation_path,
                output_dir=Path(args.output_dir),
                task_id_set=task_id_set,
                task_query=task_query,
            )
        elif group_by == GroupBy.INPUT_DATA_ID:
            self.list_annotation_count_by_input_data(
                project_id,
                annotation_path=annotation_path,
                output_dir=Path(args.output_dir),
                task_id_set=task_id_set,
                task_query=task_query,
            )
Пример #7
0
    def main(self):
        args = self.args

        annotation_path: Path = args.annotation
        # Simpleアノテーションの読み込み
        if annotation_path.is_file():
            iter_parser = lazy_parse_simple_annotation_zip(annotation_path)
        else:
            iter_parser = lazy_parse_simple_annotation_dir(annotation_path)

        df = pandas.read_csv(
            args.input_data_id_csv,
            sep=",",
            header=None,
            names=("input_data_id", "image_path"),
        )
        input_data_id_relation_dict = dict(
            zip(df["input_data_id"], df["image_path"]))

        task_query = (TaskQuery.from_dict(
            annofabcli.common.cli.get_json_from_args(args.task_query))
                      if args.task_query is not None else None)

        draw_annotation_all(
            iter_parser=iter_parser,
            image_dir=args.image_dir,
            input_data_id_relation_dict=input_data_id_relation_dict,
            output_dir=args.output_dir,
            target_task_ids=get_list_from_args(args.task_id)
            if args.task_id is not None else None,
            task_query=task_query,
            label_color_dict=self._create_label_color(args.label_color)
            if args.label_color is not None else None,
            target_label_names=get_list_from_args(args.label_name)
            if args.label_name is not None else None,
            polyline_labels=get_list_from_args(args.polyline_label)
            if args.polyline_label is not None else None,
            drawing_options=DrawingOptions.from_dict(
                get_json_from_args(args.drawing_options))
            if args.drawing_options is not None else None,
        )
Пример #8
0
 def _create_label_color(args_label_color: str) -> Dict[str, Color]:
     label_color_dict = get_json_from_args(args_label_color)
     for label_name, color in label_color_dict.items():
         if isinstance(color, list):
             label_color_dict[label_name] = tuple(color)
     return label_color_dict