Update main.py
Browse files
main.py
CHANGED
|
@@ -33,23 +33,70 @@ DOCS_PATH = "documents.pkl"
|
|
| 33 |
|
| 34 |
# --------- Fetch & Summarize Firestore Docs ---------
|
| 35 |
def fetch_documents() -> list[str]:
|
| 36 |
-
docs = []
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return docs
|
| 54 |
|
| 55 |
# --------- Embedding Helper ---------
|
|
|
|
| 33 |
|
| 34 |
# --------- Fetch & Summarize Firestore Docs ---------
|
| 35 |
def fetch_documents() -> list[str]:
|
| 36 |
+
docs: list[str] = []
|
| 37 |
+
|
| 38 |
+
# 1) Participants
|
| 39 |
+
for snap in fs.collection("participants").stream():
|
| 40 |
+
d = snap.to_dict()
|
| 41 |
+
name = d.get('name', 'Unknown Participant')
|
| 42 |
+
ent = d.get('enterpriseName', 'Unknown Enterprise')
|
| 43 |
+
sector = d.get('sector', 'Unknown Sector')
|
| 44 |
+
stage = d.get('stage', 'Unknown Stage')
|
| 45 |
+
devtype = d.get('developmentType', 'Unknown Type')
|
| 46 |
+
docs.append(
|
| 47 |
+
f"{name} ({ent}), sector: {sector}, stage: {stage}, type: {devtype}."
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
# 2) Interventions
|
| 51 |
+
for snap in fs.collection("interventions").stream():
|
| 52 |
+
d = snap.to_dict()
|
| 53 |
+
area = d.get('area', 'General')
|
| 54 |
+
for item in d.get('interventions', []):
|
| 55 |
+
title = item.get('title')
|
| 56 |
+
if title:
|
| 57 |
+
docs.append(f"Intervention: {title} under {area}.")
|
| 58 |
+
|
| 59 |
+
# 3) Feedbacks
|
| 60 |
+
for snap in fs.collection("feedbacks").stream():
|
| 61 |
+
d = snap.to_dict()
|
| 62 |
+
intervention = d.get('interventionTitle', 'Unknown Intervention')
|
| 63 |
+
smeName = d.get('smeName', 'Unknown SME')
|
| 64 |
+
comment = d.get('comment')
|
| 65 |
+
if comment:
|
| 66 |
+
docs.append(f"Feedback on {intervention} by {smeName}: {comment}")
|
| 67 |
+
|
| 68 |
+
# 4) Compliance Documents
|
| 69 |
+
for snap in fs.collection("complianceDocuments").stream():
|
| 70 |
+
d = snap.to_dict()
|
| 71 |
+
pName = d.get('participantName', 'Unknown Participant')
|
| 72 |
+
docType = d.get('documentType', 'Unknown Type')
|
| 73 |
+
status = d.get('status', 'Unknown Status')
|
| 74 |
+
expiry = d.get('expiryDate', 'Unknown Expiry')
|
| 75 |
+
docs.append(
|
| 76 |
+
f"Compliance document '{docType}' for {pName} is {status} (expires {expiry})."
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# 5) Assigned Interventions
|
| 80 |
+
for snap in fs.collection("assignedInterventions").stream():
|
| 81 |
+
d = snap.to_dict()
|
| 82 |
+
title = d.get('interventionTitle', 'Unknown Intervention')
|
| 83 |
+
smeName = d.get('smeName', 'Unknown SME')
|
| 84 |
+
cons = d.get('consultantId', 'Unknown Consultant')
|
| 85 |
+
status = d.get('status', 'Unknown Status')
|
| 86 |
+
docs.append(
|
| 87 |
+
f"Assigned intervention '{title}' for {smeName} by consultant {cons} ({status})."
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# 6) Consultants
|
| 91 |
+
for snap in fs.collection("consultants").stream():
|
| 92 |
+
d = snap.to_dict()
|
| 93 |
+
name = d.get('name', 'Unknown Consultant')
|
| 94 |
+
expertise= d.get('expertise', [])
|
| 95 |
+
rating = d.get('rating')
|
| 96 |
+
exp_txt = ", ".join(expertise) if expertise else "no listed expertise"
|
| 97 |
+
rating_txt = f"rating {rating}" if rating is not None else "no rating"
|
| 98 |
+
docs.append(f"Consultant {name} with expertise in {exp_txt} and {rating_txt}.")
|
| 99 |
+
|
| 100 |
return docs
|
| 101 |
|
| 102 |
# --------- Embedding Helper ---------
|