99 lines
3.0 KiB
Python
99 lines
3.0 KiB
Python
"""
|
|
Analytics and statistics models.
|
|
"""
|
|
from django.db import models
|
|
from django.contrib.auth import get_user_model
|
|
from reports.models import ScamReport
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class ReportStatistic(models.Model):
|
|
"""
|
|
Aggregated statistics for reports.
|
|
"""
|
|
date = models.DateField(unique=True)
|
|
total_reports = models.IntegerField(default=0)
|
|
pending_reports = models.IntegerField(default=0)
|
|
verified_reports = models.IntegerField(default=0)
|
|
rejected_reports = models.IntegerField(default=0)
|
|
|
|
# By scam type
|
|
phishing_count = models.IntegerField(default=0)
|
|
fake_website_count = models.IntegerField(default=0)
|
|
romance_scam_count = models.IntegerField(default=0)
|
|
investment_scam_count = models.IntegerField(default=0)
|
|
tech_support_scam_count = models.IntegerField(default=0)
|
|
identity_theft_count = models.IntegerField(default=0)
|
|
fake_product_count = models.IntegerField(default=0)
|
|
advance_fee_count = models.IntegerField(default=0)
|
|
other_count = models.IntegerField(default=0)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
db_table = 'analytics_reportstatistic'
|
|
verbose_name = 'Report Statistic'
|
|
verbose_name_plural = 'Report Statistics'
|
|
ordering = ['-date']
|
|
indexes = [
|
|
models.Index(fields=['date']),
|
|
]
|
|
|
|
def __str__(self):
|
|
return f"Statistics for {self.date}"
|
|
|
|
|
|
class UserStatistic(models.Model):
|
|
"""
|
|
User activity statistics.
|
|
"""
|
|
date = models.DateField(unique=True)
|
|
total_users = models.IntegerField(default=0)
|
|
new_users = models.IntegerField(default=0)
|
|
active_users = models.IntegerField(
|
|
default=0,
|
|
help_text='Users who logged in'
|
|
)
|
|
moderators = models.IntegerField(default=0)
|
|
admins = models.IntegerField(default=0)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
db_table = 'analytics_userstatistic'
|
|
verbose_name = 'User Statistic'
|
|
verbose_name_plural = 'User Statistics'
|
|
ordering = ['-date']
|
|
|
|
def __str__(self):
|
|
return f"User Statistics for {self.date}"
|
|
|
|
|
|
class OSINTStatistic(models.Model):
|
|
"""
|
|
OSINT task and result statistics.
|
|
"""
|
|
date = models.DateField(unique=True)
|
|
total_tasks = models.IntegerField(default=0)
|
|
completed_tasks = models.IntegerField(default=0)
|
|
failed_tasks = models.IntegerField(default=0)
|
|
average_confidence = models.FloatField(
|
|
default=0.0,
|
|
help_text='Average confidence score'
|
|
)
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
db_table = 'analytics_osintstatistic'
|
|
verbose_name = 'OSINT Statistic'
|
|
verbose_name_plural = 'OSINT Statistics'
|
|
ordering = ['-date']
|
|
|
|
def __str__(self):
|
|
return f"OSINT Statistics for {self.date}"
|