diff --git a/pkg/dash/func/info_test.py b/pkg/dash/func/info_test.py index f6caa0e..cde2dc8 100644 --- a/pkg/dash/func/info_test.py +++ b/pkg/dash/func/info_test.py @@ -52,9 +52,14 @@ def update_test_info(n_clicks, test_date, test_time): print(f"Error parsing date/time: {e}") return [html.Div("Invalid date or time format. Use YYYY-MM-DD and HH:MM:SS (e.g., 12:00:00).")] - # 计算周期开始时间(上一个周五 12:00 PM) - days_since_last_friday = (test_datetime.weekday() - 4) % 7 # 4 表示周五 - cycle_start = test_datetime - timedelta(days=days_since_last_friday) + # 计算周期开始时间(上一个或当前周五 12:00 PM) + test_day_of_week = test_datetime.weekday() # 0 = Monday, 4 = Friday + test_hour = test_datetime.hour + days_since_last_friday = (test_day_of_week - 4) % 7 # 4 表示周五 + if test_hour < 12 and test_day_of_week == 4: # Before 12 PM on Friday + cycle_start = test_datetime - timedelta(days=days_since_last_friday + 7) # Previous Friday + else: + cycle_start = test_datetime - timedelta(days=days_since_last_friday) # Current or next Friday cycle_start = cycle_start.replace(hour=12, minute=0, second=0, microsecond=0) # 确保周期结束时间(下周五 12:00 PM EDT)考虑夏令时 @@ -70,7 +75,7 @@ def update_test_info(n_clicks, test_date, test_time): # 调试:打印周期信息 print(f"Cycle Start: {cycle_start}, Cycle End: {cycle_end}") - # 过滤周期内的数据 + # 过滤周期内的数据(从周期开始到测试时间) cycle_data = data[(data['datetime_est'] >= cycle_start) & (data['datetime_est'] <= test_datetime)] if cycle_data.empty: return [html.Div(f"No data available in cycle from {cycle_start} to {test_datetime}")] @@ -96,22 +101,22 @@ def update_test_info(n_clicks, test_date, test_time): # 构建测试结果表格(包含 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)]), - html.Tr([html.Th("Does Actual Fall in Range?", colSpan=2), + html.Tr([html.Th("Cycle Start:", colSpan=4), html.Td(str(cycle_start), colSpan=6)]), + html.Tr([html.Th("Test Date and Time:", colSpan=4), html.Td(str(test_datetime), colSpan=6)]), + html.Tr([html.Th("Cycle End:", colSpan=4), html.Td(str(cycle_end), colSpan=6)]), + html.Tr([html.Th("Tweet Count at Test Time:", colSpan=4), html.Td(str(tweet_count), colSpan=6)]), + html.Tr([html.Th("Actual Final Tweet Count:", colSpan=4), html.Td(str(actual_end_count), colSpan=6)]), + html.Tr([html.Th(f"Predicted Range ({int(prob_start)}-{int(prob_end)}):", colSpan=4), html.Td(formatted_probability, colSpan=6)]), + html.Tr([html.Th("Does Actual Fall in Range?", colSpan=4), html.Td("Yes" if prob_start <= actual_end_count <= prob_end else "No", colSpan=6, style={'color': 'green' if prob_start <= actual_end_count <= prob_end else 'red'})]) ] if prob_start <= actual_end_count <= prob_end: expected_prob = (prob_max + prob_min) / 2 - test_table_rows.append(html.Tr([html.Th("Expected Probability:", colSpan=2), + test_table_rows.append(html.Tr([html.Th("Expected Probability:", colSpan=4), html.Td(f"~{expected_prob * 100:.2f}% (should be high if model fits)", colSpan=6)])) else: - test_table_rows.append(html.Tr([html.Th("Note:", colSpan=2), + test_table_rows.append(html.Tr([html.Th("Note:", colSpan=4), html.Td("Model prediction does not match actual outcome.", colSpan=6, style={'color': 'red'})])) test_table = html.Table(test_table_rows, style={'width': '100%', 'textAlign': 'left', 'borderCollapse': 'collapse'})