rairo commited on
Commit
4c92169
·
verified ·
1 Parent(s): 4d7d709

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +64 -17
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
- for col in [
38
- ("participants", lambda d: f"{d['name']} ({d['enterpriseName']}), sector: {d['sector']}, stage: {d['stage']}, type: {d['developmentType']}."),
39
- ("interventions", lambda d: [f"Intervention: {i['title']} under {d['area']}." for i in d.get("interventions", [])]),
40
- ("feedbacks", lambda d: f"Feedback on {d['interventionTitle']} by {d['smeName']}: {d['comment']}"),
41
- ("complianceDocuments", lambda d: f"Compliance document '{d['documentType']}' for {d['participantName']} is {d['status']} (expires {d['expiryDate']})."),
42
- ("assignedInterventions", lambda d: f"Assigned '{d['interventionTitle']}' for {d['smeName']} by consultant {d['consultantId']} ({d['status']})."),
43
- ("consultants", lambda d: f"Consultant {d['name']} – expertise: {', '.join(d.get('expertise', []))}, rating: {d['rating']}.")
44
- ]:
45
- for snap in fs.collection(col[0]).stream():
46
- entry = snap.to_dict()
47
- out = col[1](entry)
48
- # flatten lists
49
- if isinstance(out, list):
50
- docs.extend(out)
51
- else:
52
- docs.append(out)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ---------