'commit'
This commit is contained in:
@@ -42,6 +42,89 @@ class AiTeJiYiChongService:
|
||||
async def close_db(self):
|
||||
await self.db.close()
|
||||
|
||||
async def process_price_detail_data(self, station_name, hourly_schedule) -> bool:
|
||||
"""
|
||||
直接保存已处理好的小时段价格数据
|
||||
"""
|
||||
if not station_name or not hourly_schedule:
|
||||
return False
|
||||
|
||||
station_hash = self.get_hash(station_name)
|
||||
now = datetime.now()
|
||||
|
||||
async with await self.db.get_session() as session:
|
||||
schedule_id = self.generate_id()
|
||||
await self.station_price_schedule_model.save(
|
||||
session=session,
|
||||
id=schedule_id,
|
||||
station_hash=station_hash,
|
||||
schedule_json=hourly_schedule,
|
||||
valid_start_time=now
|
||||
)
|
||||
await session.commit()
|
||||
return True
|
||||
|
||||
async def process_price_detail(self, image_path, station_name) -> list:
|
||||
"""
|
||||
处理三级价格详情页截图
|
||||
"""
|
||||
prices = await ReadImageKit.get_price_detail_from_image(image_path)
|
||||
if not prices:
|
||||
return None
|
||||
|
||||
station_hash = self.get_hash(station_name)
|
||||
now = datetime.now()
|
||||
|
||||
# 将识别到的原始分时价格扩展为 24 小时整点数据
|
||||
hourly_schedule = ReadImageKit.expand_schedule_to_24h(prices)
|
||||
|
||||
async with await self.db.get_session() as session:
|
||||
schedule_id = self.generate_id()
|
||||
await self.station_price_schedule_model.save(
|
||||
session=session,
|
||||
id=schedule_id,
|
||||
station_hash=station_hash,
|
||||
schedule_json=hourly_schedule,
|
||||
valid_start_time=now
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
logger.info(f"三级页面价格详情处理完成: {station_name}, 共 {len(hourly_schedule)} 个小时段")
|
||||
return hourly_schedule
|
||||
|
||||
async def process_station_detail(self, image_path, station_name=None) -> dict:
|
||||
"""
|
||||
处理场站详情页截图
|
||||
"""
|
||||
detail = await ReadImageKit.get_station_detail_from_image(image_path)
|
||||
if not detail:
|
||||
return None
|
||||
|
||||
name = station_name or detail.get("station_name")
|
||||
if not name:
|
||||
return None
|
||||
|
||||
station_hash = self.get_hash(name)
|
||||
now = datetime.now()
|
||||
|
||||
async with await self.db.get_session() as session:
|
||||
# 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,
|
||||
address=detail.get("address"),
|
||||
valid_start_time=now
|
||||
)
|
||||
|
||||
await session.commit()
|
||||
|
||||
logger.info(f"场站详情处理完成: {name}")
|
||||
return detail
|
||||
|
||||
async def process_station_list_vl(self, image_path, device_info=None) -> list:
|
||||
"""
|
||||
基于 VL 模式处理场站列表
|
||||
|
||||
Reference in New Issue
Block a user