Spaces:
No application file
No application file
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__) | |
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) | |