From aeb401443663f2e67c8c7d16fb058793066f18ff Mon Sep 17 00:00:00 2001 From: kuangjianjun Date: Thu, 5 Feb 2026 12:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BF=9D=E5=AD=98xx=E5=A4=A9?= =?UTF-8?q?xx=E5=B0=8F=E6=97=B6xx=E5=88=86=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- predict_with_excel.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/predict_with_excel.py b/predict_with_excel.py index de3c3e7..13ec5b6 100644 --- a/predict_with_excel.py +++ b/predict_with_excel.py @@ -316,6 +316,37 @@ def get_welding_time(row): return welding_time +def minutes_to_dhm_format(minutes): + """ + 将分钟数转换为 "xx天xx小时xx分钟" 的字符串格式 + + Args: + minutes: 分钟数(浮点数) + + Returns: + 格式化的字符串,例如:"2天5小时30分钟" + """ + if pd.isna(minutes) or not isinstance(minutes, (int, float)): + return "0分钟" + + total_minutes = int(round(minutes)) + + days = total_minutes // (24 * 60) + remaining = total_minutes % (24 * 60) + hours = remaining // 60 + mins = remaining % 60 + + parts = [] + if days > 0: + parts.append(f"{days}天") + if hours > 0: + parts.append(f"{hours}小时") + if mins > 0 or len(parts) == 0: # 如果没有天和小时,至少显示分钟 + parts.append(f"{mins}分钟") + + return "".join(parts) + + def save_df_to_excel(df, output_file_path): df.to_excel(output_file_path, index=False) @@ -345,7 +376,8 @@ def build_prediction_dataframe(df: pd.DataFrame) -> pd.DataFrame: total_row = {col: np.nan for col in df_without_last.columns} total_row["序号"] = "总计" - total_row["焊接工时"] = df_without_last["焊接工时"].sum() + total_minutes = df_without_last["焊接工时"].sum() + total_row["焊接工时"] = minutes_to_dhm_format(total_minutes) result_df = pd.concat([df_without_last, pd.DataFrame([total_row])], ignore_index=True) return result_df