From a3eff701623d82a6412f0e83628ce21be4d0f9ef Mon Sep 17 00:00:00 2001 From: wangxu <1318272526@qq.com> Date: Tue, 4 Nov 2025 15:12:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E9=AA=8C=E8=AF=81=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E8=B6=8B=E5=8A=BF=E6=8E=A5=E5=8F=A3=E4=B8=AD?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E6=B5=81=E9=87=8F=E6=95=B0=E6=8D=AE=E7=9A=84?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/cross_evaluate_worker.py | 22 +++++++++--- app/eva_common.py | 68 ++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/app/cross_evaluate_worker.py b/app/cross_evaluate_worker.py index 46fb5f2..1596443 100644 --- a/app/cross_evaluate_worker.py +++ b/app/cross_evaluate_worker.py @@ -332,15 +332,21 @@ def query_cross_examine_records_detail(params): dir_str_dict = { 'E': '东', 'S': '南', 'W': '西', 'N': '北', 'NE': '东北', 'SE': '东南', 'SW': '西南', 'NW': '西北' } + if not cross_examine_records: + return json.dumps(make_common_res(10, '当前路口在所选时段无异常情况')) + final_state, level_color, first_date = 0, 0, '' + tp_start, tp_end = '', '' for row in cross_examine_records: - final_state = row['final_state'] - level_color = row['level_color'] - first_date = row['first_date'] - if final_state == 6 or level_color == 4: + if row['final_state'] == 6 or row['level_color'] == 4: continue + final_state = row['final_state'] + first_date = row['first_date'] + level_color = row['level_color'] date_list = generate_date_range(first_date, prev_day) phase_types = row['phase_type'] phase_details = row['phase_detail'] + tp_start = convert_time(row['start_hm']) + tp_end = convert_time(row['end_hm']) phase_type_list = phase_types.split('^') phase_detail_list = phase_details.split('^') for i in range(len(date_list)): @@ -366,7 +372,13 @@ def query_cross_examine_records_detail(params): phase_type_dir_dict[int(item_type)].append(item_detail) days_records[date] = phase_type_dir_dict res = make_common_res(0, 'ok') - res['data'] = days_records + res['data'] = { + 'days_records': days_records, + 'final_state': final_state, + 'level_color': level_color, + 'first_date': first_date, + 'time_range': tp_start + '-' + tp_end if tp_start != '' else '', + } return json.dumps(res, ensure_ascii=False) diff --git a/app/eva_common.py b/app/eva_common.py index 3d9a158..1a4301f 100644 --- a/app/eva_common.py +++ b/app/eva_common.py @@ -774,10 +774,10 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d key = day item_cross_delay_info = item['data'] - # 指标内容依次是 停车次数 多次停车率 停车时间 延误时间 平均速度 不停车速度 相对流量 路口失衡系数 潮汐指数 服务水平 - overview_data = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', + # 指标内容依次是 停车次数 多次停车率 停车时间 延误时间 平均速度 不停车速度 相对流量 (20251104新增流量真实数值需求) 路口失衡系数 潮汐指数 服务水平 + overview_data = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', # 下方为上述指标变化率颜色展示flag - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] tide_index = calc_tide_index(crossid, nodeid, [day], roads_dir_dict, date_type='week' if data_type == 'week' else None) if data_type != 'hour' else '-' road_data_dict = {} cross_car_num = 0 @@ -799,10 +799,12 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d item_cross_delay_info.delay_info.delay_time, item_cross_delay_info.delay_info.speed / 100, # 不停车速度 相对流量占比 item_cross_delay_info.delay_info.move_speed / 100, round(cross_car_num / max_cross_car_num * 100, 2) if max_cross_car_num != 0 else 0, + # 20251104新增流量真实数值需求 + cross_car_num, # 路口失衡系数 潮汐指数(当为小时级指标时,不计算该值) 服务水平 cross_imbalance_index, tide_index[0], calc_service_level(item_cross_delay_info.delay_info.delay_time), # 指标变化率颜色展示flag, 不含服务水平 - 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] inroad_delay_infos_with_imbalance = calc_inroad_imbalance_index(road_delay_infos) road_data_dict = {item.inroadid: item for item in inroad_delay_infos_with_imbalance} @@ -831,12 +833,14 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d road_data_dict[roads_dir_dict[src_dir]['in']].delay_info.move_speed / 100, # 相对流量占比 round(road_car_num / max_road_car_num * 100, 2) if max_road_car_num > 0 else '-', + # 20251104新增流量真实数值需求 + road_car_num, # 进口道流量占比 round(road_car_num / cross_car_num * 100, 2) if cross_car_num > 0 else '-', # 服务水平 calc_service_level(road_data_dict[roads_dir_dict[src_dir]['in']].delay_info.delay_time), # 指标变化率颜色展示flag, 顺序为上述指标顺序, 不含服务水平 - 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] flow_delay_infos = road_data_dict[roads_dir_dict[src_dir]['in']].flow_delay_infos flow_data_dict = {} @@ -859,12 +863,14 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d flow_delay_info.delay_info.move_speed / 100, # 相对流量 round(flow_delay_info.delay_info.car_num / max_flow_car_num * 100, 2) if max_flow_car_num > 0 else '-', + # 20251104新增流量真实数值需求 + flow_delay_info.delay_info.car_num, # 分流转向占比 round(flow_delay_info.delay_info.car_num / road_car_num * 100, 2) if road_car_num > 0 else '-', # 服务水平 calc_service_level(flow_delay_info.delay_info.delay_time), # 指标变化率颜色展示flag 不含服务水平 - 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0 ] flow_data_dict[turn_type] = flow_data data_dict[key]['roads_data'][src_dir] = { @@ -877,9 +883,9 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d def calc_single_day_delay_info_change_rate(data_dict): res_data_dict = copy.deepcopy(data_dict) key_list = list(res_data_dict.keys()) - empty_overview = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', + empty_overview = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', # 指标变化率颜色展示flag - 0, 0, 0, 0, 0, 0, 0, 0, 0] + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for i in range(len(key_list)-1, -1, -1): overview_data = res_data_dict[key_list[i]]['overview'] # list roads_data = res_data_dict[key_list[i]]['roads_data'] # dict 内部包含多个方向路段和各个方向路段的流向级别的数据 @@ -898,29 +904,29 @@ def calc_single_day_delay_info_change_rate(data_dict): def calc_overview_change_rate(overview_data, prev_overview_data): res_data = copy.copy(overview_data) for i in range(len(overview_data)): - if i >= 9: + if i >= 10: continue if overview_data[i] == '-' or prev_overview_data[i] == '-': - res_data[i + 10] = 0 + res_data[i + 11] = 0 # 变化率 0表示正常 1表示恶化 2表示优化 - if i in (0, 1, 2, 3, 6, 7, 8): - # 指标提升代表恶化的有停车次数、多次停车率、转向失衡指数、停车时间、延误时间、相对流量、进口道流量占比 + if i in (0, 1, 2, 3, 6, 7, 8, 9): + # 指标提升代表恶化的有停车次数、多次停车率、转向失衡指数、停车时间、延误时间、相对流量、20251104新增流量真实数值需求、进口道流量占比 if overview_data[i] == '-' or prev_overview_data[i] == '-': continue rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0 if rate < -20: - res_data[i + 10] = 2 + res_data[i + 11] = 2 elif rate > 20: - res_data[i + 10] = 1 + res_data[i + 11] = 1 else: # 指标下降代表恶化的有平均速度、不停车速度 if overview_data[i] == '-' or prev_overview_data[i] == '-': continue rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0 if rate > 20: - res_data[i + 10] = 2 + res_data[i + 11] = 2 elif rate < -20: - res_data[i + 10] = 1 + res_data[i + 11] = 1 return res_data @@ -932,26 +938,26 @@ def calc_roads_data_change_rate(roads_data, prev_roads_data): src_dir_road_data = res_data[src_dir]['road'] if src_dir not in prev_roads_data.keys(): continue - # 指标提升代表恶化的有停车次数、多次停车率、停车时间、延误时间、相对流量、分流转向占比 + # 指标提升代表恶化的有停车次数、多次停车率、停车时间、延误时间、相对流量、20251104新增流量真实数值需求、分流转向占比 prev_src_dir_road_data = prev_roads_data[src_dir]['road'] for i in range(len(src_dir_road_data)): - if i >= 9: + if i >= 10: continue if src_dir_road_data[i] == '-' or prev_src_dir_road_data[i] == '-': - src_dir_road_data[i + 10] = 0 - if i in (0, 1, 2, 3, 4, 7, 8): + src_dir_road_data[i + 11] = 0 + if i in (0, 1, 2, 3, 4, 7, 8, 9): rate = (src_dir_road_data[i] - prev_src_dir_road_data[i]) / prev_src_dir_road_data[i] * 100 if prev_src_dir_road_data[i] > 0 else 0 if rate < -20: - src_dir_road_data[i + 10] = 2 + src_dir_road_data[i + 11] = 2 elif rate > 20: - src_dir_road_data[i + 10] = 1 + src_dir_road_data[i + 11] = 1 else: # 指标下降代表恶化的有平均速度、不停车速度 rate = (src_dir_road_data[i] - prev_src_dir_road_data[i]) / prev_src_dir_road_data[i] * 100 if prev_src_dir_road_data[i] > 0 else 0 if rate > 20: - src_dir_road_data[i + 10] = 2 + src_dir_road_data[i + 11] = 2 elif rate < -20: - src_dir_road_data[i + 10] = 1 + src_dir_road_data[i + 11] = 1 flow_datas = res_data[src_dir]['flow'] prev_flow_datas = prev_roads_data[src_dir]['flow'] for turn_type in flow_datas.keys(): @@ -960,22 +966,22 @@ def calc_roads_data_change_rate(roads_data, prev_roads_data): continue prev_flow_data = prev_flow_datas[turn_type] for i in range(len(flow_data)): - if i >= 8: + if i >= 9: continue if flow_data[i] == '-' or prev_flow_data[i] == '-': flow_data[i + 9] = 0 - if i in (0, 1, 2, 3, 6, 7): + if i in (0, 1, 2, 3, 6, 7, 8): rate = (flow_data[i] - prev_flow_data[i]) / prev_flow_data[i] * 100 if prev_flow_data[i] > 0 else 0 if rate < -20: - flow_data[i + 9] = 2 + flow_data[i + 10] = 2 elif rate > 20: - flow_data[i + 9] = 1 + flow_data[i + 10] = 1 else: rate = (flow_data[i] - prev_flow_data[i]) / prev_flow_data[i] * 100 if prev_flow_data[i] > 0 else 0 if rate > 20: - flow_data[i + 9] = 2 + flow_data[i + 10] = 2 elif rate < -20: - flow_data[i + 9] = 1 + flow_data[i + 10] = 1 return res_data @@ -1429,7 +1435,7 @@ def gen_phase_problems(nodeid, area_id, crossid, time_range, date_list, min_date 'total_num': 0 } phase_problems_detail, err = QueryCrossPhaseDiagnosis(int(nodeid), crossid, [str(item) for item in date_list], time_range, int(area_id)) - if not err: + if not err and phase_problems_detail: phase_problems = phase_problems_detail phase_err_detail, phase_err_suggestions, phase_err_total_num = gen_err_phase_problems(start_hm, max_date, crossid, min_date) if len(phase_err_suggestions) > 0: