'commit'
This commit is contained in:
@@ -6,20 +6,19 @@ import sys
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
# Ensure sys path includes root for imports if not already
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
if project_root not in sys.path:
|
||||
sys.path.append(project_root)
|
||||
|
||||
from Apps.AiTeJiYiChong.ReadImageKit import ReadImageKit
|
||||
from DbKit.Db import Db
|
||||
from Config.Config import DB_URL
|
||||
from Config.Config import DB_URL, PRICE_FLATTEN_TO_24H_GLOBAL
|
||||
from Model.StationProfile import StationProfile
|
||||
from Model.StationStatus import StationStatus
|
||||
from Model.StationPriceSchedule import StationPriceSchedule
|
||||
from Apps.AiTeJiYiChong.Config.Setting import PRICE_FLATTEN_TO_24H
|
||||
|
||||
# 配置日志
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class AiTeJiYiChongService:
|
||||
@@ -62,23 +61,29 @@ class AiTeJiYiChongService:
|
||||
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()
|
||||
|
||||
schedule_to_save = hourly_schedule
|
||||
|
||||
use_flatten = (PRICE_FLATTEN_TO_24H_GLOBAL or PRICE_FLATTEN_TO_24H) and isinstance(hourly_schedule, list)
|
||||
|
||||
if use_flatten:
|
||||
rows = ReadImageKit.expand_schedule_to_24h(hourly_schedule)
|
||||
if rows:
|
||||
schedule_to_save = rows
|
||||
|
||||
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
|
||||
schedule_json=schedule_to_save,
|
||||
valid_start_time=now,
|
||||
)
|
||||
await session.commit()
|
||||
return True
|
||||
@@ -94,8 +99,12 @@ class AiTeJiYiChongService:
|
||||
station_hash = self.get_hash(station_name)
|
||||
now = datetime.now()
|
||||
|
||||
# 将识别到的原始分时价格扩展为 24 小时整点数据
|
||||
hourly_schedule = ReadImageKit.expand_schedule_to_24h(prices)
|
||||
schedule_to_save = prices
|
||||
use_flatten = PRICE_FLATTEN_TO_24H_GLOBAL or PRICE_FLATTEN_TO_24H
|
||||
if use_flatten:
|
||||
rows = ReadImageKit.expand_schedule_to_24h(prices)
|
||||
if rows:
|
||||
schedule_to_save = rows
|
||||
|
||||
async with await self.db.get_session() as session:
|
||||
schedule_id = self.generate_id()
|
||||
@@ -103,13 +112,13 @@ class AiTeJiYiChongService:
|
||||
session=session,
|
||||
id=schedule_id,
|
||||
station_hash=station_hash,
|
||||
schedule_json=hourly_schedule,
|
||||
valid_start_time=now
|
||||
schedule_json=schedule_to_save,
|
||||
valid_start_time=now,
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
logger.info(f"三级页面价格详情处理完成: {station_name}, 共 {len(hourly_schedule)} 个小时段")
|
||||
return hourly_schedule
|
||||
logger.info(f"三级页面价格详情处理完成: {station_name}, 共 {len(schedule_to_save)} 条记录")
|
||||
return schedule_to_save
|
||||
|
||||
async def process_station_detail(self, image_path, station_name=None) -> dict:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user