Skip to content

Commit

Permalink
"--labor_csv"の必要な列を定義
Browse files Browse the repository at this point in the history
  • Loading branch information
yuji38kwmt committed Feb 19, 2024
1 parent bf2ee31 commit b9003e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 12 additions & 0 deletions annofabcli/statistics/visualization/dataframe/actual_worktime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ class ActualWorktime:

columns = ["project_id", "date", "account_id", "actual_worktime_hour"]

@staticmethod
def required_columns_exist(df: pandas.DataFrame) -> bool:
"""
必須の列が存在するかどうかを返します。
Returns:
必須の列が存在するかどうか
"""
return len(set(ActualWorktime.columns) - set(df.columns)) == 0

def __init__(self, df: pandas.DataFrame) -> None:
if not self.required_columns_exist(df):
ValueError(f"引数`df`には、{ActualWorktime.columns}の列が必要です。")
self.df = df

def is_empty(self) -> bool:
Expand Down
14 changes: 11 additions & 3 deletions annofabcli/statistics/visualize_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,16 @@ def main(self) -> None:

if args.labor_csv is None:
logger.warning("'--labor_csv'が指定されていないので、実績作業時間に関する情報は出力されません。")

actual_worktime = ActualWorktime.from_csv(args.labor_csv) if args.labor_csv is not None else None
actual_worktime = ActualWorktime.empty()
else:
df_actual_worktime = pandas.read_csv(args.labor_csv)
if not ActualWorktime.required_columns_exist(df_actual_worktime):
logger.error(
"引数`--labor_csv`のCSVには以下の列が存在しないので、終了します。\n"
"`project_id`, `date`, `account_id`, `actual_worktime_hour`"
)
sys.exit(COMMAND_LINE_ERROR_STATUS_CODE)
actual_worktime = ActualWorktime(df_actual_worktime)

with tempfile.TemporaryDirectory() as str_temp_dir:
main_obj = VisualizingStatisticsMain(
Expand Down Expand Up @@ -568,7 +576,7 @@ def parse_args(parser: argparse.ArgumentParser) -> None:
"* date\n"
"* account_id\n"
"* actual_worktime_hour\n"
"* project_id (optional: ``--project_id`` に複数の値を指定したときは必須です) \n"
"* project_id \n"
),
)

Expand Down

0 comments on commit b9003e9

Please sign in to comment.