File size: 1,446 Bytes
8ff1b66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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())