File size: 1,960 Bytes
ee79eb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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