修改大数据方案验证接口返回值,新增流量变化趋势接口中真实流量数据的返回值
This commit is contained in:
parent
a115eadbec
commit
a3eff70162
|
|
@ -332,15 +332,21 @@ def query_cross_examine_records_detail(params):
|
||||||
dir_str_dict = {
|
dir_str_dict = {
|
||||||
'E': '东', 'S': '南', 'W': '西', 'N': '北', 'NE': '东北', 'SE': '东南', 'SW': '西南', 'NW': '西北'
|
'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:
|
for row in cross_examine_records:
|
||||||
final_state = row['final_state']
|
if row['final_state'] == 6 or row['level_color'] == 4:
|
||||||
level_color = row['level_color']
|
|
||||||
first_date = row['first_date']
|
|
||||||
if final_state == 6 or level_color == 4:
|
|
||||||
continue
|
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)
|
date_list = generate_date_range(first_date, prev_day)
|
||||||
phase_types = row['phase_type']
|
phase_types = row['phase_type']
|
||||||
phase_details = row['phase_detail']
|
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_type_list = phase_types.split('^')
|
||||||
phase_detail_list = phase_details.split('^')
|
phase_detail_list = phase_details.split('^')
|
||||||
for i in range(len(date_list)):
|
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)
|
phase_type_dir_dict[int(item_type)].append(item_detail)
|
||||||
days_records[date] = phase_type_dir_dict
|
days_records[date] = phase_type_dir_dict
|
||||||
res = make_common_res(0, 'ok')
|
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)
|
return json.dumps(res, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -774,10 +774,10 @@ def parse_single_cross_delay_info(crossid, nodeid, data_list, data_type, roads_d
|
||||||
key = day
|
key = day
|
||||||
|
|
||||||
item_cross_delay_info = item['data']
|
item_cross_delay_info = item['data']
|
||||||
# 指标内容依次是 停车次数 多次停车率 停车时间 延误时间 平均速度 不停车速度 相对流量 路口失衡系数 潮汐指数 服务水平
|
# 指标内容依次是 停车次数 多次停车率 停车时间 延误时间 平均速度 不停车速度 相对流量 (20251104新增流量真实数值需求) 路口失衡系数 潮汐指数 服务水平
|
||||||
overview_data = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
|
overview_data = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
|
||||||
# 下方为上述指标变化率颜色展示flag
|
# 下方为上述指标变化率颜色展示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 '-'
|
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 = {}
|
road_data_dict = {}
|
||||||
cross_car_num = 0
|
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.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,
|
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),
|
cross_imbalance_index, tide_index[0], calc_service_level(item_cross_delay_info.delay_info.delay_time),
|
||||||
# 指标变化率颜色展示flag, 不含服务水平
|
# 指标变化率颜色展示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)
|
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}
|
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,
|
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 '-',
|
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 '-',
|
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),
|
calc_service_level(road_data_dict[roads_dir_dict[src_dir]['in']].delay_info.delay_time),
|
||||||
# 指标变化率颜色展示flag, 顺序为上述指标顺序, 不含服务水平
|
# 指标变化率颜色展示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_delay_infos = road_data_dict[roads_dir_dict[src_dir]['in']].flow_delay_infos
|
||||||
flow_data_dict = {}
|
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,
|
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 '-',
|
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 '-',
|
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),
|
calc_service_level(flow_delay_info.delay_info.delay_time),
|
||||||
# 指标变化率颜色展示flag 不含服务水平
|
# 指标变化率颜色展示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
|
flow_data_dict[turn_type] = flow_data
|
||||||
data_dict[key]['roads_data'][src_dir] = {
|
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):
|
def calc_single_day_delay_info_change_rate(data_dict):
|
||||||
res_data_dict = copy.deepcopy(data_dict)
|
res_data_dict = copy.deepcopy(data_dict)
|
||||||
key_list = list(res_data_dict.keys())
|
key_list = list(res_data_dict.keys())
|
||||||
empty_overview = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
|
empty_overview = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
|
||||||
# 指标变化率颜色展示flag
|
# 指标变化率颜色展示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):
|
for i in range(len(key_list)-1, -1, -1):
|
||||||
overview_data = res_data_dict[key_list[i]]['overview'] # list
|
overview_data = res_data_dict[key_list[i]]['overview'] # list
|
||||||
roads_data = res_data_dict[key_list[i]]['roads_data'] # dict 内部包含多个方向路段和各个方向路段的流向级别的数据
|
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):
|
def calc_overview_change_rate(overview_data, prev_overview_data):
|
||||||
res_data = copy.copy(overview_data)
|
res_data = copy.copy(overview_data)
|
||||||
for i in range(len(overview_data)):
|
for i in range(len(overview_data)):
|
||||||
if i >= 9:
|
if i >= 10:
|
||||||
continue
|
continue
|
||||||
if overview_data[i] == '-' or prev_overview_data[i] == '-':
|
if overview_data[i] == '-' or prev_overview_data[i] == '-':
|
||||||
res_data[i + 10] = 0
|
res_data[i + 11] = 0
|
||||||
# 变化率 0表示正常 1表示恶化 2表示优化
|
# 变化率 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] == '-':
|
if overview_data[i] == '-' or prev_overview_data[i] == '-':
|
||||||
continue
|
continue
|
||||||
rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0
|
rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0
|
||||||
if rate < -20:
|
if rate < -20:
|
||||||
res_data[i + 10] = 2
|
res_data[i + 11] = 2
|
||||||
elif rate > 20:
|
elif rate > 20:
|
||||||
res_data[i + 10] = 1
|
res_data[i + 11] = 1
|
||||||
else:
|
else:
|
||||||
# 指标下降代表恶化的有平均速度、不停车速度
|
# 指标下降代表恶化的有平均速度、不停车速度
|
||||||
if overview_data[i] == '-' or prev_overview_data[i] == '-':
|
if overview_data[i] == '-' or prev_overview_data[i] == '-':
|
||||||
continue
|
continue
|
||||||
rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0
|
rate = (overview_data[i] - prev_overview_data[i]) / prev_overview_data[i] * 100 if prev_overview_data[i] > 0 else 0
|
||||||
if rate > 20:
|
if rate > 20:
|
||||||
res_data[i + 10] = 2
|
res_data[i + 11] = 2
|
||||||
elif rate < -20:
|
elif rate < -20:
|
||||||
res_data[i + 10] = 1
|
res_data[i + 11] = 1
|
||||||
return res_data
|
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']
|
src_dir_road_data = res_data[src_dir]['road']
|
||||||
if src_dir not in prev_roads_data.keys():
|
if src_dir not in prev_roads_data.keys():
|
||||||
continue
|
continue
|
||||||
# 指标提升代表恶化的有停车次数、多次停车率、停车时间、延误时间、相对流量、分流转向占比
|
# 指标提升代表恶化的有停车次数、多次停车率、停车时间、延误时间、相对流量、20251104新增流量真实数值需求、分流转向占比
|
||||||
prev_src_dir_road_data = prev_roads_data[src_dir]['road']
|
prev_src_dir_road_data = prev_roads_data[src_dir]['road']
|
||||||
for i in range(len(src_dir_road_data)):
|
for i in range(len(src_dir_road_data)):
|
||||||
if i >= 9:
|
if i >= 10:
|
||||||
continue
|
continue
|
||||||
if src_dir_road_data[i] == '-' or prev_src_dir_road_data[i] == '-':
|
if src_dir_road_data[i] == '-' or prev_src_dir_road_data[i] == '-':
|
||||||
src_dir_road_data[i + 10] = 0
|
src_dir_road_data[i + 11] = 0
|
||||||
if i in (0, 1, 2, 3, 4, 7, 8):
|
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
|
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:
|
if rate < -20:
|
||||||
src_dir_road_data[i + 10] = 2
|
src_dir_road_data[i + 11] = 2
|
||||||
elif rate > 20:
|
elif rate > 20:
|
||||||
src_dir_road_data[i + 10] = 1
|
src_dir_road_data[i + 11] = 1
|
||||||
else:
|
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
|
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:
|
if rate > 20:
|
||||||
src_dir_road_data[i + 10] = 2
|
src_dir_road_data[i + 11] = 2
|
||||||
elif rate < -20:
|
elif rate < -20:
|
||||||
src_dir_road_data[i + 10] = 1
|
src_dir_road_data[i + 11] = 1
|
||||||
flow_datas = res_data[src_dir]['flow']
|
flow_datas = res_data[src_dir]['flow']
|
||||||
prev_flow_datas = prev_roads_data[src_dir]['flow']
|
prev_flow_datas = prev_roads_data[src_dir]['flow']
|
||||||
for turn_type in flow_datas.keys():
|
for turn_type in flow_datas.keys():
|
||||||
|
|
@ -960,22 +966,22 @@ def calc_roads_data_change_rate(roads_data, prev_roads_data):
|
||||||
continue
|
continue
|
||||||
prev_flow_data = prev_flow_datas[turn_type]
|
prev_flow_data = prev_flow_datas[turn_type]
|
||||||
for i in range(len(flow_data)):
|
for i in range(len(flow_data)):
|
||||||
if i >= 8:
|
if i >= 9:
|
||||||
continue
|
continue
|
||||||
if flow_data[i] == '-' or prev_flow_data[i] == '-':
|
if flow_data[i] == '-' or prev_flow_data[i] == '-':
|
||||||
flow_data[i + 9] = 0
|
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
|
rate = (flow_data[i] - prev_flow_data[i]) / prev_flow_data[i] * 100 if prev_flow_data[i] > 0 else 0
|
||||||
if rate < -20:
|
if rate < -20:
|
||||||
flow_data[i + 9] = 2
|
flow_data[i + 10] = 2
|
||||||
elif rate > 20:
|
elif rate > 20:
|
||||||
flow_data[i + 9] = 1
|
flow_data[i + 10] = 1
|
||||||
else:
|
else:
|
||||||
rate = (flow_data[i] - prev_flow_data[i]) / prev_flow_data[i] * 100 if prev_flow_data[i] > 0 else 0
|
rate = (flow_data[i] - prev_flow_data[i]) / prev_flow_data[i] * 100 if prev_flow_data[i] > 0 else 0
|
||||||
if rate > 20:
|
if rate > 20:
|
||||||
flow_data[i + 9] = 2
|
flow_data[i + 10] = 2
|
||||||
elif rate < -20:
|
elif rate < -20:
|
||||||
flow_data[i + 9] = 1
|
flow_data[i + 10] = 1
|
||||||
return res_data
|
return res_data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1429,7 +1435,7 @@ def gen_phase_problems(nodeid, area_id, crossid, time_range, date_list, min_date
|
||||||
'total_num': 0
|
'total_num': 0
|
||||||
}
|
}
|
||||||
phase_problems_detail, err = QueryCrossPhaseDiagnosis(int(nodeid), crossid, [str(item) for item in date_list], time_range, int(area_id))
|
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_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)
|
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:
|
if len(phase_err_suggestions) > 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue