修复部分接口异常,上线问题诊断接口

This commit is contained in:
wangxu 2025-10-30 20:18:58 +08:00
parent bae939f2ca
commit cd4276ad86
7 changed files with 205 additions and 103 deletions

View File

@ -36,10 +36,16 @@ def query_cross_usable_date_api():
def query_cross_delay_info_api():
return query_cross_delay_info_controller(request.json)
@app.route('/api/query_cross_index_trend', methods=['POST'])
def query_cross_index_trend_api():
return query_cross_index_trend_controller(request.json)
@app.route('/api/cross_problems', methods=['POST'])
def cross_problems_api():
return query_cross_problems(request.json)
if __name__ == '__main__':
pass

View File

@ -145,13 +145,15 @@ def query_cross_delay_info_controller(params):
road_flow_delay_infos = gen_road_delay_index(avg_cross_delay_info, roads_dir_dict)
# 路段进出口方向分流比
road_flow_turn_rate = gen_flow_turn_rate_index(avg_cross_delay_info, roads_dir_dict)
next_cross_info = get_next_cross(nodeid, area_id, roads_dir_dict)
res = make_common_res(0, 'ok')
res['data'] = {
'overview': overview_res,
'road_flow_delay_infos': road_flow_delay_infos,
'road_flow_turn_rate': road_flow_turn_rate,
'cross_static_info': cross_static_info,
'ledger_info': cross_ledger_info
'ledger_info': cross_ledger_info,
'next_cross_info': next_cross_info
}
return json.dumps(res, ensure_ascii=False)
@ -186,9 +188,6 @@ def query_cross_problems(params):
if not time_range:
return json.dumps(make_common_res(8, '缺少时段范围,请选择时段范围'))
tp_start = int(str(time_range.split('-')[0]).split(':')[0]) * 100 + int(str(time_range.split('-')[0]).split(':')[1])
# tp_end = int(str(time_range.split('-')[1]).split(':')[0]) * 100 + int(str(time_range.split('-')[1]).split(':')[1])
# if tp_end == 0:
# tp_end = 2400
if query_type == 1:
tp_start = 't' + str(tp_start)
elif query_type == 2:
@ -207,10 +206,13 @@ def query_cross_problems(params):
return json.dumps(make_common_res(10, '查询路口信息失败'))
cross_static_info, cross_ledger_info = gen_cross_static_info(crossid, nodeid, area_id, cross_ledger_info_dict)
roads_dir_dict = gen_road_dir_dict(cross_ledger_info)
cross_phase, err = QueryCrossRunningPhase(nodeid, [crossid], date_list, time_range)
cross_phase, err = QueryCrossRunningPhase(int(nodeid), [crossid], [str(item) for item in date_list], time_range)
if err or not cross_phase or cross_phase.code != 0:
logging.warning("路口未录入配时方案")
gen_cross_problems(crossid, nodeid, date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase, is_peak, cross_ledger_info)
problems = gen_cross_problems(crossid, nodeid, area_id, time_range, tp_start.replace('h', '').replace('t', ''), date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase, is_peak, cross_ledger_info)
res = make_common_res(0, 'ok')
res['data'] = problems
return json.dumps(res, ensure_ascii=False)
# 指标变化趋势接口

View File

@ -31,3 +31,8 @@ class CrossDbHelper(TableDbHelperBase):
"""
return self.do_select(sql)
def query_cross_examine_records(self, start_hm, first_date, crossid, end_date):
sql = """
select * from cross_doctor_matedata.cross_phase_problems_record where crossid = '%s' and start_hm = '%s' and first_date <= %s and (end_date >= '%s' or end_date is null)
""" % (crossid, start_hm, first_date, end_date)
return self.do_select(sql)

View File

@ -11,7 +11,7 @@ from google.protobuf.json_format import MessageToJson
import proto.xlcomm_pb2 as pb
from app.common_worker import *
from proto.phase_grpc import QueryCrossRunningPhase
from proto.phase_grpc import QueryCrossRunningPhase, QueryCrossPhaseDiagnosis
src_reverse = {'N': 'S', 'S': 'N', 'W': 'E', 'E': 'W', 'NE': 'SW', 'SW': 'NE', 'SE': 'NW', 'NW': 'SE'}
@ -501,7 +501,8 @@ def gen_road_dir_dict(cross_ledger_info_dict):
def calc_inroad_imbalance_index(inroad_delay_pb_list):
for item in inroad_delay_pb_list:
tmp_list = copy.deepcopy(inroad_delay_pb_list)
for item in tmp_list:
avg_stop_times = item.delay_info.stop_times
max_stop_times, min_stop_times = 0, 99999
flow_delay_infos = item.flow_delay_infos
@ -512,7 +513,7 @@ def calc_inroad_imbalance_index(inroad_delay_pb_list):
min_stop_times = flow_delay_info.delay_info.stop_times
imbalance_index = round((max_stop_times - min_stop_times) / avg_stop_times, 2) if avg_stop_times > 0 and max_stop_times > 0 and min_stop_times != 99999 else 0
item.delay_info.imbalance_index = imbalance_index
return inroad_delay_pb_list
return tmp_list
def gen_flow_turn_rate_index(avg_cross_delay_info, roads_dir_dict):
@ -916,13 +917,18 @@ def parse_data2pb(data_list):
# 生成路口诊断问题
def gen_cross_problems(crossid, nodeid, date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase, is_peak, cross_ledger_info):
def gen_cross_problems(crossid, nodeid, area_id, time_range, start_hm, date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase, is_peak, cross_ledger_info):
# 运行效率、均衡调控、配时方案、路口渠化
operating_efficiency_problems = gen_operating_efficiency_problems(avg_cross_delay_info, roads_dir_dict, cross_phase, is_peak)
balanced_control_problems = gen_balanced_control_problems(crossid, nodeid, date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase)
phase_problems = gen_phase_problems()
phase_problems = gen_phase_problems(nodeid, area_id, crossid, time_range, date_list, min(date_list), max(date_list), start_hm)
cross_channelized_problems = gen_cross_channelized_problems(avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_ledger_info)
problems = [operating_efficiency_problems, balanced_control_problems, phase_problems, cross_channelized_problems]
problems = {
'operating_efficiency_problems': operating_efficiency_problems,
'balanced_control_problems': balanced_control_problems,
'phase_problems': phase_problems,
'cross_channelized_problems': cross_channelized_problems
}
return problems
@ -934,8 +940,8 @@ def gen_operating_efficiency_problems(avg_cross_delay_info, roads_dir_dict, cros
'values': []
}]
road_delay_infos = avg_cross_delay_info.inroad_delay_infos
high_park_problems, high_park_suggestions = gen_high_park_problems(road_delay_infos, roads_dir_dict, cross_phase)
high_stop_times_problems, high_stop_times_suggestions = gen_high_stop_time_problems(avg_cross_delay_info, is_peak)
high_park_problems, high_park_suggestions, high_park_total_num = gen_high_park_problems(road_delay_infos, roads_dir_dict, cross_phase)
high_stop_times_problems, high_stop_times_suggestions, high_stop_times_total_num = gen_high_stop_time_problems(avg_cross_delay_info, is_peak)
operating_efficiency_problems = {
'item': '运行效率',
'values': [
@ -951,21 +957,16 @@ def gen_operating_efficiency_problems(avg_cross_delay_info, roads_dir_dict, cros
'reason': '高峰时段路口停车次数大于2次非高峰时段停车次数大于1次',
'suggestions': high_stop_times_suggestions
}
]
],
'total_num': high_park_total_num + high_stop_times_total_num
}
return operating_efficiency_problems
# 运行效率-多次排队
def gen_high_park_problems(road_delay_infos, roads_dir_dict, cross_phase):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestion = []
detail = []
suggestion, total_num = [], 0
err_src_dict = {}
src_list = list(roads_dir_dict.keys())
road_delays_dict = {item.inroadid: item for item in road_delay_infos}
@ -987,6 +988,7 @@ def gen_high_park_problems(road_delay_infos, roads_dir_dict, cross_phase):
if err_src_dict:
detail = []
for src_dir in err_src_dict.keys():
total_num = 1
src_detail, src_suggestions, turn_type_list = [], [], []
for turn_type in err_src_dict[src_dir]:
turn_type_list.append(int(turn_type.split(':')[0]))
@ -1017,25 +1019,20 @@ def gen_high_park_problems(road_delay_infos, roads_dir_dict, cross_phase):
'child_detail': src_suggestions
})
suggestion.extend(phase_suggestions)
return detail, suggestion
return detail, suggestion, total_num
# 运行效率-停车较多
def gen_high_stop_time_problems(avg_cross_delay_info, is_peak):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestion = []
detail = []
suggestion, total_num = [], 0
desc, max_stop_times = '非高峰时段', 1
if is_peak:
# 表示为高峰时段,否则为平峰时段
desc, max_stop_times = '高峰时段', 2
if avg_cross_delay_info:
if avg_cross_delay_info.delay_info.stop_times > max_stop_times:
total_num = 1
detail = [{
'child_detail': [
{
@ -1057,15 +1054,15 @@ def gen_high_stop_time_problems(avg_cross_delay_info, is_peak):
]
}
]
return detail, suggestion
return detail, suggestion, total_num
# 均衡调控
def gen_balanced_control_problems(crossid, nodeid, date_list, avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_phase):
road_delay_infos = avg_cross_delay_info.inroad_delay_infos
cross_imbalance_detail, cross_imbalance_suggestions = gen_cross_imbalance_problems(road_delay_infos, roads_dir_dict, cross_phase)
turn_imbalance_detail, turn_imbalance_suggestions = gen_turn_imbalance_problems(road_delay_infos, roads_dir_dict, inroad_static_info_dict, cross_phase)
cross_tide_problems, cross_tide_suggestions = gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict)
cross_imbalance_detail, cross_imbalance_suggestions, cross_imbalance_total_num = gen_cross_imbalance_problems(road_delay_infos, roads_dir_dict, cross_phase)
turn_imbalance_detail, turn_imbalance_suggestions, turn_imbalance_total_num = gen_turn_imbalance_problems(road_delay_infos, roads_dir_dict, inroad_static_info_dict, cross_phase)
cross_tide_problems, cross_tide_suggestions, cross_tide_total_num = gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict)
balanced_control_problems = {
'item': '均衡调控',
'values': [
@ -1087,22 +1084,17 @@ def gen_balanced_control_problems(crossid, nodeid, date_list, avg_cross_delay_in
'reason': '对向进口道早高峰其中一个方向的进口道与出口道流量比大于150%晚高峰另一个方向进口道与出口道流量比大于150%',
'suggestions': cross_tide_suggestions
}
]
],
'total_num': cross_imbalance_total_num + turn_imbalance_total_num + cross_tide_total_num
}
return balanced_control_problems
# 均衡调控-路口失衡问题诊断
def gen_cross_imbalance_problems(road_delay_infos, roads_dir_dict, cross_phase):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestion = []
road_src_dict = {item['in']: item for item in roads_dir_dict}
detail = []
suggestion, total_num = [], 0
road_src_dict = {v['in']: k for k, v in roads_dir_dict.items()}
max_stop_times_road = max(road_delay_infos, key=lambda x: x.delay_info.stop_times)
min_stop_times_road = min(road_delay_infos, key=lambda x: x.delay_info.stop_times)
if max_stop_times_road.delay_info.stop_times > 1 \
@ -1112,7 +1104,8 @@ def gen_cross_imbalance_problems(road_delay_infos, roads_dir_dict, cross_phase):
max_src = road_src_dict[max_roadid] if max_roadid in road_src_dict else None
min_src = road_src_dict[min_roadid] if min_roadid in road_src_dict else None
if max_src is None or min_src is None:
return detail, suggestion
return detail, suggestion, total_num
total_num = 1
detail = [
{
'child_detail': [
@ -1149,21 +1142,15 @@ def gen_cross_imbalance_problems(road_delay_infos, roads_dir_dict, cross_phase):
is_tide = True
phase_suggestions = gen_src_dir_phase_detail(max_src, min_src, cross_phase, is_tide=is_tide)
suggestion.extend(phase_suggestions)
return detail, suggestion
return detail, suggestion, total_num
# 均衡调控-转向失衡问题诊断
def gen_turn_imbalance_problems(road_delay_infos, roads_dir_dict, inroad_static_info_dict, cross_phase):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestion = []
detail = []
suggestion, total_num = [], 0
err_road_dict = {}
road_src_dict = {item['in']: item for item in roads_dir_dict}
road_src_dict = {v['in']: k for k, v in roads_dir_dict.items()}
for road_delay_info in road_delay_infos:
inroadid = road_delay_info.inroadid
src_dir = road_src_dict[inroadid] if inroadid in road_src_dict.keys() else None
@ -1183,6 +1170,7 @@ def gen_turn_imbalance_problems(road_delay_infos, roads_dir_dict, inroad_static_
if len(err_road_dict.keys()) > 0:
detail, suggestion, road_num_suggestion = [], [], []
for src_dir in err_road_dict.keys():
total_num = 1
item_detail = [
{
'src_dir': dir_str_dict[src_dir] + '进口',
@ -1244,19 +1232,13 @@ def gen_turn_imbalance_problems(road_delay_infos, roads_dir_dict, inroad_static_
lane_num_suggestion.extend(road_num_suggestion)
suggestion = suggestion + lane_num_suggestion
return detail, suggestion
return detail, suggestion, total_num
# 均衡调控-路口潮汐问题诊断
def gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestions = []
detail = []
suggestions, total_num = [], 0
am_tp_start, am_tp_end = 't700', '900'
pm_tp_start, pm_tp_end = 't1700', '1900'
am_cross_delay_data_list = db_cross.query_cross_delay_info(crossid, nodeid, date_list, am_tp_start)
@ -1265,7 +1247,7 @@ def gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict):
pm_avg_cross_delay_info = gen_avg_cross_delay_pb(pm_cross_delay_data_list)
# 构建对向进口道对
subtend_road_pair = gen_subtend_road_pair(roads_dir_dict)
road_src_dict = {item['in']: item for item in roads_dir_dict}
road_src_dict = {v['in']: k for k, v in roads_dir_dict.items()}
max_am_flow, max_pm_flow, tide_index, max_am_flow_road, max_pm_flow_road = 0, 99999999999, 0, '', ''
am_inroad_infos = am_avg_cross_delay_info.inroad_delay_infos
pm_inroad_infos = pm_avg_cross_delay_info.inroad_delay_infos
@ -1277,10 +1259,12 @@ def gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict):
if am_flow > max_am_flow:
max_am_flow = am_flow
max_am_flow_road = am_inroad_info.inroadid
subtend_road_am_flow = am_inroad_info_dict[subtend_road_pair[max_am_flow_road]].delay_info.car_num if subtend_road_pair[max_am_flow_road] in am_inroad_info_dict.keys() else 0
subtend_road_am_flow = 0
if max_am_flow_road in subtend_road_pair.keys() and subtend_road_pair[max_am_flow_road] in am_inroad_info_dict.keys():
subtend_road_am_flow = am_inroad_info_dict[subtend_road_pair[max_am_flow_road]].delay_info.car_num
# 如果进口道流量小于20 则无意义
if min(subtend_road_am_flow, max_am_flow) < 20:
return detail, suggestions
return detail, suggestions, total_num
# 找出晚高峰最高流量的进口道
for pm_inroad_info in pm_inroad_infos:
pm_flow = pm_inroad_info.delay_info.car_num
@ -1289,13 +1273,14 @@ def gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict):
max_pm_flow_road = pm_inroad_info.inroadid
# 如果路段id为空或不在对向对里则无意义
if max_pm_flow_road == '' or max_pm_flow_road not in subtend_road_pair.keys():
return detail, suggestions
return detail, suggestions, total_num
subtend_road_pm_flow = pm_inroad_info_dict[subtend_road_pair[max_pm_flow_road]].delay_info.car_num
if min(subtend_road_pm_flow, max_pm_flow) < 20:
return detail, suggestions
return detail, suggestions, total_num
Fam = max(max_am_flow_road, subtend_road_am_flow) / min(max_am_flow_road, subtend_road_am_flow)
Fpm = max(max_pm_flow_road, subtend_road_pm_flow) / min(max_pm_flow_road, subtend_road_pm_flow)
if Fam >= 1.5 and Fpm >= 1.5 and max_pm_flow_road == subtend_road_pair[max_am_flow_road]:
total_num = 1
src_dir = road_src_dict[max_am_flow_road]
full_src_dir = dir_str_dict[src_dir] + dir_str_dict[src_reverse[src_dir]] + '方向'
am_src_dir = dir_str_dict[src_dir] + '' + dir_str_dict[src_reverse[src_dir]]
@ -1333,20 +1318,93 @@ def gen_cross_tide_problems(crossid, nodeid, date_list, roads_dir_dict):
]
}
]
return detail, suggestions
return detail, suggestions, total_num
# 配时方案
def gen_phase_problems():
def gen_phase_problems(nodeid, area_id, crossid, time_range, date_list, min_date, max_date, start_hm):
phase_problems = {
'item': '配时方案',
'values': [],
'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:
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:
phase_problems['values'].append({
'item': '路口方案异常',
'detail': phase_err_detail,
'reason': '路口停车次数徒增或大数据计算方案与录入方案不一致',
'suggestions': phase_err_suggestions
})
total = phase_problems_detail['total'] if len(phase_problems_detail) > 0 else 0
phase_problems['total_num'] = total + phase_err_total_num
pass
return phase_problems
def gen_err_phase_problems(start_hm, max_date, crossid, min_date):
cross_examine_records = db_cross.query_cross_examine_records(start_hm, max_date, crossid, min_date)
detail = []
suggestions, total_num = [], 0
color_dict = {
1: '红色',
2: '橙色',
3: '黄色',
4: '绿色'
}
state_dict = {
1: '需核查逾期',
2: '需核查',
3: '监测中',
4: '核查有异常',
5: '核查无异常',
6: '自动结束'
}
if len(cross_examine_records) > 0:
total_num = 1
detail = []
suggestions = [
{
'child_detail': [
{
'text': '核查该时段配时方案是否正常运行'
}
]
}
]
for cross_examine_record in cross_examine_records:
if cross_examine_record['level_color'] == 4:
continue
first_date = cross_examine_record['first_date']
start_hm = convert_time(cross_examine_record['start_hm'])
end_hm = convert_time(cross_examine_record['end_hm'])
color_level = color_dict[cross_examine_record['level_color']]
final_state = state_dict[cross_examine_record['final_state']]
item_detail = [
{
'text': f'{first_date}起在{start_hm}-{end_hm}时段运行的配时方案有异常变动风险,异常等级为'
},
{
'color': color_level,
'text': f',处理状态为',
'final_state': final_state
}
]
detail.append({
'child_detail': item_detail
})
return detail, suggestions, total_num
# 路口渠化
def gen_cross_channelized_problems(avg_cross_delay_info, roads_dir_dict, inroad_static_info_dict, cross_ledger_info):
road_delay_infos = avg_cross_delay_info.inroad_delay_infos
inroad_num_detail, inroad_num_suggestion = gen_inroad_num_problems(road_delay_infos, inroad_static_info_dict, roads_dir_dict)
inout_lane_num_gap_problems, inout_lane_num_gap_suggestions = gen_in_out_lane_num_gap_problems(cross_ledger_info)
inroad_num_detail, inroad_num_suggestion, inroad_num_err_total_num = gen_inroad_num_problems(road_delay_infos, inroad_static_info_dict, roads_dir_dict)
inout_lane_num_gap_problems, inout_lane_num_gap_suggestions, inout_lane_num_gap_total_num = gen_in_out_lane_num_gap_problems(cross_ledger_info)
cross_channelized_problems = {
'item': '路口渠化',
'values': [
@ -1362,32 +1420,27 @@ def gen_cross_channelized_problems(avg_cross_delay_info, roads_dir_dict, inroad_
'reason': '进口道车道数比对向的出口道车道数多2',
'suggestions': inout_lane_num_gap_suggestions
},
]
],
'total_num': inroad_num_err_total_num + inout_lane_num_gap_total_num
}
return cross_channelized_problems
# 路口渠化-车道资源不匹配
def gen_inroad_num_problems(road_delay_infos, inroad_static_info_dict, roads_dir_dict):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestions, err_src_dirs = [], {}
road_src_dict = {item['in']: item for item in roads_dir_dict}
detail = []
suggestions, err_src_dirs, total_num = [], {}, 0
road_src_dict = {v['in']: k for k, v in roads_dir_dict.items()}
max_flow_car_num = 0
for road_delay in road_delay_infos:
inroadid = road_delay.inroadid
src_dir = road_src_dict[inroadid]
src_dir = road_src_dict[inroadid] if inroadid in road_src_dict else None
if src_dir is None:
continue
lane_info = inroad_static_info_dict[inroadid]['lane_turn_info']
flow_delay_infos = road_delay.flow_delay_infos
max_car_num = max([item.delay_info.car_num for item in flow_delay_infos if item.turn_type in [0, 1]]).delay_info.car_num
max_car_num = max([item.delay_info.car_num for item in flow_delay_infos if item.turn_type in [0, 1]])
if max_car_num > max_flow_car_num:
max_flow_car_num = max_car_num
road_car_num = road_delay.delay_info.car_num
@ -1426,6 +1479,7 @@ def gen_inroad_num_problems(road_delay_infos, inroad_static_info_dict, roads_dir
}]
if len(err_src_dirs.keys()) > 0:
detail = []
total_num = 1
for src_dir in err_src_dirs.keys():
err_road_dict = err_src_dirs[src_dir]
src_detail = [
@ -1468,19 +1522,13 @@ def gen_inroad_num_problems(road_delay_infos, inroad_static_info_dict, roads_dir
]
}
)
return detail, suggestions
return detail, suggestions, total_num
# 路口渠化-进出口道数不匹配
def gen_in_out_lane_num_gap_problems(cross_ledger_info):
detail = [{
'child_detail': [
{
'text': '未见异常'
}
]
}]
suggestions, err_src_dict = [], {}
detail = []
suggestions, err_src_dict, total_num = [], {}, 0
road_infos = cross_ledger_info['roads']
for src_dir in road_infos.keys():
entry_lane_num = road_infos[src_dir]['entry_lane_num']
@ -1494,6 +1542,7 @@ def gen_in_out_lane_num_gap_problems(cross_ledger_info):
}
if len(err_src_dict.keys()) > 0:
detail = []
total_num = 1
suggestions = {
'child_detail': [
{
@ -1514,7 +1563,7 @@ def gen_in_out_lane_num_gap_problems(cross_ledger_info):
]
}
])
return detail, suggestions
return detail, suggestions, total_num
def check_is_peak_tp(time_range, area_id, nodeid):
@ -1527,6 +1576,8 @@ def check_is_peak_tp(time_range, area_id, nodeid):
def get_flow_phase_detail(src_dir, turn_type_list, cross_phase):
phase_suggestion = []
if not cross_phase:
return phase_suggestion
for item in cross_phase:
# 单个元素的含义为一个周计划
schedule_suggestion = []
@ -1691,3 +1742,17 @@ def count_lsr_half(turn_str):
# 返回格式化的结果,保留一位小数
return round(left_count, 1), round(straight_count, 1), round(right_count, 1)
def get_next_cross(nodeid, area_id, roads_dir_dict):
src_cross = {}
for src_dir in roads_dir_dict.keys():
outroadid = roads_dir_dict[src_dir]['out']
if outroadid and outroadid != '-':
row_list = db_tmnet.query_out_cross(outroadid)
if len(row_list) > 0:
crossid = row_list[0]['to_crossid']
cross_info = db_tmnet.query_next_cross_info(nodeid, area_id, crossid)
if cross_info:
src_cross[src_dir] = cross_info[0]
return src_cross

View File

@ -76,7 +76,8 @@ class TmnetDbHelper(TableDbHelperBase):
if(t2.from_crossid is not null, t2.from_crossid, t1.from_crossid) as from_crossid,
if(t2.to_crossid is not null, t2.to_crossid, t1.to_crossid) as to_crossid,
if(t2.name is not null, t2.name, t1.name) as name,
if(t2.src_direct is not null, t2.src_direct, t1.src_direct) as src_direct
if(t2.src_direct is not null, t2.src_direct, t1.src_direct) as src_direct,
if(t2.lane_turn_info is not null, t2.lane_turn_info, t1.lane_turn_info) as lane_turn_info
from
(select * from road where nodeid = '%s' and recordstate=0 and to_crossid='%s' and (is_sup_road is null or is_sup_road<>1)) t1
left join
@ -150,3 +151,26 @@ class TmnetDbHelper(TableDbHelperBase):
conn.rollback()
self.close(conn, cursor)
return 0, e
def query_cross_examine_records(self, start_hm, first_date, crossid, end_date):
sql = """
select * from cross_doctor_matedata.cross_phase_problems_record where crossid = '%s' and start_hm = '%s' and first_date <= %s and (end_date >= '%s' or end_date is null)
""" % (crossid, start_hm, first_date, end_date)
return self.do_select(sql)
def query_out_cross(self, outroadid):
sql = "select to_crossid from road where roadid = '%s'" % outroadid
return self.do_select(sql)
def query_next_cross_info(self, nodeid, area_id, crossid):
sql = """
select
if(t2.name is not null, t2.name, t1.name) as name,
t1.crossid,
if (t2.location is not null, t2.location, t1.location) as location,
t1.nodeid,
t1.area_id
from (select name,crossid, location,nodeid, area_id from `cross` where nodeid = %s and area_id = %s and at_edge=0 and isdeleted=0 and crossid = %s) as t1
left join (select name,crossid, location,nodeid, area_id from `cross_ledger_update_info` where nodeid = %s and area_id = %s and at_edge=0 and isdeleted=0 and crossid = %s) as t2 on t1.crossid=t2.crossid
""" % (nodeid, area_id, crossid, nodeid, area_id, crossid)
return self.do_select(sql)

View File

@ -6,7 +6,7 @@ citylist = 350100
hot_citylist = 350100
[db]
host = sass_dev
host = 82.157.173.20
host_inner = 172.21.32.32
user = root
password = pmenJIn7EaK40oThn~~
@ -25,7 +25,7 @@ db = 2
[rpc]
# 本机服务配置
host = 120.53.125.169
host = 82.157.173.20
host_inner = 172.21.32.21
port = 50051
@ -53,7 +53,7 @@ dbname = tmnet
port = 3306
[roadnet_db]
host = sass_dev
host = 82.157.173.20
host_inner = 172.21.32.32
user = root
password = pmenJIn7EaK40oThn~~

View File

@ -151,7 +151,7 @@ def QueryCrossPhaseDiagnosis(citycode: int, crossid: str, date_list: List, tp: s
if response.code != 0:
raise Exception(response.msg)
data = MessageToDict(response.data)
data = MessageToDict(response.data, preserving_proto_field_name=True)
if len(data) > 0:
data['total'] = len(data['values'])
return data, None