Spaces:
Running
Running
| import asyncio | |
| import os | |
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from dotenv import load_dotenv | |
| # Załaduj .env z głównego katalogu lub katalogu backend | |
| load_dotenv(".env") | |
| load_dotenv("backend/.env") | |
| async def check_stats(): | |
| # Pobranie parametrów z .env | |
| mongo_url = os.getenv("MONGODB_URL") | |
| db_name = os.getenv("MONGODB_DB_NAME", "sentimentSummary") | |
| if not mongo_url: | |
| print("ERROR: MONGODB_URL not found in .env file!") | |
| return | |
| print(f"Connecting to MongoDB: {mongo_url.split('@')[-1]}...") # Pokazuje tylko hosta dla bezpieczeństwa | |
| try: | |
| client = AsyncIOMotorClient(mongo_url) | |
| db = client[db_name] | |
| collection = db["games"] | |
| total = await collection.count_documents({}) | |
| with_cn = await collection.count_documents({ | |
| "name_cn": {"$exists": True, "$ne": None, "$nin": ["", "null", "None"]} | |
| }) | |
| print("\n" + "="*30) | |
| print(f"DATABASE STATS") | |
| print("="*30) | |
| print(f"Total games: {total}") | |
| print(f"With Chinese: {with_cn}") | |
| if total > 0: | |
| percentage = (with_cn / total) * 100 | |
| print(f"Coverage: {percentage:.2f}%") | |
| print("="*30) | |
| client.close() | |
| except Exception as e: | |
| print(f"ERROR: Could not connect or query DB: {e}") | |
| if __name__ == "__main__": | |
| asyncio.run(check_stats()) | |