2026-01-24 02:48:56 +08:00
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
2026-01-26 21:10:42 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
# Add parent directory to path to allow importing web module
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
|
|
from web.services.feature_service import FeatureService
|
|
|
|
|
from web.config import Config
|
|
|
|
|
import sqlite3
|
2026-01-24 02:48:56 +08:00
|
|
|
|
|
|
|
|
# Setup logging
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2026-01-26 21:10:42 +08:00
|
|
|
L3_DB_PATH = Config.DB_L3_PATH
|
|
|
|
|
SCHEMA_PATH = os.path.join(Config.BASE_DIR, 'database', 'L3', 'schema.sql')
|
2026-01-24 02:48:56 +08:00
|
|
|
|
|
|
|
|
def init_db():
|
2026-01-26 21:10:42 +08:00
|
|
|
l3_dir = os.path.dirname(L3_DB_PATH)
|
|
|
|
|
if not os.path.exists(l3_dir):
|
|
|
|
|
os.makedirs(l3_dir)
|
2026-01-24 02:48:56 +08:00
|
|
|
|
|
|
|
|
conn = sqlite3.connect(L3_DB_PATH)
|
|
|
|
|
with open(SCHEMA_PATH, 'r', encoding='utf-8') as f:
|
|
|
|
|
conn.executescript(f.read())
|
|
|
|
|
conn.commit()
|
|
|
|
|
conn.close()
|
2026-01-26 21:10:42 +08:00
|
|
|
logger.info("L3 DB Initialized/Updated with Schema.")
|
2026-01-24 02:48:56 +08:00
|
|
|
|
2026-01-26 21:10:42 +08:00
|
|
|
def main():
|
|
|
|
|
logger.info("Starting L3 Builder (Delegating to FeatureService)...")
|
2026-01-24 02:48:56 +08:00
|
|
|
|
2026-01-26 21:10:42 +08:00
|
|
|
# 1. Ensure Schema is up to date
|
|
|
|
|
init_db()
|
2026-01-24 02:48:56 +08:00
|
|
|
|
2026-01-26 21:10:42 +08:00
|
|
|
# 2. Rebuild Features using the centralized logic
|
2026-01-24 02:48:56 +08:00
|
|
|
try:
|
2026-01-26 21:10:42 +08:00
|
|
|
count = FeatureService.rebuild_all_features()
|
|
|
|
|
logger.info(f"Successfully rebuilt features for {count} players.")
|
2026-01-24 02:48:56 +08:00
|
|
|
except Exception as e:
|
2026-01-26 21:10:42 +08:00
|
|
|
logger.error(f"Error rebuilding features: {e}")
|
|
|
|
|
import traceback
|
|
|
|
|
traceback.print_exc()
|
2026-01-24 02:48:56 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-01-26 21:10:42 +08:00
|
|
|
main()
|