-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from kurusugawa-computer/add-task-progress
タスク進捗状況、フェーズ別累積作業時間をCSVで出力するコマンドを追加
- Loading branch information
Showing
8 changed files
with
222 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.19.0" | ||
__version__ = "1.20.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
アノテーション仕様を出力する | ||
""" | ||
|
||
import argparse | ||
import logging | ||
from typing import Any, Dict, List | ||
|
||
import pandas | ||
|
||
import annofabcli | ||
import annofabcli.common.cli | ||
from annofabcli import AnnofabApiFacade | ||
from annofabcli.common.cli import AbstractCommandLineInterface, ArgumentParser, build_annofabapi_resource_and_login | ||
from annofabcli.common.utils import isoduration_to_hour | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TaskProgress(AbstractCommandLineInterface): | ||
""" | ||
タスクフェーズ別の累積作業時間を出力する。 | ||
""" | ||
|
||
def get_task_phase_statistics(self, project_id: str) -> List[Dict[str, Any]]: | ||
""" | ||
フェーズごとの累積作業時間をCSVに出力するための dict 配列を作成する。 | ||
Args: | ||
project_id: | ||
Returns: | ||
フェーズごとの累積作業時間に対応するdict配列 | ||
""" | ||
task_phase_statistics, _ = self.service.api.get_task_phase_statistics(project_id) | ||
row_list: List[Dict[str, Any]] = [] | ||
for stat_by_date in task_phase_statistics: | ||
date = stat_by_date["date"] | ||
phase_stat_list = stat_by_date["phases"] | ||
for phase_stat in phase_stat_list: | ||
phase_stat["date"] = date | ||
phase_stat["worktime_hour"] = isoduration_to_hour(phase_stat["worktime"]) | ||
row_list.extend(phase_stat_list) | ||
return row_list | ||
|
||
def list_cumulative_labor_time(self, project_id: str) -> None: | ||
super().validate_project(project_id, project_member_roles=None) | ||
|
||
phase_stat_list = self.get_task_phase_statistics(project_id) | ||
df = pandas.DataFrame(phase_stat_list) | ||
# 出力対象の列を指定する | ||
target_df = df[["date", "phase", "worktime_hour"]] | ||
annofabcli.utils.print_csv(target_df, output=self.output, to_csv_kwargs=self.csv_format) | ||
|
||
def main(self): | ||
args = self.args | ||
|
||
project_id = args.project_id | ||
self.list_cumulative_labor_time(project_id) | ||
|
||
|
||
def parse_args(parser: argparse.ArgumentParser): | ||
argument_parser = ArgumentParser(parser) | ||
|
||
argument_parser.add_project_id() | ||
argument_parser.add_csv_format() | ||
argument_parser.add_output() | ||
|
||
parser.set_defaults(subcommand_func=main) | ||
|
||
|
||
def main(args): | ||
service = build_annofabapi_resource_and_login(args) | ||
facade = AnnofabApiFacade(service) | ||
TaskProgress(service, facade, args).main() | ||
|
||
|
||
def add_parser(subparsers: argparse._SubParsersAction): | ||
subcommand_name = "list_cumulative_labor_time" | ||
subcommand_help = "タスクフェーズ別の累積作業時間を出力する。" | ||
description = "タスクフェーズ別の累積作業時間をCSV形式で出力する。" | ||
parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description=description) | ||
parse_args(parser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
アノテーション仕様を出力する | ||
""" | ||
|
||
import argparse | ||
import logging | ||
from typing import Any, Dict, List | ||
|
||
import pandas | ||
|
||
import annofabcli | ||
import annofabcli.common.cli | ||
from annofabcli import AnnofabApiFacade | ||
from annofabcli.common.cli import AbstractCommandLineInterface, ArgumentParser, build_annofabapi_resource_and_login | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TaskProgress(AbstractCommandLineInterface): | ||
""" | ||
タスクの進捗状況を出力する。 | ||
""" | ||
|
||
def get_task_statistics(self, project_id: str) -> List[Dict[str, Any]]: | ||
""" | ||
タスクの進捗状況をCSVに出力するための dict 配列を作成する。 | ||
Args: | ||
project_id: | ||
Returns: | ||
タスクの進捗状況に対応するdict配列 | ||
""" | ||
task_statistics, _ = self.service.api.get_task_statistics(project_id) | ||
row_list: List[Dict[str, Any]] = [] | ||
for stat_by_date in task_statistics: | ||
date = stat_by_date["date"] | ||
task_stat_list = stat_by_date["tasks"] | ||
for task_stat in task_stat_list: | ||
task_stat["date"] = date | ||
row_list.extend(task_stat_list) | ||
return row_list | ||
|
||
def list_task_progress(self, project_id: str) -> None: | ||
super().validate_project(project_id, project_member_roles=None) | ||
|
||
task_stat_list = self.get_task_statistics(project_id) | ||
df = pandas.DataFrame(task_stat_list) | ||
# 出力対象の列を指定する | ||
target_df = df[["date", "phase", "status", "count"]] | ||
|
||
annofabcli.utils.print_csv(target_df, output=self.output, to_csv_kwargs=self.csv_format) | ||
|
||
def main(self): | ||
args = self.args | ||
|
||
project_id = args.project_id | ||
self.list_task_progress(project_id) | ||
|
||
|
||
def parse_args(parser: argparse.ArgumentParser): | ||
argument_parser = ArgumentParser(parser) | ||
|
||
argument_parser.add_project_id() | ||
argument_parser.add_csv_format() | ||
argument_parser.add_output() | ||
|
||
parser.set_defaults(subcommand_func=main) | ||
|
||
|
||
def main(args): | ||
service = build_annofabapi_resource_and_login(args) | ||
facade = AnnofabApiFacade(service) | ||
TaskProgress(service, facade, args).main() | ||
|
||
|
||
def add_parser(subparsers: argparse._SubParsersAction): | ||
subcommand_name = "list_task_progress" | ||
subcommand_help = "タスク進捗情報を出力する" | ||
description = "タスク進捗状況をCSV形式で出力する。" | ||
parser = annofabcli.common.cli.add_parser(subparsers, subcommand_name, subcommand_help, description=description) | ||
parse_args(parser) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters