|
- #!/usr/bin/env python3
- # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil -*-
- # vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
-
- import os
- import sys
- import json
- import sqlite3
-
- """
- {
- "LocalHost": "192.168.1.19",
- "LocalPort": 48999,
- "LocalCameraHost": "192.168.1.19",
- "LocalCameraPort": 48998,
- "SimulationHost": "192.168.1.18",
- "SimulationPort": 8880,
- "LocalizerHost": "127.0.0.1",
- "LocalizerPort": 9003,
- "VtdServer": {
- "Enabled": true,
- "SensorHost": "127.0.0.1",
- "SensorPort": 48185
- },
- "CentralMeridian": 102.65,
- "GaussianOffset": [
- 20489000.0,
- 3260000.0
- ],
- "BaseOffset": [
- 11204.2,
- 4071.96,
- 314.43818336,
- 135.5618
- ],
- "VtdScenarios": [],
- "HdMapPath": "/navinfo/config/data/19146703.adms",
- "Description": "\u573a\u666f\u63cf\u8ff0",
- "InsFrequency": 100,
- "EnableLocalizer": false,
- "ErrorModel": {
- "Enabled": false,
- "UseScene": true,
- "VehicleParameters": [
- 2.7,
- 1.92
- ],
- "TriggerPosition": [
- 0.0,
- 0.0,
- 0.0
- ],
- "Means": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "Varience": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "UN": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "LimitMaxes": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "LimitMins": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "ConstantErrors": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "Amplitude": [
- 1.0,
- 1.0,
- 1.0,
- 1.0
- ],
- "Scene": "/navinfo/config/bridge/scenes/multi_scene_1_dr.csv"
- },
- "SensorErrorModel": {
- "Enabled": false,
- "UseScene": false,
- "ImuEnabled": false,
- "GnssEnabled": true,
- "CameraEnabled": true,
- "VehicleEnabled": false,
- "Gyro": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "GyroCB": [
- 0.0,
- 0.0,
- 0.0
- ],
- "GyroAM": [
- 0.0,
- 0.0,
- 0.0
- ],
- "Acc": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "AccCB": [
- 0.0,
- 0.0,
- 0.0
- ],
- "AccAM": [
- 0.0,
- 0.0,
- 0.0
- ],
- "SpeedDistrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "YawRateDistrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "XDistrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "YDistrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "ZDistrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "LaneA0Distrib": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "LaneInfoRecallRate": [
- 0.0,
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "Amplitude": [
- 0.0,
- 0.0,
- 0.0
- ],
- "Scene": ""
- },
- "ChannelNames": {
- "InsData": "InsData",
- "LocalizerInsData": "InsData2",
- "PlanningInsData": "InsData",
- "BrainInsData": "InsData02"
- },
- "Verbose": {
- "Roadmark": false,
- "InsData": false,
- "ControlCommand": false,
- "ControlFeedback": false,
- "WebSocket": false,
- "ErrorModel": false
- }
- }
- """
-
-
- if __name__ == "__main__":
- if len(sys.argv) < 3:
- sys.exit("update_db <db_path> <config_path>")
-
- update_exist = False
- if len(sys.argv) >= 4:
- update_exist = True
-
- db_path = os.path.abspath(sys.argv[1])
- config_path = os.path.abspath(sys.argv[2])
-
- if not os.path.isfile(db_path) or not os.path.isdir(config_path):
- sys.exit("<db_path> must be a db file, and <config_path> must be a directory contains config JSON files")
-
- replace_cols = ['common', 'map', 'channels', 'verbose']
-
- default_template = dict()
- default_template['common'] = json.loads('{"InsFrequency": 100,"EnableLocalizer": false,"Description": ""}')
- default_template['map'] = json.loads('{"CentralMeridian": 102.65,"GaussianOffset": [20489000.0,3260000.0],"BaseOffset": [11204.2,4071.96,314.43818336,135.5618],"VtdScenarios": [],"HdMapPath": "/navinfo/config/data/19146703.adms"}')
- default_template['error_injection'] = json.loads('{"ErrorModel": {"Enabled": false,"UseScene": true,"VehicleParameters": [2.7,1.92],"TriggerPosition": [0.0,0.0,0.0],"Means": [0.3835,-0.5556,-5.1341,0.9079],"Varience": [0.1194,0.3206,1.0249,1.2292],"UN": [20.0,20.0,30.0,40.0],"LimitMaxes": [4.0,10.0,10.0,10.0],"LimitMins": [1.0,-10.0,-15.0,-10.0],"ConstantErrors": [0.0,0.0,0.0,0.0],"Amplitude": [1.0,1.0,1.0,1.0],"Scene": "/navinfo/config/bridge/scenes/multi_scene_1_dr.csv"}}')
- default_template['sensor_error_injection'] = json.loads('{"SensorErrorModel": {"Enabled": false, "UseScene": false, "ImuEnabled": false, "GnssEnabled": false, "CameraEnabled": false, "VehicleEnabled": false, "Gyro": [-125.0, 125.0, 0.122, 5.0, 0.0, 0.05, 0.0, 0.0], "GyroCB": [10.0, 10.0, 10.0], "GyroAM": [1.0, 1.0, 1.0], "Acc": [-2.0, 2.0, 4.37, 60.0, 0.0, 0.0, 0.0], "AccCB": [80.0, 80.0, 80.0], "AccAM": [1.0, 1.0, 1.0], "SpeedDistrib": [-0.311716, 0.104909, 6, 0.003011, -0.626443, 0.0], "YawRateDistrib": [0.12766, 0.0780293, 2, 0.3617479, -0.1064279, 0.0], "XDistrib": [0.1, 0.5, 20, 1.0, -0.5, 0.05], "YDistrib": [0.1, 0.5, 20, 1.0, -0.5, 0.05], "ZDistrib": [0.1, 0.5, 20, 1.0, -0.5, 0.05], "LaneA0Distrib": [-0.163166, 0.100137, 2, 0.137245, -0.463577, 0.0], "LaneInfoRecallRate": [0.0, 0.97572, 0.8917, 0.981112, 0.995736], "Amplitude": [1.0, 1.0, 1.0], "Scene": ""}}')
- default_template['channels'] = json.loads('{"ChannelNames": {"InsData": "InsData","LocalizerInsData": "InsData2","PlanningInsData": "InsData","BrainInsData": "InsData02"}}')
- default_template['verbose'] = json.loads('{"Verbose": {"Roadmark": false,"InsData": false,"ControlCommand": false,"ControlFeedback": false,"WebSocket": false,"ErrorModel": false}}')
-
- conn = sqlite3.connect(db_path)
- cursor = conn.cursor()
-
- select_sql = """SELECT id FROM Scenario WHERE id='{}'"""
- update_sql = """UPDATE Scenario SET common=?, map=?, error_injection=?, sensor_error_injection=?, channels=?, verbose=?, others=NULL WHERE id='{}'"""
- insert_sql = """INSERT INTO Scenario (id, common, map, error_injection, sensor_error_injection, channels, verbose, others) VALUES (?,?,?,?,?,?,?,NULL)"""
-
- for cfg in os.listdir(config_path):
- cfg_path = os.path.join(config_path, cfg)
- if not os.path.isfile(cfg_path) or cfg.endswith('.json'):
- continue
- sid = os.path.splitext(cfg)[1][1:]
- config_json = json.loads(open(cfg_path).read())
- for col in replace_cols:
- for k in default_template[col]:
- if k in config_json:
- default_template[col][k] = config_json[k]
-
- v_list = [sid, json.dumps(default_template['common'], indent=4),
- json.dumps(default_template['map'], indent=4), json.dumps(default_template['error_injection'], indent=4),
- json.dumps(default_template['sensor_error_injection'], indent=4), json.dumps(default_template['channels'], indent=4),
- json.dumps(default_template['verbose'], indent=4)]
-
- if update_exist:
- cursor.execute(select_sql.format(sid))
- one = cursor.fetchone()
- if one:
- cursor.execute(update_sql.format(sid), v_list[1:])
- print(f"Attempt to update {sid} ...")
- else:
- cursor.execute(insert_sql, v_list)
- print(f"Attempt to insert {sid} ...")
- else:
- cursor.execute(insert_sql, v_list)
- print(f"Attempt to insert {sid} ...")
- conn.commit()
- cursor.close()
- conn.close()
- conn = None
|