refactor: 清理不需要的代码文件,添加.gitignore,优化项目结构

This commit is contained in:
赵杰 Jie Zhao (雄狮汽车科技)
2025-09-16 17:05:50 +01:00
parent 9451945e08
commit 9ca36042e3
65 changed files with 3370 additions and 10809 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
车辆数据管理模块

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
车辆实时数据管理器
@@ -89,6 +89,43 @@ class VehicleDataManager:
except Exception as e:
logger.error(f"获取车辆数据失败: {e}")
return []
def get_vehicle_data_by_vin(
self,
vehicle_vin: str,
data_type: str = None,
limit: int = 10
) -> List[Dict[str, Any]]:
"""按VIN获取车辆实时数据"""
try:
with db_manager.get_session() as session:
query = session.query(VehicleData).filter(
VehicleData.vehicle_vin == vehicle_vin,
VehicleData.is_active == True
)
if data_type:
query = query.filter(VehicleData.data_type == data_type)
vehicle_data_list = query.order_by(desc(VehicleData.timestamp)).limit(limit).all()
results = []
for data in vehicle_data_list:
try:
data_value = json.loads(data.data_value)
except:
data_value = data.data_value
results.append({
"id": data.id,
"vehicle_id": data.vehicle_id,
"vehicle_vin": data.vehicle_vin,
"data_type": data.data_type,
"data_value": data_value,
"timestamp": data.timestamp.isoformat(),
"is_active": data.is_active
})
return results
except Exception as e:
logger.error(f"按VIN获取车辆数据失败: {e}")
return []
def get_latest_vehicle_data(self, vehicle_id: str) -> Dict[str, Any]:
"""获取车辆最新数据"""
@@ -121,6 +158,34 @@ class VehicleDataManager:
except Exception as e:
logger.error(f"获取车辆最新数据失败: {e}")
return {}
def get_latest_vehicle_data_by_vin(self, vehicle_vin: str) -> Dict[str, Any]:
"""按VIN获取车辆最新数据"""
try:
with db_manager.get_session() as session:
data_types = ['location', 'status', 'fault', 'battery', 'engine']
latest_data: Dict[str, Any] = {}
for data_type in data_types:
data = session.query(VehicleData).filter(
VehicleData.vehicle_vin == vehicle_vin,
VehicleData.data_type == data_type,
VehicleData.is_active == True
).order_by(desc(VehicleData.timestamp)).first()
if data:
try:
data_value = json.loads(data.data_value)
except:
data_value = data.data_value
latest_data[data_type] = {
"value": data_value,
"timestamp": data.timestamp.isoformat(),
"vehicle_id": data.vehicle_id,
"vehicle_vin": data.vehicle_vin
}
return latest_data
except Exception as e:
logger.error(f"按VIN获取车辆最新数据失败: {e}")
return {}
def search_vehicle_data(
self,