From 1e46faa2739f50e32ae897a2bc768ab23350b689 Mon Sep 17 00:00:00 2001 From: wangxu <1318272526@qq.com> Date: Wed, 6 May 2026 19:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=9B=B8=E5=AF=B9=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E4=B8=BA=E5=8D=95=E4=BD=8D=E5=B0=8F=E6=97=B6=E6=B5=81?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common_worker.py | 12 +++++++++++- app/monitor_common.py | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/common_worker.py b/app/common_worker.py index b6edbe2..db0041c 100644 --- a/app/common_worker.py +++ b/app/common_worker.py @@ -576,4 +576,14 @@ def load_road_mapping(mapping_file: str): # 忽略crossid映射 continue # 输出道路个数 - print(f"road_mapping_count: {len(g_road_mapping)}") \ No newline at end of file + print(f"road_mapping_count: {len(g_road_mapping)}") + + +def get_hours(start_str, end_str): + # 分别提取小时和分钟并转为整数 + start_h, start_m = map(int, start_str.split(':')) + end_h, end_m = map(int, end_str.split(':')) + + # 直接相减计算总小时数 + total_hours = (end_h - start_h) + (end_m - start_m) / 60 + return total_hours diff --git a/app/monitor_common.py b/app/monitor_common.py index 546137c..45251ca 100644 --- a/app/monitor_common.py +++ b/app/monitor_common.py @@ -401,16 +401,22 @@ def parse_cross_index_dict(delay_index_list, special_time_range, routing_crosses user_favorite_crosses = db_workstation.query_favorite_crosses(userid, nodeid, area_id) user_favorite_crosses = [item['favorite_id'] for item in user_favorite_crosses] cross_week_flow_dict = {} + # 20260506 调整相对流量计算单位为单位小时流量 for delay_index in delay_index_list: crossid = delay_index.crossid + start_hm = delay_index.tp.start_hm + end_hm = delay_index.tp.end_hm + start_time, end_time = convert_time(start_hm), convert_time(end_hm) + hours = get_hours(start_time, end_time) if crossid not in routing_crosses_dict.keys(): continue weekdays = parse_wd_bitmap(delay_index.tp.weekday) key = '%s_%s' % (weekdays, crossid) + hour_flow = delay_index.delay_info.car_num / hours if hours > 0 else 0 if key not in cross_week_flow_dict.keys(): - cross_week_flow_dict[key] = delay_index.delay_info.car_num - if key in cross_week_flow_dict.keys() and delay_index.delay_info.car_num > cross_week_flow_dict[key]: - cross_week_flow_dict[key] = delay_index.delay_info.car_num + cross_week_flow_dict[key] = hour_flow + if key in cross_week_flow_dict.keys() and hour_flow > cross_week_flow_dict[key]: + cross_week_flow_dict[key] = hour_flow for delay_index in delay_index_list: crossid = delay_index.crossid if crossid not in routing_crosses_dict.keys(): @@ -421,6 +427,7 @@ def parse_cross_index_dict(delay_index_list, special_time_range, routing_crosses if special_time_range != '' and not is_overlap_greater_than_one_hour(start_hm, end_hm, special_time_range): continue start_time, end_time = convert_time(start_hm), convert_time(end_hm) + hours = get_hours(start_time, end_time) weekdays = parse_wd_bitmap(delay_index.tp.weekday) weekdays_str = gen_week_str({'weekday': weekdays}) if date_type in ('weekend', 'workday'): @@ -439,7 +446,8 @@ def parse_cross_index_dict(delay_index_list, special_time_range, routing_crosses if weekdays not in res[crossid]['delay_infos'].keys(): res[crossid]['delay_infos'][weekdays] = [] is_peak = 0 if not time_overlap(start_time + '-' + end_time, peak_tp) else 1 - relative_flow_rate = round(delay_index.delay_info.car_num / cross_week_flow_dict[weekdays + '_' + crossid], 2) if weekdays + '_' + crossid in cross_week_flow_dict.keys() and cross_week_flow_dict[weekdays + '_' + crossid] > 0 else 0 + item_hour_flow = delay_index.delay_info.car_num / hours if hours > 0 else 0 + relative_flow_rate = round(item_hour_flow / cross_week_flow_dict[weekdays + '_' + crossid], 2) if weekdays + '_' + crossid in cross_week_flow_dict.keys() and cross_week_flow_dict[weekdays + '_' + crossid] > 0 else 0 delay_info = { 'start_time': start_time, 'end_time': end_time if end_time != '24:00' else '23:59',