Spaces:
Running
Running
| from typing import Dict, List, Any | |
| from collections import Counter | |
| import datetime | |
| class FeedbackAnalyzer: | |
| def __init__(self): | |
| self.feedback_db = None # Initialize your database connection here | |
| def get_feedback_stats(self) -> Dict[str, Any]: | |
| """Get statistics about user feedback""" | |
| stats = { | |
| "total_feedback": 0, | |
| "helpful_count": 0, | |
| "not_helpful_count": 0, | |
| "incorrect_count": 0, | |
| "improvement_suggestions": 0, | |
| "common_issues": [], | |
| "top_improved_questions": [] | |
| } | |
| # Calculate statistics from feedback database | |
| # Implementation depends on your database structure | |
| return stats | |
| def get_top_improvements(self, limit: int = 10) -> List[Dict[str, Any]]: | |
| """Get top user-suggested improvements""" | |
| improvements = [] | |
| # Fetch and sort improvements by usefulness | |
| return improvements[:limit] | |
| def export_feedback_report(self) -> str: | |
| """Generate a detailed feedback report""" | |
| stats = self.get_feedback_stats() | |
| improvements = self.get_top_improvements() | |
| report = f""" | |
| Feedback Analysis Report | |
| Generated: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')} | |
| Overall Statistics: | |
| - Total Feedback: {stats['total_feedback']} | |
| - Helpful Responses: {stats['helpful_count']} ({stats['helpful_count']/stats['total_feedback']*100:.1f}%) | |
| - Not Helpful: {stats['not_helpful_count']} | |
| - Incorrect: {stats['incorrect_count']} | |
| - Improvement Suggestions: {stats['improvement_suggestions']} | |
| Common Issues: | |
| {chr(10).join(f"- {issue}" for issue in stats['common_issues'])} | |
| Top Improved Questions: | |
| {chr(10).join(f"- {q}" for q in stats['top_improved_questions'])} | |
| """ | |
| return report |