@@ -293,6 +293,83 @@ async def get_trending_patterns(self, language: str = "en", time_range: str = "7
293293 logger .error (f"❌ Failed to get trending patterns: { e } " )
294294 return {"trending_patterns" : [], "time_range" : time_range , "language" : language }
295295
296+ # Analysis operations
297+ async def store_analysis (self , analysis_id : str , analysis_data : Dict [str , Any ]) -> bool :
298+ """Store analysis record."""
299+ try :
300+ client = self ._get_client ()
301+ doc_ref = client .collection ("analyses" ).document (analysis_id )
302+ await doc_ref .set (analysis_data )
303+ logger .info (f"✅ Stored analysis { analysis_id } " )
304+ return True
305+ except Exception as e :
306+ logger .error (f"❌ Failed to store analysis { analysis_id } : { e } " )
307+ return False
308+
309+ async def update_analysis (self , analysis_id : str , update_data : Dict [str , Any ]) -> bool :
310+ """Update existing analysis record."""
311+ try :
312+ client = self ._get_client ()
313+ doc_ref = client .collection ("analyses" ).document (analysis_id )
314+ await doc_ref .update (update_data )
315+ logger .info (f"✅ Updated analysis { analysis_id } " )
316+ return True
317+ except Exception as e :
318+ logger .error (f"❌ Failed to update analysis { analysis_id } : { e } " )
319+ return False
320+
321+ async def get_analysis (self , analysis_id : str ) -> Optional [Dict [str , Any ]]:
322+ """Get analysis record by ID."""
323+ try :
324+ client = self ._get_client ()
325+ doc_ref = client .collection ("analyses" ).document (analysis_id )
326+ doc = await doc_ref .get ()
327+
328+ if doc .exists :
329+ return doc .to_dict ()
330+ return None
331+ except Exception as e :
332+ logger .error (f"❌ Failed to get analysis { analysis_id } : { e } " )
333+ return None
334+
335+ async def store_batch_analysis (self , batch_id : str , batch_data : Dict [str , Any ]) -> bool :
336+ """Store batch analysis record."""
337+ try :
338+ client = self ._get_client ()
339+ doc_ref = client .collection ("batch_analyses" ).document (batch_id )
340+ await doc_ref .set (batch_data )
341+ logger .info (f"✅ Stored batch analysis { batch_id } " )
342+ return True
343+ except Exception as e :
344+ logger .error (f"❌ Failed to store batch analysis { batch_id } : { e } " )
345+ return False
346+
347+ async def update_batch_analysis (self , batch_id : str , update_data : Dict [str , Any ]) -> bool :
348+ """Update existing batch analysis record."""
349+ try :
350+ client = self ._get_client ()
351+ doc_ref = client .collection ("batch_analyses" ).document (batch_id )
352+ await doc_ref .update (update_data )
353+ logger .info (f"✅ Updated batch analysis { batch_id } " )
354+ return True
355+ except Exception as e :
356+ logger .error (f"❌ Failed to update batch analysis { batch_id } : { e } " )
357+ return False
358+
359+ async def get_batch_analysis (self , batch_id : str ) -> Optional [Dict [str , Any ]]:
360+ """Get batch analysis record by ID."""
361+ try :
362+ client = self ._get_client ()
363+ doc_ref = client .collection ("batch_analyses" ).document (batch_id )
364+ doc = await doc_ref .get ()
365+
366+ if doc .exists :
367+ return doc .to_dict ()
368+ return None
369+ except Exception as e :
370+ logger .error (f"❌ Failed to get batch analysis { batch_id } : { e } " )
371+ return None
372+
296373
297374# Global database manager instance
298375db_manager = FirestoreManager ()
0 commit comments