From 4ddb6f051ffd46addd6a5e07959b851ed92a0817 Mon Sep 17 00:00:00 2001 From: NY Date: Fri, 14 Mar 2025 16:22:00 +0800 Subject: [PATCH] +probability(debug&test) --- pkg/dash/func/info_test.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/dash/func/info_test.py b/pkg/dash/func/info_test.py index 92c7669..f6caa0e 100644 --- a/pkg/dash/func/info_test.py +++ b/pkg/dash/func/info_test.py @@ -53,17 +53,19 @@ def update_test_info(n_clicks, test_date, test_time): return [html.Div("Invalid date or time format. Use YYYY-MM-DD and HH:MM:SS (e.g., 12:00:00).")] # 计算周期开始时间(上一个周五 12:00 PM) - test_date_only = test_datetime.replace(hour=0, minute=0, second=0, microsecond=0) # 只考虑日期部分 - days_to_last_friday = (test_date_only.weekday() - 4) % 7 # 4 表示周五 - cycle_start = test_date_only - timedelta(days=days_to_last_friday) - cycle_start = cycle_start.replace(hour=12, minute=0, second=0, microsecond=0) # 已经是 tz-aware,直接调整时间 + days_since_last_friday = (test_datetime.weekday() - 4) % 7 # 4 表示周五 + cycle_start = test_datetime - timedelta(days=days_since_last_friday) + cycle_start = cycle_start.replace(hour=12, minute=0, second=0, microsecond=0) # 确保周期结束时间(下周五 12:00 PM EDT)考虑夏令时 cycle_end = cycle_start + timedelta(days=7) - if cycle_end.month == 3 and 8 <= cycle_end.day <= 14: # 粗略检查夏令时开始(3月第二个星期日) - cycle_end = cycle_end.tz_convert(est) # 转换为 EDT + # 精确计算夏令时开始(2025年3月9日,第二个星期日) + first_day = cycle_end.replace(day=1) + second_sunday = first_day + timedelta(days=((6 - first_day.weekday()) % 7) + 7) + if cycle_end.month == 3 and cycle_end >= second_sunday.replace(hour=2): + cycle_end = cycle_end.tz_convert(est) # EDT else: - cycle_end = cycle_end.tz_convert(est) # 保持一致 + cycle_end = cycle_end.tz_convert(est) # EST 或 EDT # 调试:打印周期信息 print(f"Cycle Start: {cycle_start}, Cycle End: {cycle_end}") @@ -92,9 +94,11 @@ def update_test_info(n_clicks, test_date, test_time): prob_min, prob_max = map(float, probability.split(" - ")) formatted_probability = f"{prob_min * 100:.2f}% - {prob_max * 100:.2f}%" - # 构建测试结果表格 + # 构建测试结果表格(包含 Cycle End) test_table_rows = [ html.Tr([html.Th("Test Date and Time:", colSpan=2), html.Td(str(test_datetime), colSpan=6)]), + html.Tr([html.Th("Cycle Start:", colSpan=2), html.Td(str(cycle_start), colSpan=6)]), + html.Tr([html.Th("Cycle End:", colSpan=2), html.Td(str(cycle_end), colSpan=6)]), html.Tr([html.Th("Tweet Count at Test Time:", colSpan=2), html.Td(str(tweet_count), colSpan=6)]), html.Tr([html.Th("Actual Final Tweet Count:", colSpan=2), html.Td(str(actual_end_count), colSpan=6)]), html.Tr([html.Th(f"Predicted Range ({int(prob_start)}-{int(prob_end)}):", colSpan=2), html.Td(formatted_probability, colSpan=6)]),