File size: 1,022 Bytes
3214b6b
aada386
4cca9d6
 
e42fcaf
aada386
4cca9d6
aada386
 
 
 
 
 
8e0fcfe
4cca9d6
ce72c52
3214b6b
aada386
 
 
 
 
 
 
 
 
 
 
54f7978
aada386
 
 
 
 
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
import json
from datetime import datetime
import firebase_admin
from firebase_admin import credentials, firestore

# πŸ” Secure Firebase initialization
if not firebase_admin._apps:
    try:
        cred = credentials.Certificate("firebase_key.json")
        firebase_admin.initialize_app(cred)
    except Exception as e:
        print(f"❌ Firebase initialization failed: {e}")
        raise

db = firestore.client()

def log_user_feedback(goal, sol1, sol2, winner):
    try:
        formatted_winner = "1" if "1" in winner else "2"

        doc = {
            "timestamp": datetime.utcnow().isoformat(),
            "goal": goal.strip(),
            "solution_1": sol1.strip(),
            "solution_2": sol2.strip(),
            "winner": formatted_winner,
            "user_feedback": "from app.py"
        }

        db.collection("evo_feedback").add(doc)
        print(f"πŸ“₯ Logged feedback: Solution {formatted_winner}")
    except Exception as e:
        print(f"❌ Failed to log feedback: {e}")
        raise