'commit'
This commit is contained in:
@@ -144,141 +144,15 @@ class AiTeJiYiChongService:
|
||||
logger.info(f"场站详情处理完成: {name}")
|
||||
return detail
|
||||
|
||||
async def process_station_list_hybrid(self, image_path, device_info=None) -> list:
|
||||
async def process_station_list_vl(self, image_path, json_metadata, device_info=None) -> list:
|
||||
"""
|
||||
基于混合模式处理场站列表 (图形学切片 + VL 模型)
|
||||
"""
|
||||
station_list = await ReadImageKit.get_stations_hybrid(image_path, device_info=device_info)
|
||||
if not station_list:
|
||||
return []
|
||||
|
||||
processed_stations = []
|
||||
async with await self.db.get_session() as session:
|
||||
for station in station_list:
|
||||
name = station.get("station_name")
|
||||
if not name:
|
||||
continue
|
||||
|
||||
station_hash = self.get_hash(name)
|
||||
now = datetime.now()
|
||||
station["station_hash"] = station_hash
|
||||
|
||||
# 1. 保存 Profile
|
||||
profile_id = self.generate_id()
|
||||
await self.station_profile_model.save(
|
||||
session=session,
|
||||
id=profile_id,
|
||||
station_hash=station_hash,
|
||||
operator=self.operator,
|
||||
station_name=name,
|
||||
valid_start_time=now
|
||||
)
|
||||
station["profile_id"] = profile_id
|
||||
station["valid_start_time"] = now.isoformat()
|
||||
|
||||
# 2. 保存 Status (解析价格和电桩)
|
||||
status_id = self.generate_id()
|
||||
|
||||
# 处理 piles 字段
|
||||
piles_data = station.get("piles")
|
||||
total, free = 0, 0
|
||||
standardized_piles = []
|
||||
if isinstance(piles_data, list):
|
||||
for idx, p in enumerate(piles_data):
|
||||
try:
|
||||
t = int(p.get("total", 0))
|
||||
f = int(p.get("free", 0))
|
||||
total += t
|
||||
free += f
|
||||
standardized_piles.append({
|
||||
"pile_no": f"G{idx+1}",
|
||||
"type": p.get("type", "未知"),
|
||||
"power": "",
|
||||
"status_text": f"空闲{f}/总{t}",
|
||||
"remark": "列表页VL"
|
||||
})
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
# Fallback: 如果不是列表(可能是字符串)
|
||||
piles_str = str(piles_data) if piles_data else "0/0"
|
||||
|
||||
nums = re.findall(r"\d+", piles_str)
|
||||
if len(nums) >= 2:
|
||||
# 假设最后两个数字是 free 和 total
|
||||
v1 = int(nums[-2])
|
||||
v2 = int(nums[-1])
|
||||
if v2 >= v1:
|
||||
free = v1
|
||||
total = v2
|
||||
else:
|
||||
free = v2
|
||||
total = v1
|
||||
|
||||
# 构造一条记录用于 Excel 展示
|
||||
standardized_piles.append({
|
||||
"pile_no": "-",
|
||||
"type": "未知",
|
||||
"status_text": piles_str,
|
||||
"remark": "原始识别文本"
|
||||
})
|
||||
else:
|
||||
# Fallback: 如果不是列表(可能是字符串)
|
||||
piles_str = str(piles_data) if piles_data else "0/0"
|
||||
|
||||
nums = re.findall(r"\d+", piles_str)
|
||||
if len(nums) >= 2:
|
||||
# 假设最后两个数字是 free 和 total
|
||||
v1 = int(nums[-2])
|
||||
v2 = int(nums[-1])
|
||||
if v2 >= v1:
|
||||
free = v1
|
||||
total = v2
|
||||
else:
|
||||
free = v2
|
||||
total = v1
|
||||
|
||||
# 构造一条记录用于 Excel 展示
|
||||
standardized_piles.append({
|
||||
"pile_no": "-",
|
||||
"type": "未知",
|
||||
"status_text": piles_str,
|
||||
"remark": "原始识别文本"
|
||||
})
|
||||
|
||||
await self.station_status_model.save(
|
||||
session=session,
|
||||
id=status_id,
|
||||
station_hash=station_hash,
|
||||
total_piles=total,
|
||||
free_piles=free,
|
||||
piles_detail_json=standardized_piles if standardized_piles else None,
|
||||
current_price=self._to_float(station.get("price")),
|
||||
parking_info=station.get("parking", ""),
|
||||
distance=station.get("distance", ""),
|
||||
valid_start_time=now
|
||||
)
|
||||
station["status_id"] = status_id
|
||||
|
||||
processed_stations.append(station)
|
||||
|
||||
await session.commit()
|
||||
|
||||
return processed_stations
|
||||
|
||||
async def process_station_list_vl(self, image_path, device_info=None) -> list:
|
||||
"""
|
||||
基于 VL 模式处理场站列表
|
||||
基于 VL 模式处理场站列表 (整页识别)
|
||||
"""
|
||||
# 优先使用带绿框的 _vl.jpg 图片进行识别
|
||||
vl_img_path = image_path.replace(".jpg", "_vl.jpg")
|
||||
if os.path.exists(vl_img_path):
|
||||
logger.info(f"使用带绿框的图片进行识别: {vl_img_path}")
|
||||
image_to_process = vl_img_path
|
||||
else:
|
||||
image_to_process = image_path
|
||||
img_to_process = vl_img_path if os.path.exists(vl_img_path) else image_path
|
||||
|
||||
station_list = await ReadImageKit.get_stations_from_image(image_to_process, device_info=device_info)
|
||||
station_list = await ReadImageKit.parse_vl_image(img_to_process, json_metadata, device_info=device_info)
|
||||
if not station_list:
|
||||
return []
|
||||
|
||||
@@ -328,8 +202,8 @@ class AiTeJiYiChongService:
|
||||
"remark": "列表页VL"
|
||||
})
|
||||
except:
|
||||
pass
|
||||
|
||||
continue
|
||||
|
||||
await self.station_status_model.save(
|
||||
session=session,
|
||||
id=status_id,
|
||||
@@ -345,7 +219,7 @@ class AiTeJiYiChongService:
|
||||
station["status_id"] = status_id
|
||||
|
||||
processed_stations.append(station)
|
||||
|
||||
|
||||
await session.commit()
|
||||
|
||||
return processed_stations
|
||||
|
||||
Reference in New Issue
Block a user