# Generated by Django 5.2.9 on 2026-01-04 03:49

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("sentiment", "0002_delete_sentimentanalysislog_delete_sentimentcache_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="SentimentCache",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "text_hash",
                    models.CharField(
                        db_index=True, max_length=64, unique=True, verbose_name="文本哈希"
                    ),
                ),
                (
                    "sentiment_score",
                    models.FloatField(
                        validators=[
                            django.core.validators.MinValueValidator(-3.0),
                            django.core.validators.MaxValueValidator(3.0),
                        ],
                        verbose_name="情感评分",
                    ),
                ),
                ("category", models.CharField(max_length=20, verbose_name="情感分类")),
                (
                    "confidence",
                    models.FloatField(
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                        verbose_name="置信度",
                    ),
                ),
                ("keywords", models.JSONField(blank=True, default=list, verbose_name="关键词")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
            ],
            options={
                "verbose_name": "情感分析缓存",
                "verbose_name_plural": "情感分析缓存",
                "db_table": "sentiment_cache",
                "ordering": ["-updated_at"],
            },
        ),
        migrations.CreateModel(
            name="SentimentIndexModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "index_date",
                    models.DateField(db_index=True, unique=True, verbose_name="指数日期"),
                ),
                (
                    "news_sentiment",
                    models.FloatField(
                        default=0.0,
                        validators=[
                            django.core.validators.MinValueValidator(-3.0),
                            django.core.validators.MaxValueValidator(3.0),
                        ],
                        verbose_name="新闻情绪",
                    ),
                ),
                (
                    "policy_sentiment",
                    models.FloatField(
                        default=0.0,
                        validators=[
                            django.core.validators.MinValueValidator(-3.0),
                            django.core.validators.MaxValueValidator(3.0),
                        ],
                        verbose_name="政策情绪",
                    ),
                ),
                (
                    "composite_index",
                    models.FloatField(
                        db_index=True,
                        default=0.0,
                        validators=[
                            django.core.validators.MinValueValidator(-3.0),
                            django.core.validators.MaxValueValidator(3.0),
                        ],
                        verbose_name="综合指数",
                    ),
                ),
                (
                    "confidence_level",
                    models.FloatField(
                        default=0.0,
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                        verbose_name="置信度",
                    ),
                ),
                (
                    "sector_sentiment",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text='格式: {"金融": 0.5, "科技": 0.8}',
                        verbose_name="行业情绪",
                    ),
                ),
                ("news_count", models.IntegerField(default=0, verbose_name="新闻数量")),
                (
                    "policy_events_count",
                    models.IntegerField(default=0, verbose_name="政策事件数量"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
            ],
            options={
                "verbose_name": "情绪指数",
                "verbose_name_plural": "情绪指数",
                "db_table": "sentiment_index",
                "ordering": ["-index_date"],
            },
        ),
        migrations.CreateModel(
            name="SentimentAnalysisLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "source_type",
                    models.CharField(
                        help_text="news/policy/social/manual",
                        max_length=50,
                        verbose_name="数据源类型",
                    ),
                ),
                (
                    "source_id",
                    models.CharField(
                        blank=True, max_length=100, null=True, verbose_name="数据源ID"
                    ),
                ),
                ("input_text", models.TextField(verbose_name="输入文本")),
                (
                    "sentiment_score",
                    models.FloatField(
                        validators=[
                            django.core.validators.MinValueValidator(-3.0),
                            django.core.validators.MaxValueValidator(3.0),
                        ],
                        verbose_name="情感评分",
                    ),
                ),
                ("category", models.CharField(max_length=20, verbose_name="情感分类")),
                (
                    "confidence",
                    models.FloatField(
                        validators=[
                            django.core.validators.MinValueValidator(0.0),
                            django.core.validators.MaxValueValidator(1.0),
                        ],
                        verbose_name="置信度",
                    ),
                ),
                ("keywords", models.JSONField(blank=True, default=list, verbose_name="关键词")),
                (
                    "ai_provider",
                    models.CharField(
                        blank=True, max_length=100, null=True, verbose_name="AI提供商"
                    ),
                ),
                (
                    "ai_model",
                    models.CharField(blank=True, max_length=100, null=True, verbose_name="AI模型"),
                ),
                (
                    "ai_response_time_ms",
                    models.IntegerField(blank=True, null=True, verbose_name="AI响应时间(ms)"),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="创建时间"),
                ),
            ],
            options={
                "verbose_name": "情感分析日志",
                "verbose_name_plural": "情感分析日志",
                "db_table": "sentiment_analysis_log",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["source_type", "source_id"], name="sentiment_a_source__c7c7fc_idx"
                    ),
                    models.Index(fields=["-created_at"], name="sentiment_a_created_ad51b1_idx"),
                ],
            },
        ),
    ]
