Skip to content

Commit

Permalink
common: coding style refactor for python files under modules/tools (A…
Browse files Browse the repository at this point in the history
…polloAuto#10631)

* common: autopep8 coding style fixes

* sort import orders

* minor fix
  • Loading branch information
michael4338 authored Jan 15, 2020
1 parent 3e2b771 commit c8d872c
Show file tree
Hide file tree
Showing 103 changed files with 1,109 additions and 696 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

from subprocess import call
import sys

import yaml


def main():
"""Main function.
Expand Down Expand Up @@ -54,5 +56,6 @@ def main():
except OSError as e:
print(e)


if __name__ == '__main__':
main()
17 changes: 10 additions & 7 deletions modules/tools/fuel_proxy/submit_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@
###############################################################################

""" Submit Apollo fuel job. """
import sys
# Disable python2 paths.
sys.path = [path for path in sys.path if 'python2' not in path]

import json
import os
import requests
import sys

from absl import app
from absl import flags
from absl import logging
import google.protobuf.json_format as json_format
from absl import flags
from absl import app
import google.protobuf.text_format as text_format
import requests
import google.protobuf.json_format as json_format

from modules.tools.fuel_proxy.proto.job_config_pb2 import JobConfig


# Disable python2 paths.
sys.path = [path for path in sys.path if 'python2' not in path]


flags.DEFINE_string('fuel_proxy', 'https://apollofuel0.bceapp.com:8443/proxy',
'Endpoint of Apollo-Fuel proxy.')
flags.DEFINE_string('job_config', None, 'Apollo fuel job config.')
Expand Down Expand Up @@ -90,5 +92,6 @@ def main(argv):
if job.parse_input():
job.send_request()


if __name__ == '__main__':
app.run(main)
10 changes: 6 additions & 4 deletions modules/tools/gen_vehicle_protocol/extract_dbc_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
# limitations under the License.
###############################################################################

import re
import shlex
import sys

import yaml
import shlex
import re


MAX_CAN_ID = 4096000000 # 2048

Expand Down Expand Up @@ -106,7 +108,7 @@ def extract_dbc_meta(dbc_file, out_file, car_type, black_list, sender_list,
if len(protocol) != 0 and len(protocol["vars"]) != 0 and len(
protocol["vars"]) < 65:
protocols[protocol["id"]] = protocol
#print protocol
# print protocol
protocol = {}

if len(items) == 5 and items[0] == "CM_" and items[1] == "SG_":
Expand Down Expand Up @@ -138,7 +140,7 @@ def extract_dbc_meta(dbc_file, out_file, car_type, black_list, sender_list,
if var["name"].lower() in cpp_reserved_key_words:
var["name"] = "MY_" + var["name"]

#print protocols
# print protocols
config = {}
config["car_type"] = car_type
config["protocols"] = protocols
Expand Down
4 changes: 3 additions & 1 deletion modules/tools/gen_vehicle_protocol/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
# limitations under the License.
###############################################################################

#-*- coding:utf-8 -*-
# -*- coding:utf-8 -*-

import datetime
import os
import shutil
import sys

import yaml

from gen_proto_file import gen_proto_file
from gen_protocols import gen_protocols
from gen_vehicle_controller_and_manager import gen_vehicle_controller_and_manager
Expand Down
5 changes: 3 additions & 2 deletions modules/tools/gen_vehicle_protocol/gen_proto_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import datetime
import os
import re
import shutil
import sys

import yaml
import re


def write_single_protocol_vars(pb_fp, p):
Expand Down Expand Up @@ -131,7 +132,7 @@ def gen_proto_file(config_file, work_dir):
pb_var_seq = pb_var_seq + 1
pb_fp.write("}\n")

#update_detail_pb(car_type)
# update_detail_pb(car_type)


if __name__ == "__main__":
Expand Down
9 changes: 6 additions & 3 deletions modules/tools/gen_vehicle_protocol/gen_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# limitations under the License.
###############################################################################

#-*- coding:utf-8 -*-
# -*- coding:utf-8 -*-

import datetime
import os
import shutil
import sys

import yaml


Expand Down Expand Up @@ -322,7 +323,7 @@ def gen_control_value_func_impl(classname, var, protocol):
"""
impl = ""
if var["len"] > 32:
print("This generator not support big than four bytes var." + \
print("This generator not support big than four bytes var." +
"protocol classname: %s, var_name:%s " % (
class_name, var["name"]))
return impl
Expand Down Expand Up @@ -457,16 +458,18 @@ def gen_protocols(protocol_conf_file, protocol_dir):
print("Unknown protocol_type:%s" % protocol["protocol_type"])
gen_build_file(car_type, protocol_dir)


def gen_esd_can_extended(str):
"""
id string:
"""
int_id = int(str,16)
int_id = int(str, 16)
int_id &= 0x1FFFFFFF
int_id |= 0x20000000
str = hex(int_id).replace('0x', '')
return str


if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage:\npython %s some_config.yml" % sys.argv[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# limitations under the License.
###############################################################################

#-*- coding:utf-8 -*-
# -*- coding:utf-8 -*-

import datetime
import os
import shutil
import sys

import yaml


Expand Down Expand Up @@ -239,7 +240,7 @@ def gen_vehicle_controller_and_manager(config_file, output_dir):
protocol_conf = conf["protocol_conf"]

output_dir = conf["output_dir"] + "vehicle/" + conf["car_type"].lower() + \
"/"
"/"
shutil.rmtree(output_dir, True)
os.makedirs(output_dir)
gen_vehicle_controller_and_manager(protocol_conf, output_dir)
57 changes: 32 additions & 25 deletions modules/tools/localization/evaluate_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
# limitations under the License.
###############################################################################

import sys
import numpy
import math
import numpy
import os
import sys


def get_stat2_from_data(data):
"""Find the max number of continuous frames when position error is lager
Expand Down Expand Up @@ -61,6 +62,7 @@ def get_stat2_from_data(data):
stat = [max_con_frame_num_10, max_con_frame_num_20, max_con_frame_num_30]
return stat


def get_angle_stat2_from_data(data):
"""Find the max number of continuous frames when yaw error is lager
than 1.0d, 0.6d and 0.3d
Expand Down Expand Up @@ -101,6 +103,7 @@ def get_angle_stat2_from_data(data):
stat = [max_con_frame_num_1_0, max_con_frame_num_0_6, max_con_frame_num_0_3]
return stat


def get_stat_from_data(data):
if len(data) == 0:
print("No statistics data!")
Expand Down Expand Up @@ -128,6 +131,7 @@ def get_stat_from_data(data):
count_less_than_20, count_less_than_10]
return stat


def get_angle_stat_from_data(data):
if len(data) == 0:
print("No statistics data!")
Expand Down Expand Up @@ -155,6 +159,7 @@ def get_angle_stat_from_data(data):
count_less_than_06, count_less_than_03]
return stat


def parse_file(filename, type):
with open(filename, 'r') as fp:
lines = fp.readlines()
Expand All @@ -169,7 +174,7 @@ def parse_file(filename, type):
for line in lines:
s = line.split()
if (len(s) > 7):
#error.append(float(s[6]))
# error.append(float(s[6]))
error_lon.append(float(s[2]))
error_lat.append(float(s[3]))
error_alt.append(float(s[4]))
Expand All @@ -180,7 +185,7 @@ def parse_file(filename, type):
x = float(s[2])
y = float(s[3])
error.append(math.sqrt(x * x + y * y))
#print "%f %f %f" % (error[-1], error_lon[-1], error_lat[-1])
# print "%f %f %f" % (error[-1], error_lon[-1], error_lat[-1])
if type == "all":
print_distance_error(error, error_lon, error_lat, error_alt)
print_angle_error(error_roll, error_pitch, error_yaw)
Expand All @@ -199,44 +204,46 @@ def print_distance_error(error, error_lon, error_lat, error_alt):
if len(result) != 6:
return
res = get_stat2_from_data(error)
print('error : %06f %06f %06f %06f %06f %06f %06d' % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
print('error : %06f %06f %06f %06f %06f %06f %06d' %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
result = get_stat_from_data(error_lon)
res = get_stat2_from_data(error_lon)
print('error lon: %06f %06f %06f %06f %06f %06f %06d' % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
print('error lon: %06f %06f %06f %06f %06f %06f %06d' %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
result = get_stat_from_data(error_lat)
res = get_stat2_from_data(error_lat)
print('error lat: %06f %06f %06f %06f %06f %06f %06d' % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
print('error lat: %06f %06f %06f %06f %06f %06f %06d' %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
result = get_stat_from_data(error_alt)
res = get_stat2_from_data(error_alt)
print('error alt: %06f %06f %06f %06f %06f %06f %06d' % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))
print('error alt: %06f %06f %06f %06f %06f %06f %06d' %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[2]))


def print_angle_error(error_roll, error_pitch, error_yaw):
print('criteria : mean std max < 1.0d < 0.6d < 0.3d con_frames(>1.0d)')
result = get_angle_stat_from_data(error_roll)
if len(result) != 6:
return
res = get_angle_stat2_from_data(error_roll)
print("error rol: %06f %06f %06f %06f %06f %06f %06d" % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))
print("error rol: %06f %06f %06f %06f %06f %06f %06d" %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))
result = get_angle_stat_from_data(error_pitch)
res = get_angle_stat2_from_data(error_pitch)
print("error pit: %06f %06f %06f %06f %06f %06f %06d" % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))
print("error pit: %06f %06f %06f %06f %06f %06f %06d" %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))
result = get_angle_stat_from_data(error_yaw)
res = get_angle_stat2_from_data(error_yaw)
print("error yaw: %06f %06f %06f %06f %06f %06f %06d" % \
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))
print("error yaw: %06f %06f %06f %06f %06f %06f %06d" %
(result[0], result[1], result[2],
result[3], result[4], result[5], res[0]))


if __name__ == '__main__':
if len(sys.argv) < 2:
Expand Down
10 changes: 5 additions & 5 deletions modules/tools/mapshow/libs/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import random

import matplotlib.pyplot as plt
from matplotlib import cm as cmx
from matplotlib import colors as mcolors
import matplotlib.pyplot as plt

import common.proto_utils as proto_utils
from modules.map.proto import map_pb2
import common.proto_utils as proto_utils


class Map:
Expand Down Expand Up @@ -89,7 +89,7 @@ def draw_lanes(self, ax, is_show_lane_ids, laneids, is_show_lane_details):
def _draw_lane_id(self, lane, ax, color_val):
"""draw lane id"""
x, y = self._find_lane_central_point(lane)
self._draw_label(lane.id.id, (x, y), ax, color_val);
self._draw_label(lane.id.id, (x, y), ax, color_val)

def _draw_lane_details(self, lane, ax, color_val):
"""draw lane id"""
Expand Down Expand Up @@ -142,7 +142,7 @@ def draw_pnc_junctions(self, ax):
def _draw_pnc_junction_id(self, pnc_junction, ax, color_val):
x = pnc_junction.polygon.point[0].x
y = pnc_junction.polygon.point[0].y
self._draw_label(pnc_junction.id.id, (x, y), ax, color_val);
self._draw_label(pnc_junction.id.id, (x, y), ax, color_val)

def draw_crosswalks(self, ax):
cnt = 1
Expand All @@ -155,7 +155,7 @@ def draw_crosswalks(self, ax):
def _draw_crosswalk_id(self, crosswalk, ax, color_val):
x = crosswalk.polygon.point[0].x
y = crosswalk.polygon.point[0].y
self._draw_label(crosswalk.id.id, (x, y), ax, color_val);
self._draw_label(crosswalk.id.id, (x, y), ax, color_val)

@staticmethod
def _draw_label(label_id, point, ax, color_val):
Expand Down
Loading

0 comments on commit c8d872c

Please sign in to comment.