Skip to content

Commit

Permalink
Merge pull request #139 from kurusugawa-computer/feature/add-task-his…
Browse files Browse the repository at this point in the history
…tory

統計情報の更新
  • Loading branch information
yuji38kwmt authored Dec 18, 2019
2 parents ea22e2d + 36ab2d6 commit 14f81c1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion annofabcli/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.15.7'
__version__ = '1.15.8'
5 changes: 4 additions & 1 deletion annofabcli/labor/list_worktime_by_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def get_project_title(project_list: List[Project], project_id: str) -> str:
return ""

@staticmethod
def get_worktime_hour(working_time_by_user: Dict[str, Any], key: str) -> float:
def get_worktime_hour(working_time_by_user: Optional[Dict[str, Any]], key: str) -> float:
if working_time_by_user is None:
return 0

value = working_time_by_user.get(key)
if value is None:
return 0
Expand Down
26 changes: 24 additions & 2 deletions annofabcli/statistics/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _inspection_condition(inspection_arg, exclude_reply: bool, only_error_correc

return exclude_reply_flag and only_error_corrected_flag

def _get_user_id(self, account_id):
def _get_user_id(self, account_id: Optional[str]) -> Optional[str]:
"""
プロジェクトメンバのuser_idを取得する。プロジェクトメンバでなければ、account_idを返す。
account_idがNoneならばNoneを返す。
Expand All @@ -170,7 +170,7 @@ def _get_user_id(self, account_id):
else:
return account_id

def _get_username(self, account_id):
def _get_username(self, account_id: Optional[str]) -> Optional[str]:
"""
プロジェクトメンバのusernameを取得する。プロジェクトメンバでなければ、account_idを返す。
account_idがNoneならばNoneを返す。
Expand Down Expand Up @@ -395,6 +395,28 @@ def diff_days(ended_key: str, started_key: str) -> Optional[float]:

return task

def create_task_history_df(self) -> pd.DataFrame:
"""
タスク履歴の一覧のDataFrameを出力する。
Returns:
"""
task_histories_dict = self.database.read_task_histories_from_checkpoint()

all_task_history_list = []
for _, task_history_list in task_histories_dict.items():
for history in task_history_list:
account_id = history["account_id"]
history["user_id"] = self._get_user_id(account_id)
history["username"] = self._get_username(account_id)
history["worktime_hour"] = annofabcli.utils.isoduration_to_hour(
history["accumulated_labor_time_milliseconds"])
all_task_history_list.append(history)

df = pd.DataFrame(all_task_history_list)
return df

def create_task_df(self) -> pd.DataFrame:
"""
タスク一覧からdataframeを作成する。
Expand Down
32 changes: 32 additions & 0 deletions annofabcli/statistics/tsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,38 @@ def write_task_list(self, df: pd.DataFrame, dropped_columns: List[str] = None):
required_columns = self._create_required_columns(df, prior_columns, dropped_columns)
self._write_csv(f"{self.short_project_id}-タスクlist.csv", df[required_columns])

def write_task_history_list(self, df: pd.DataFrame, dropped_columns: List[str] = None) -> None:
"""
タスク履歴一覧をCSVで出力する
Args:
arg_df:
dropped_columns:
Returns:
"""
if len(df) == 0:
logger.info("タスク履歴一覧が0件のため出力しない")
return

prior_columns = [
"project_id",
"task_id",
"task_history_id",
"phase",
"phase_stage",
"started_datetime",
"ended_datetime",
"user_id",
"username",
"worktime_hour",
]

df = df.sort_values(["task_id", "started_datetime"])
required_columns = self._create_required_columns(df, prior_columns, dropped_columns)
self._write_csv(f"{self.short_project_id}-タスク履歴list.csv", df[required_columns])

def write_member_list(self, df: pd.DataFrame, dropped_columns: List[str] = None):
"""
プロジェクトメンバ一覧をTSVで出力する
Expand Down
2 changes: 2 additions & 0 deletions annofabcli/statistics/visualize_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def visualize_statistics(self, project_id: str, work_dir: Path, output_dir: Path
graph_obj = Graph(str(output_dir), project_id)

task_df = table_obj.create_task_df()
task_history_df = table_obj.create_task_history_df()
inspection_df = table_obj.create_inspection_df()
inspection_df_all = table_obj.create_inspection_df(only_error_corrected=False)

Expand All @@ -76,6 +77,7 @@ def visualize_statistics(self, project_id: str, work_dir: Path, output_dir: Path

try:
tsv_obj.write_task_list(task_df, dropped_columns=["histories_by_phase", "input_data_id_list"])
tsv_obj.write_task_history_list(task_history_df)
tsv_obj.write_inspection_list(df=inspection_df, dropped_columns=["data"], only_error_corrected=True)
tsv_obj.write_inspection_list(df=inspection_df_all, dropped_columns=["data"], only_error_corrected=False)

Expand Down

0 comments on commit 14f81c1

Please sign in to comment.