File size: 2,344 Bytes
6bcf797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
from pathlib import Path
from sqlalchemy import func
from flask import Blueprint, render_template
from flask_login import login_required, current_user
from datetime import datetime

from extensions import db
from models import AnalysisReport

profile_bp = Blueprint('profile', __name__)


@profile_bp.route('/profile')
@login_required
def profile():
    # Получаем отчеты
    reports = AnalysisReport.query.filter_by(user_id=current_user.id) \
        .order_by(AnalysisReport.created_at.desc()) \
        .all()

    # Преобразуем в список словарей с правильными датами
    formatted_reports = []
    for report in reports:
        report_dict = {
            'content': report.content,
            'emotion': report.emotion,
            'confidence': report.confidence,
            'created_at': report.created_at.strftime('%Y-%m-%d %H:%M:%S') if report.created_at else None
        }
        formatted_reports.append(report_dict)

    # Получаем статистику по эмоциям
    emotion_stats = db.session.query(
        AnalysisReport.emotion,
        func.count(AnalysisReport.id).label('count')
    ).filter_by(user_id=current_user.id).group_by(AnalysisReport.emotion).all()

    most_common_emotion = max(emotion_stats, key=lambda x: x.count).emotion if emotion_stats else None
    total_reports = len(formatted_reports)

    # Полный словарь соответствий эмоций
    emotion_map = {
        'joy': '😊 Радость',
        'happy': '😊 Радость',
        'neutral': '😐 Нейтрально',
        'no_emotion': '😐 Нейтрально',
        'anger': '😠 Злость',
        'angry': '😠 Злость',
        'sadness': '😢 Грусть',
        'sad': '😢 Грусть',
        'surprise': '😲 Удивление',
        'fear': '😨 Страх',
        'disgust': '🤢 Отвращение'
    }

    return render_template('profile.html',
                           reports=formatted_reports,
                           most_common_emotion=most_common_emotion,
                           total_reports=total_reports,
                           emotion_map=emotion_map,
                           datetime=datetime)