-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
92 lines (77 loc) · 4.08 KB
/
models.py
File metadata and controls
92 lines (77 loc) · 4.08 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from datetime import datetime
from extensions import db
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
class Admin(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password_hash = db.Column(db.String(256))
email_notifications = db.Column(db.Boolean, default=True)
receive_synthesis_copy = db.Column(db.Boolean, default=False)
is_superuser = db.Column(db.Boolean, default=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
last_login = db.Column(db.DateTime)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
def update_last_login(self):
self.last_login = datetime.utcnow()
db.session.commit()
@classmethod
def create(cls, username, email, password=None, is_superuser=False):
admin = cls()
admin.username = username
admin.email = email
if password:
admin.set_password(password)
admin.is_superuser = is_superuser
return admin
@property
def can_manage_admins(self):
return self.is_superuser
class Synthesis(db.Model):
__tablename__ = 'synthesis'
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
archived = db.Column(db.Boolean, default=False)
archive_date = db.Column(db.DateTime, nullable=True)
questions = db.relationship('Question', backref='synthesis', lazy=True)
class Question(db.Model):
__tablename__ = 'questions'
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text, nullable=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
processed = db.Column(db.Boolean, default=False)
synthesis_id = db.Column(db.Integer, db.ForeignKey('synthesis.id'), nullable=True)
@staticmethod
def get_statistics():
"""Calcule les statistiques sur les questions et génère une description détaillée"""
from sqlalchemy import func
total_questions = Question.query.count()
processed_questions = Question.query.filter_by(processed=True).count()
unprocessed_questions = Question.query.filter_by(processed=False).count()
# Statistiques par jour
questions_by_day = db.session.query(
func.date(Question.created_at).label('date'),
func.count(Question.id).label('count')
).group_by(func.date(Question.created_at)).all()
# Conversion en format adapté pour Chart.js
dates = [str(stat.date) for stat in questions_by_day]
counts = [stat.count for stat in questions_by_day]
# Construction de la description détaillée
if total_questions == 0:
transformation_description = "Aucune question n'a encore été soumise au système."
else:
processed_percent = (processed_questions / total_questions * 100) if total_questions > 0 else 0
transformation_description = f"Sur l'ensemble des {total_questions} questions reçues :\n• {processed_questions} questions ({processed_percent:.1f}%) ont été traitées par le LLM\n• {unprocessed_questions} questions sont en attente de traitement\n\nLe processus de transformation comprend :\n1. La modération automatique pour filtrer les contenus inappropriés\n2. L'identification et la fusion des questions similaires\n3. La génération d'une synthèse structurée des questions restantes"
return {
'total': total_questions,
'processed': processed_questions,
'unprocessed': unprocessed_questions,
'dates': dates,
'counts': counts,
'transformation_description': transformation_description
}