From 521b0806fa9dfd7c15079e024508f573f0c0a843 Mon Sep 17 00:00:00 2001 From: Valentin Vikhorev Date: Thu, 17 Apr 2025 16:46:13 +0200 Subject: [PATCH] Delete 'dataset report' command, and the methods used by it --- darwin/cli.py | 2 - darwin/cli_functions.py | 59 ----------------------------- darwin/client.py | 37 ------------------ darwin/dataset/remote_dataset.py | 16 -------- darwin/dataset/remote_dataset_v2.py | 20 ---------- darwin/options.py | 20 ---------- 6 files changed, 154 deletions(-) diff --git a/darwin/cli.py b/darwin/cli.py index f72ed9fd8..35c28086b 100644 --- a/darwin/cli.py +++ b/darwin/cli.py @@ -145,8 +145,6 @@ def _run(args: Namespace, parser: ArgumentParser) -> None: # Remove a project (remotely) elif args.action == "remove": f.remove_remote_dataset(args.dataset) - elif args.action == "report": - f.dataset_report(args.dataset, args.granularity or "day", args.pretty) elif args.action == "export": f.export_dataset( args.dataset, diff --git a/darwin/cli_functions.py b/darwin/cli_functions.py index 5c17b46bc..05273db3c 100644 --- a/darwin/cli_functions.py +++ b/darwin/cli_functions.py @@ -300,65 +300,6 @@ def url(dataset_slug: str) -> None: _error(f"Dataset '{e.name}' does not exist.") -def dataset_report(dataset_slug: str, granularity: str, pretty: bool) -> None: - """ - Prints a dataset's report in CSV format. - Exits the application if no dataset is found. - - Parameters - ---------- - dataset_slug : str - The dataset's slug. - granularity : str - Granularity of the report, can be 'day', 'week' or 'month'. - pretty : bool - If ``True``, it will print the output in a Rich formatted table. - """ - client: Client = _load_client(offline=True) - console = Console(theme=_console_theme()) - try: - remote_dataset: RemoteDataset = client.get_remote_dataset( - dataset_identifier=dataset_slug - ) - report: str = remote_dataset.get_report(granularity) - - if not pretty: - # if no one worked in the report, we print nothing - print(report) - return - - lines: List[str] = report.split("\n") - lines.pop(0) # remove csv headers - - if not lines: - console.print("No one has worked on this dataset yet!\n", style="success") - return - - lines.pop() # remove last line, which is empty - - table: Table = Table(show_header=True, header_style="bold cyan") - table.add_column("Date") - table.add_column("Dataset Id", justify="right") - table.add_column("Dataset Name", justify="right") - table.add_column("User Id", justify="right") - table.add_column("Email", justify="right") - table.add_column("First Name", justify="right") - table.add_column("Last Name", justify="right") - table.add_column("Annotation Time", justify="right") - table.add_column("Annotations Approved", justify="right") - table.add_column("Annotations Created", justify="right") - table.add_column("Images Annotated", justify="right") - table.add_column("Images Approved", justify="right") - table.add_column("Images Rejected", justify="right") - - for row in lines: - table.add_row(*row.split(",")) - - console.print(table) - except NotFound: - _error(f"Dataset '{dataset_slug}' does not exist.") - - def export_dataset( dataset_slug: str, include_url_token: bool, diff --git a/darwin/client.py b/darwin/client.py index 19f8ec9fd..9923e622c 100644 --- a/darwin/client.py +++ b/darwin/client.py @@ -615,43 +615,6 @@ def annotation_types(self) -> List[Dict[str, UnknownType]]: ) return response - def get_report( - self, dataset_id: int, granularity: str, team_slug: Optional[str] = None - ) -> Response: - """ - Gets the report for the given dataset. - - Parameters - ---------- - dataset_id: int - The id of the dataset. - granularity: str - Granularity of the report, can be 'day', 'week' or 'month'. - team_slug: Optional[str] - Team slug of the team the dataset will belong to. Defaults to None. - - Returns - ------ - Response - The raw response of the report (CSV format) or None if the Team was not found. - - Raises - ------ - ValueError - If no team was found. - """ - the_team: Optional[Team] = self.config.get_team(team_slug or self.default_team) - - if not the_team: - raise ValueError("No team was found.") - - the_team_slug: str = the_team.slug - - return self._get_raw( - f"/reports/{the_team_slug}/annotation?group_by=dataset,user&dataset_ids={dataset_id}&granularity={granularity}&format=csv&include=dataset.name,user.first_name,user.last_name,user.email", - the_team_slug, - ) - def get_annotators_report( self, dataset_ids: list[int], diff --git a/darwin/dataset/remote_dataset.py b/darwin/dataset/remote_dataset.py index 3fbb3466e..5010d7f6e 100644 --- a/darwin/dataset/remote_dataset.py +++ b/darwin/dataset/remote_dataset.py @@ -718,22 +718,6 @@ def export( Omit this option to get your team's default. """ - @abstractmethod - def get_report(self, granularity: str = "day") -> str: - """ - Returns a String representation of a CSV report for this ``RemoteDataset``. - - Parameters - ---------- - granularity : str, default: "day" - The granularity of the report, can be 'day', 'week' or 'month'. - - Returns - ------- - str - A CSV report. - """ - @abstractmethod def get_releases(self, include_unavailable: bool = False) -> List["Release"]: """ diff --git a/darwin/dataset/remote_dataset_v2.py b/darwin/dataset/remote_dataset_v2.py index f2d67bc13..4432616d7 100644 --- a/darwin/dataset/remote_dataset_v2.py +++ b/darwin/dataset/remote_dataset_v2.py @@ -13,7 +13,6 @@ Iterable, ) from pydantic import ValidationError -from requests.models import Response from darwin.dataset import RemoteDataset from darwin.dataset.release import Release @@ -504,25 +503,6 @@ def export( team_slug=self.team, ) - def get_report(self, granularity: str = "day") -> str: - """ - Returns a String representation of a CSV report for this ``RemoteDataset``. - - Parameters - ---------- - granularity : str, default: "day" - The granularity of the report, can be 'day', 'week' or 'month'. - - Returns - ------- - str - A CSV report. - """ - response: Response = self.client.get_report( - self.dataset_id, granularity, self.team - ) - return response.text - def workview_url_for_item(self, item: DatasetItem) -> str: """ Returns the darwin URL for the given ``DatasetItem``. diff --git a/darwin/options.py b/darwin/options.py index f3eb9aa2a..ef0f10b0a 100644 --- a/darwin/options.py +++ b/darwin/options.py @@ -199,26 +199,6 @@ def __init__(self) -> None: "dataset", type=str, help="Remote dataset name to delete." ) - # Report - parser_report = dataset_action.add_parser( - "report", help="Report about the annotators." - ) - parser_report.add_argument( - "dataset", type=str, help="Remote dataset name to report on." - ) - parser_report.add_argument( - "-g", - "--granularity", - choices=["day", "week", "month", "total"], - help="Granularity of the report.", - ) - parser_report.add_argument( - "-r", - "--pretty", - action="store_true", - default=False, - help="Prints the results formatted in a rich table.", - ) # Export parser_export = dataset_action.add_parser( "export", help="Export a version of a dataset."