兼容pb对象中偶尔出现的存在值为Nan的情况
This commit is contained in:
parent
f3ae2d7028
commit
7eba15db91
|
|
@ -465,4 +465,23 @@ def gen_ten_weeks_ago_data_list_with_weekdays(date_type='week'):
|
||||||
|
|
||||||
# 大 list:从远到近(最早一周在最前面)
|
# 大 list:从远到近(最早一周在最前面)
|
||||||
result = [week_buckets[k] for k in sorted(week_buckets, reverse=False)]
|
result = [week_buckets[k] for k in sorted(week_buckets, reverse=False)]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def clean_dict_nan(obj, default_value=None):
|
||||||
|
"""
|
||||||
|
递归清理 dict/list 中的 NaN/Infinity
|
||||||
|
Args:
|
||||||
|
obj: 任意 Python 对象
|
||||||
|
default_value: NaN 的替换值(None 会转为 JSON null)
|
||||||
|
"""
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
return {k: clean_dict_nan(v, default_value) for k, v in obj.items()}
|
||||||
|
|
||||||
|
if isinstance(obj, list):
|
||||||
|
return [clean_dict_nan(item, default_value) for item in obj]
|
||||||
|
|
||||||
|
if isinstance(obj, float) and (math.isnan(obj) or math.isinf(obj)):
|
||||||
|
return default_value
|
||||||
|
|
||||||
|
return obj
|
||||||
|
|
@ -94,7 +94,7 @@ def query_compare_data(params):
|
||||||
if export == 1:
|
if export == 1:
|
||||||
return query_compare_data_export_excel(compared_inroad_delay_infos, cross_static_info['name'],compare_date_list,date_list,time_range)
|
return query_compare_data_export_excel(compared_inroad_delay_infos, cross_static_info['name'],compare_date_list,date_list,time_range)
|
||||||
|
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def do_add_cross_survey_job(params):
|
def do_add_cross_survey_job(params):
|
||||||
|
|
@ -452,7 +452,7 @@ def query_cross_survey_result(params):
|
||||||
'ledger_info': cross_ledger_info,
|
'ledger_info': cross_ledger_info,
|
||||||
'can_rerun_dir': dir_info
|
'can_rerun_dir': dir_info
|
||||||
}
|
}
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def rerun_cross_survey_dir(params):
|
def rerun_cross_survey_dir(params):
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ def query_cross_delay_info_controller(params):
|
||||||
if excel == 1:
|
if excel == 1:
|
||||||
return query_cross_delay_info_controller_export_excel(road_flow_delay_infos, road_flow_turn_rate)
|
return query_cross_delay_info_controller_export_excel(road_flow_delay_infos, road_flow_turn_rate)
|
||||||
|
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
# 问题诊断接口
|
# 问题诊断接口
|
||||||
|
|
@ -224,7 +224,7 @@ def query_cross_problems(params):
|
||||||
problems = gen_cross_problems(crossid, nodeid, area_id, time_range, str(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, weekdays)
|
problems = gen_cross_problems(crossid, nodeid, area_id, time_range, str(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, weekdays)
|
||||||
res = make_common_res(0, 'ok')
|
res = make_common_res(0, 'ok')
|
||||||
res['data'] = problems
|
res['data'] = problems
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
# 指标变化趋势接口
|
# 指标变化趋势接口
|
||||||
|
|
@ -318,7 +318,7 @@ def query_cross_index_trend_controller(params):
|
||||||
'days_data': days_data_with_change_rate,
|
'days_data': days_data_with_change_rate,
|
||||||
'weeks_data': weeks_data_with_change_rate
|
'weeks_data': weeks_data_with_change_rate
|
||||||
}
|
}
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def query_cross_examine_records_detail(params):
|
def query_cross_examine_records_detail(params):
|
||||||
|
|
@ -410,7 +410,7 @@ def query_cross_examine_records_detail(params):
|
||||||
'first_date': first_date,
|
'first_date': first_date,
|
||||||
'time_range': tp_start + '-' + tp_end if tp_start != '' else '',
|
'time_range': tp_start + '-' + tp_end if tp_start != '' else '',
|
||||||
}
|
}
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def update_cross_examine_record_state(params):
|
def update_cross_examine_record_state(params):
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ def query_monitor_data(params):
|
||||||
'monitor_crosses_ledger_info': monitor_crosses_ledger_info,
|
'monitor_crosses_ledger_info': monitor_crosses_ledger_info,
|
||||||
'cross_delay_info_list': cross_delay_info_list
|
'cross_delay_info_list': cross_delay_info_list
|
||||||
}
|
}
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
# 查询巡检数据变化趋势
|
# 查询巡检数据变化趋势
|
||||||
|
|
@ -142,7 +142,7 @@ def query_monitor_data_trend(params):
|
||||||
data = parse_monitor_trend_data(monitor_datas, date_type, special_time_range)
|
data = parse_monitor_trend_data(monitor_datas, date_type, special_time_range)
|
||||||
res = make_common_res(0, 'ok')
|
res = make_common_res(0, 'ok')
|
||||||
res['data'] = data
|
res['data'] = data
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
# 查询路口时段数据变化趋势
|
# 查询路口时段数据变化趋势
|
||||||
|
|
@ -222,7 +222,7 @@ def query_cross_tp_data_trend(params):
|
||||||
'time_range': time_range,
|
'time_range': time_range,
|
||||||
'delay_infos': res_data
|
'delay_infos': res_data
|
||||||
}
|
}
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def query_monitor_problems(params):
|
def query_monitor_problems(params):
|
||||||
|
|
@ -326,7 +326,7 @@ def query_monitor_problems(params):
|
||||||
monitor_problems = gen_monitor_problem_info(cross_report_pb, routing_crosses_dict, special_time_range, records, date_type, shield_info, query_date, nodeid, area_id, filter_shield)
|
monitor_problems = gen_monitor_problem_info(cross_report_pb, routing_crosses_dict, special_time_range, records, date_type, shield_info, query_date, nodeid, area_id, filter_shield)
|
||||||
res = make_common_res(0, 'ok')
|
res = make_common_res(0, 'ok')
|
||||||
res['data'] = monitor_problems
|
res['data'] = monitor_problems
|
||||||
return json.dumps(res, ensure_ascii=False)
|
return json.dumps(clean_dict_nan(res, '-'), ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def update_cross_problem_shield_state(params):
|
def update_cross_problem_shield_state(params):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue