Suhsiung Claude Opus 4.8 commited on
Commit
e4dc730
·
1 Parent(s): 4c2d4b7

修正:報告時間統一為台灣時區 (UTC+8)

Browse files

新增 now_tw() helper,將全部 6 處時間戳改用台灣時間,
避免雲端伺服器 (UTC) 與本地時間相差 8 小時。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. app_agent.py +13 -7
app_agent.py CHANGED
@@ -25,7 +25,13 @@ if sys.platform.startswith("win"):
25
  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
26
  sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
27
  from pathlib import Path
28
- from datetime import datetime
 
 
 
 
 
 
29
  from collections import Counter
30
 
31
  import numpy as np
@@ -793,7 +799,7 @@ def run_indicator_calculation(file_paths: list, output_dir: Path, resources: dic
793
  print(f" 計算 {fp} 時發生錯誤:{e}")
794
  traceback.print_exc()
795
 
796
- timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
797
  xlsx_path = output_dir / f"textIndex_calculated_1_{timestamp}.xlsx"
798
  csv_path = output_dir / "textIndex_calculated.csv"
799
  result_df.to_excel(str(xlsx_path), index=False)
@@ -1063,7 +1069,7 @@ def run_statistical_analysis(csv_path: Path, output_dir: Path):
1063
  df[result_cols].to_csv(str(cluster_csv_path), index=False, encoding='utf-8-sig')
1064
 
1065
  # ── 6. 產出 docx 技術報告 ──────────────────────────────────────────────────
1066
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
1067
  report_path = output_dir / f"Final_Report-{timestamp}.docx"
1068
  doc = Document()
1069
  style = doc.styles['Normal']
@@ -1072,7 +1078,7 @@ def run_statistical_analysis(csv_path: Path, output_dir: Path):
1072
 
1073
  title = doc.add_heading('重譯分析技術報告', level=0)
1074
  title.alignment = WD_ALIGN_PARAGRAPH.CENTER
1075
- doc.add_paragraph(f'報告產出時間:{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}',
1076
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1077
  doc.add_paragraph(f'分析文本數:{df.shape[0]} 筆',
1078
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
@@ -1278,7 +1284,7 @@ def run_report_writing(scenario_key: str, user_metadata: str, user_focus: str,
1278
 
1279
  result_text = call_main_agent(system_prompt, user_prompt)
1280
 
1281
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
1282
  docx_path = output_dir / f"LLM_Analysis-{timestamp}.docx"
1283
  txt_path = output_dir / f"LLM_Analysis-{timestamp}.txt"
1284
 
@@ -1291,7 +1297,7 @@ def run_report_writing(scenario_key: str, user_metadata: str, user_focus: str,
1291
  heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
1292
  doc.add_paragraph(f'研究情境:{scenario_info["title"]}',
1293
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1294
- doc.add_paragraph(f'報告時間:{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}',
1295
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1296
  doc.add_page_break()
1297
  for line in result_text.split('\n'):
@@ -1308,7 +1314,7 @@ def run_report_writing(scenario_key: str, user_metadata: str, user_focus: str,
1308
  # 存 txt
1309
  with open(str(txt_path), 'w', encoding='utf-8') as f:
1310
  f.write(f"研究情境:{scenario_info['title']}\n")
1311
- f.write(f"時間:{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
1312
  f.write("=" * 60 + "\n\n")
1313
  f.write(result_text)
1314
 
 
25
  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
26
  sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
27
  from pathlib import Path
28
+ from datetime import datetime, timezone, timedelta
29
+
30
+ # 台灣時區(UTC+8):確保雲端(UTC 伺服器)與本地時間一致
31
+ TW_TZ = timezone(timedelta(hours=8))
32
+ def now_tw():
33
+ """回傳台灣時間(UTC+8),不受伺服器時區影響。"""
34
+ return datetime.now(TW_TZ)
35
  from collections import Counter
36
 
37
  import numpy as np
 
799
  print(f" 計算 {fp} 時發生錯誤:{e}")
800
  traceback.print_exc()
801
 
802
+ timestamp = now_tw().strftime("%Y%m%d%H%M%S")
803
  xlsx_path = output_dir / f"textIndex_calculated_1_{timestamp}.xlsx"
804
  csv_path = output_dir / "textIndex_calculated.csv"
805
  result_df.to_excel(str(xlsx_path), index=False)
 
1069
  df[result_cols].to_csv(str(cluster_csv_path), index=False, encoding='utf-8-sig')
1070
 
1071
  # ── 6. 產出 docx 技術報告 ──────────────────────────────────────────────────
1072
+ timestamp = now_tw().strftime("%Y%m%d_%H%M%S")
1073
  report_path = output_dir / f"Final_Report-{timestamp}.docx"
1074
  doc = Document()
1075
  style = doc.styles['Normal']
 
1078
 
1079
  title = doc.add_heading('重譯分析技術報告', level=0)
1080
  title.alignment = WD_ALIGN_PARAGRAPH.CENTER
1081
+ doc.add_paragraph(f'報告產出時間:{now_tw().strftime("%Y-%m-%d %H:%M:%S")}(台灣時間)',
1082
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1083
  doc.add_paragraph(f'分析文本數:{df.shape[0]} 筆',
1084
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
 
1284
 
1285
  result_text = call_main_agent(system_prompt, user_prompt)
1286
 
1287
+ timestamp = now_tw().strftime("%Y%m%d_%H%M%S")
1288
  docx_path = output_dir / f"LLM_Analysis-{timestamp}.docx"
1289
  txt_path = output_dir / f"LLM_Analysis-{timestamp}.txt"
1290
 
 
1297
  heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
1298
  doc.add_paragraph(f'研究情境:{scenario_info["title"]}',
1299
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1300
+ doc.add_paragraph(f'報告時間:{now_tw().strftime("%Y-%m-%d %H:%M:%S")}(台灣時間)',
1301
  style='Normal').alignment = WD_ALIGN_PARAGRAPH.CENTER
1302
  doc.add_page_break()
1303
  for line in result_text.split('\n'):
 
1314
  # 存 txt
1315
  with open(str(txt_path), 'w', encoding='utf-8') as f:
1316
  f.write(f"研究情境:{scenario_info['title']}\n")
1317
+ f.write(f"時間:{now_tw().strftime('%Y-%m-%d %H:%M:%S')}(台灣時間)\n")
1318
  f.write("=" * 60 + "\n\n")
1319
  f.write(result_text)
1320