Skip to content

Commit

Permalink
statistics visualize : 実績作業時間あたりの生産性の算出方法を変更する (#1133)
Browse files Browse the repository at this point in the history
* 計測作業時間の実際の値を出力

* 不要な設定を廃止

* update

* format

* 微修正

* 計測作業時間を出力

* update test data

* 修正

* 実績作業時間の修正

* 標準偏差を出す
  • Loading branch information
yuji38kwmt authored Feb 14, 2024
1 parent 6b1023a commit 177b297
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 143 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Dataframe",
"dateutil",
"ddof",
"Downcasting",
"dropna",
"dryrun",
"dtype",
Expand Down
24 changes: 2 additions & 22 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@
"ruff.path": [
".venv/bin/ruff"
],
"python.formatting.blackPath": ".venv/bin/black",
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": ".venv/bin/pylint",
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": ".venv/bin/mypy",
"python.linting.mypyArgs": [],
"python.linting.banditEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.prospectorEnabled": false,
"python.linting.pydocstyleEnabled": false,
"python.linting.pycodestyleEnabled": false,
"python.linting.ignorePatterns": [
".vscode/*.py",
"**/site-packages/**/*.py",
"docs/**/*.py",
"tests/**/*.py",
],
"python.analysis.extraPaths": [
".venv/lib/python3.11/site-packages/"
],
Expand All @@ -49,8 +29,8 @@
".devcontainer/venv/": true
},
"editor.minimap.enabled": false,
"ruff.args": [
"ruff.lint.args": [
"--config=pyproject.toml"
],

}
234 changes: 208 additions & 26 deletions annofabcli/statistics/visualization/dataframe/user_performance.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, df: pandas.DataFrame) -> None:

_df_dtype = {
"date": "string",
"account_id": "string",
"user_id": "string",
"username": "string",
"biography": "string",
Expand Down Expand Up @@ -244,7 +245,7 @@ def _get_cumulative_dataframe(df: pandas.DataFrame) -> pandas.DataFrame:
def merge(cls, obj1: WorktimePerDate, obj2: WorktimePerDate) -> WorktimePerDate:
df_tmp = pandas.concat([obj1.df, obj2.df])

df = df_tmp.groupby(["date", "user_id"])[
df = df_tmp.groupby(["date", "account_id"])[
[
"actual_worktime_hour",
"monitored_worktime_hour",
Expand All @@ -255,9 +256,9 @@ def merge(cls, obj1: WorktimePerDate, obj2: WorktimePerDate) -> WorktimePerDate:
].sum()
df.reset_index(inplace=True)

df_user = df_tmp.drop_duplicates(subset="user_id")[["user_id", "username", "biography"]]
df_user = df_tmp.drop_duplicates(subset="account_id")[["account_id", "user_id", "username", "biography"]]

df = df.merge(df_user, on="user_id", how="left")
df = df.merge(df_user, on="account_id", how="left")

return cls(df)

Expand Down
19 changes: 13 additions & 6 deletions annofabcli/statistics/visualize_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def get_project_output_dir(project_title: str) -> str:


class WriteCsvGraph:
task_df: Optional[pandas.DataFrame] = None
task_history_df: Optional[pandas.DataFrame] = None

def __init__(
self,
service: annofabapi.Resource,
Expand All @@ -81,6 +78,10 @@ def __init__(

self.project_dir = ProjectDir(output_dir)

self.task_df: Optional[pandas.DataFrame] = None
self.task_history_df: Optional[pandas.DataFrame] = None
self.worktime_per_date: Optional[WorktimePerDate] = None

def _catch_exception(self, function: Callable[..., Any]) -> Callable[..., Any]:
"""
Exceptionをキャッチしてログにstacktraceを出力する。
Expand All @@ -105,6 +106,13 @@ def _get_task_history_df(self) -> pandas.DataFrame:
self.task_history_df = self.table_obj.create_task_history_df()
return self.task_history_df

def _get_worktime_per_date(self) -> WorktimePerDate:
if self.worktime_per_date is None:
self.worktime_per_date = WorktimePerDate.from_webapi(
self.service, self.project_id, self.df_labor, start_date=self.start_date, end_date=self.end_date
)
return self.worktime_per_date

def write_task_info(self) -> None:
"""
タスクに関するヒストグラムを出力する。
Expand Down Expand Up @@ -136,6 +144,7 @@ def write_user_performance(self) -> None:
df_task_history=df_task_history,
df_worktime_ratio=annotation_count_ratio_df,
df_user=df_user,
df_worktime_per_date=self._get_worktime_per_date().df,
df_labor=self.df_labor,
)

Expand Down Expand Up @@ -168,9 +177,7 @@ def write_cumulative_linegraph_by_user(self, user_id_list: Optional[List[str]] =

def write_worktime_per_date(self, user_id_list: Optional[List[str]] = None) -> None:
"""日ごとの作業時間情報を出力する。"""
worktime_per_date_obj = WorktimePerDate.from_webapi(
self.service, self.project_id, self.df_labor, start_date=self.start_date, end_date=self.end_date
)
worktime_per_date_obj = self._get_worktime_per_date()

self.project_dir.write_worktime_per_date_user(worktime_per_date_obj)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
date,user_id,username,biography,actual_worktime_hour,monitored_worktime_hour,monitored_annotation_worktime_hour,monitored_inspection_worktime_hour,monitored_acceptance_worktime_hour
2021-11-01,AE,AE,category-KK,3,2.35747638888889,2.35747638888889,0,0
2021-11-01,OW,OW,category-KT,5.16666666666667,4.37651388888889,3.43365333333333,0,0.942860555555555
2021-11-01,KX,KX,category-KT,3.75,1.61257861111111,1.61257861111111,0,0
2021-11-02,AE,AE,category-KK,2.5,2.33247083333333,2.33247083333333,0,0
2021-11-02,OW,OW,category-KT,4.83333333333333,4.56632861111111,4.14881194444445,0,0.417516666666667
2021-11-02,KX,KX,category-KT,0,1.71704527777778,1.71704527777778,0,0
2021-11-02,EM,EM,category-KT,0,1.59044583333333,0.1913825,0,1.39906333333333
2021-11-03,EM,EM,category-KT,3,0.846563611111111,0.846563611111111,0,0
2021-11-04,AE,AE,category-KK,2,1.90333416666667,1.90333416666667,0,0
2021-11-04,OW,OW,category-KT,5.5,5.42994055555556,3.75310444444445,0,1.67683611111111
2021-11-04,KX,KX,category-KT,2,1.61104777777778,1.61104777777778,0,0
2021-11-04,EM,EM,category-KT,3.75,4.790775,3.73020194444444,0,1.06057305555556
2021-11-05,AE,AE,category-KK,1,1.0133925,1.0133925,0,0
2021-11-05,OW,OW,category-KT,5.16666666666667,5.04375055555556,3.25301527777778,0,1.79073527777778
2021-11-05,KX,KX,category-KT,2.5,0.902265833333333,0.902265833333333,0,0
date,account_id,user_id,username,biography,actual_worktime_hour,monitored_worktime_hour,monitored_annotation_worktime_hour,monitored_inspection_worktime_hour,monitored_acceptance_worktime_hour
2021-11-01,AE,AE,AE,category-KK,3,2.357476389,2.357476389,0,0
2021-11-01,OW,OW,OW,category-KT,5.166666667,4.376513889,3.433653333,0,0.942860556
2021-11-01,KX,KX,KX,category-KT,3.75,1.612578611,1.612578611,0,0
2021-11-02,AE,AE,AE,category-KK,2.5,2.332470833,2.332470833,0,0
2021-11-02,OW,OW,OW,category-KT,4.833333333,4.566328611,4.148811944,0,0.417516667
2021-11-02,KX,KX,KX,category-KT,0,1.717045278,1.717045278,0,0
2021-11-02,EM,EM,EM,category-KT,0,1.590445833,0.1913825,0,1.399063333
2021-11-03,EM,EM,EM,category-KT,3,0.846563611,0.846563611,0,0
2021-11-04,AE,AE,AE,category-KK,2,1.903334167,1.903334167,0,0
2021-11-04,OW,OW,OW,category-KT,5.5,5.429940556,3.753104444,0,1.676836111
2021-11-04,KX,KX,KX,category-KT,2,1.611047778,1.611047778,0,0
2021-11-04,EM,EM,EM,category-KT,3.75,4.790775,3.730201944,0,1.060573056
2021-11-05,AE,AE,AE,category-KK,1,1.0133925,1.0133925,0,0
2021-11-05,OW,OW,OW,category-KT,5.166666667,5.043750556,3.253015278,0,1.790735278
2021-11-05,KX,KX,KX,category-KT,2.5,0.902265833,0.902265833,0,0
Loading

0 comments on commit 177b297

Please sign in to comment.