# -*- coding: utf-8 -*-
from enum import Enum
from data_map_conf import *
ProfileType = Enum("ProfileType", {"Position":1, "ProfileMessage":2, "PathControl":3, "GlobalData":4, "ProfileControl":5})
profilemessage = Enum("ProfileMessage",
{
"Node":1,
"LaneModel":4,
"LaneConnectivity":5,
"LinearObject":6,
"LanesGeometry":7,
"LaneWidth":8,
"FunctionRoadClass":13,
"FormOfWay":15,
"Tunnel":19,
"TrafficSign":27,
"SpecialSituation":29,
"RoadSurface":98,
"StaticNotODD":103,
"StaticODD":108,
"Speed":112,
"CenterLanesGeometry":113,
}
)
def adapt_Node(value):
new_dic = {"node_num":1,"node_info":[]}
new_dic["node_info"].append(value.pop("node"))
value.update({"node":new_dic})
# 江淮
# 'value': {
# 'lanesGeometry':
# {'pointNum': 5,
# 'points':
# [{'slope': 0, 'longitude': '1389772624', 'crossSlope': 0, 'latitude': '479355947', 'headingAngle': 987, 'curvatur': 20},
# {'slope': 0, 'longitude': '1389773005', 'crossSlope': 0, 'latitude': '479357621', 'headingAngle': 1083, 'curvatur': 61},
# {'slope': 0, 'longitude': '1389773414', 'crossSlope': 0, 'latitude': '479359262', 'headingAngle': 1171, 'curvatur': 90},
# {'slope': 0, 'longitude': '1389773855', 'crossSlope': 0, 'latitude': '479360896', 'headingAngle': 1305, 'curvatur': 136},
# {'slope': 0, 'longitude': '1389774336', 'crossSlope': 0, 'latitude': '479362485', 'headingAngle': 1305, 'curvatur': 238}],
# 'linearid': 91162}}
# 广汽
# data = {
# "line_geometry":
# {
# "geometry":{
# "point_num":10,
# "points":[{"latitude":,"longitude":,},{"latitude":,"longitude":,}]
# },
# "linearid":,
# },
# "geometrycount":,
# "curvetype":,
# }
def adapt_LaneGeometry(value):
point_num = value["lanesGeometry"].pop("pointNum")
points = value["lanesGeometry"].pop("points")
geometry = {"pointNum":point_num,"points":points}
value["lanesGeometry"].update({"geometry":geometry})
# 'value': {
# 'centerLane': {
# 'type': 1,
# 'pointNum': 3,
# 'points': [{
# 'latitude': 479342541.0,
# 'longitude': 1389768162.0
# }, {
# 'latitude': 479342795.0,
# 'longitude': 1389768209.0
# }, {
# 'latitude': 479343570.0,
# 'longitude': 1389768348.0
# }],
# 'linearid': 100043911
# }
# }
# data = {
# "line_geometry": {
# "geometry": {
# "point_num": ,
# "points": [],
# }
# }
# }
def adapt_CenterLanesGeometry(value):
point_num = value["centerLane"].pop("pointNum")
points = value["centerLane"].pop("points")
geometry = {"pointNum":point_num,"points":points}
value["centerLane"].update({"geometry":geometry})
def reload_ori_data(message, data_map):
"""
message dic profile_name key
"""
if type(message) == list:
for member in message:
reload_ori_data(member, data_map)
else:
for key in data_map.keys():
new_key = data_map[key]
if(type(new_key) == dict):
for lower_key in new_key.keys():
if lower_key == "main":
_new_key = new_key["main"]
message[_new_key] = message.pop(key)
reload_ori_data(message[_new_key], new_key["sub"])
else:
message[new_key] = message.pop(key)
return message
def profile_reload_ori_data(message):
message = reload_ori_data(message, profile_outer_map_conf)
length = len(message["profileh"][0]["profile_datas"])
for index in range(length):
reload_ori_data({"head":message["profileh"][0]["profile_datas"][index]["head"]}, profile_head_map_conf)
for index in range(length):
_type = message["profileh"][0]["profile_datas"][index]["head"]["type"]
if _type == profilemessage.Node.value:
adapt_Node(message["profileh"][0]["profile_datas"][index]["value"])
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, Node_map_conf)
if _type == profilemessage.LaneModel.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, LaneModel_map_conf)
if _type == profilemessage.LaneConnectivity.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, LaneConnectivity_map_conf)
if _type == profilemessage.LinearObject.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, LinearObject_map_conf)
if _type == profilemessage.LanesGeometry.value:
# print "LanesGeometry1", message["profileh"][0]["profile_datas"][index]["value"], "LanesGeometry2"
adapt_LaneGeometry(message["profileh"][0]["profile_datas"][index]["value"])
# print "LanesGeometry3", message["profileh"][0]["profile_datas"][index]["value"], "LanesGeometry4"
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, LanesGeometry_map_conf)
# print "LanesGeometry5", message["profileh"][0]["profile_datas"][index]["value"], "LanesGeometry6"
if _type == profilemessage.LaneWidth.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, LaneWidth_map_conf)
if _type == profilemessage.FunctionRoadClass.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, FunctionRoadClass_map_conf)
if _type == profilemessage.FormOfWay.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, FormOfWay_map_conf)
if _type == profilemessage.Tunnel.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, Tunnel_map_conf)
if _type == profilemessage.TrafficSign.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, TrafficSign_map_conf)
if _type == profilemessage.SpecialSituation.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, SpecialSituation_map_conf)
if _type == profilemessage.RoadSurface.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, RoadSurface_map_conf)
if _type == profilemessage.StaticNotODD.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, StaticNotODD_map_conf)
if _type == profilemessage.StaticODD.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, StaticODD_map_conf)
if _type == profilemessage.Speed.value:
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, Speed_map_conf)
if _type == profilemessage.CenterLanesGeometry.value:
adapt_CenterLanesGeometry(message["profileh"][0]["profile_datas"][index]["value"])
reload_ori_data({"value":message["profileh"][0]["profile_datas"][index]["value"]}, CenterLanesGeometry_map_conf)
return message
def ReloadOriData(message, index):
if (index == ProfileType.PathControl.value):
message = reload_ori_data(message, path_control_map_conf)
if (index == ProfileType.ProfileMessage.value):
message = profile_reload_ori_data(message)
return message
if __name__ == "__main__":
# message = {'profileh':
# [
# {
# 'cyclicCounter': 0, 'profileDatas':
# [
# {'head':
# {'available': 1, 'confidence': 100.0, 'isRetransmission': False, 'endoffset': 49690,
# 'instanceid': 914802, 'endoffsetFinal': True, 'laneNumber': 0, 'offset': 0, 'pathid': 1,
# 'cyclicCounter': 1, 'type': 13, 'change': 0, 'interpolation': 1
# },
# 'value': {'laneWidth': {'value': 377}},
# }
# ]
# }
# ]
# }
message = {'profileh':
[
{
'cyclicCounter': 0, 'profileDatas':
[
{'head':
{'available': 1, 'confidence': 100.0, 'isRetransmission': False, 'endoffset': 49690,
'instanceid': 914802, 'endoffsetFinal': True, 'laneNumber': 0, 'offset': 0, 'pathid': 1,
'cyclicCounter': 1, 'type': 0, 'change': 0, 'interpolation': 1
},
'value': {
'node':
{'probability': 100.0,
'endoffset': 62526,
'instanceid': 13538,
'subpath': 3,
'isComplexIntersection': False,
'rightOfWay': 2,
'offset': 62526,
'pathid': 1,
'turnangle': 4.706233}
}
}
]
}
]
}
# FunctionRoadClass_map_conf = {
# "value":{
# "main":"value",
# "sub":{
# "unit8Valuel":"single_value",
# }
# }
# }
print ReloadOriData(message, 2)
# print reload_ori_data({"value":_message["profileh"][0]["profileDatas"][0]["value"]}, FunctionRoadClass_map_conf)
# print _message
# length = len(message["profileh"][0]["profile_datas"])
# for index in range(length):
# print reload_ori_data({"head":message["profileh"][0]["profileDatas"][index]["head"]}, profile_head_map_conf)