Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics visualize : 集計対象タスクが0件でもエラーがでないようにする #1153

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion annofabcli/statistics/visualization/dataframe/task_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,25 @@ def from_api_response(cls, task_histories: dict[str, list[dict[str, Any]]]) -> T
)
all_task_history_list.append(new_task_history)

df = pandas.DataFrame(all_task_history_list)
if len(all_task_history_list) > 0:
df = pandas.DataFrame(all_task_history_list)
else:
df = cls.empty()

return cls(df)

@classmethod
def empty(cls) -> TaskHistory:
"""空のデータフレームを持つインスタンスを生成します。"""

df_dtype: dict[str, str] = {
"project_id": "string",
"task_id": "string",
"phase": "string",
"phase_stage": "int",
"account_id": "string",
"worktime_hour": "float64",
}

df = pandas.DataFrame(columns=cls.columns).astype(df_dtype)
return cls(df)
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def from_df_wrapper(
"""
df_task = task.df
df_worktime_ratio = cls._create_annotation_count_ratio_df(task_history.df, task.df)
if len(df_worktime_ratio) == 0:
return cls.empty()

df = df_worktime_ratio.merge(user.df, on="account_id", how="left")
df = df.merge(df_task[["task_id", "status"]], on="task_id", how="left")
df["project_id"] = project_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def _create_df_working_period(worktime_per_date: WorktimePerDate) -> pandas.Data
# joinしない理由: レベル1の列名が空文字のDataFrameをjoinすると、Python3.12のpandas2.2.0で、列名が期待通りにならないため
# https://github.com/pandas-dev/pandas/issues/57500
# return df2.join(df3)
return pandas.concat([df2,df3], axis=1)
return pandas.concat([df2, df3], axis=1)

@staticmethod
def _create_df_user(worktime_per_date: WorktimePerDate) -> pandas.DataFrame:
Expand Down