# Generated by Django 5.2.9 on 2025-12-30 02:15

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="FilterConfig",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                (
                    "indicator_code",
                    models.CharField(help_text="指标代码", max_length=50, unique=True),
                ),
                ("hp_enabled", models.BooleanField(default=True, help_text="是否启用 HP 滤波")),
                (
                    "hp_lambda",
                    models.DecimalField(
                        decimal_places=2,
                        default=129600,
                        help_text="HP 滤波 lambda 参数",
                        max_digits=20,
                    ),
                ),
                (
                    "kalman_enabled",
                    models.BooleanField(default=True, help_text="是否启用 Kalman 滤波"),
                ),
                (
                    "kalman_level_variance",
                    models.DecimalField(
                        decimal_places=6, default=0.05, help_text="Kalman 水平方差", max_digits=20
                    ),
                ),
                (
                    "kalman_slope_variance",
                    models.DecimalField(
                        decimal_places=6, default=0.005, help_text="Kalman 斜率方差", max_digits=20
                    ),
                ),
                (
                    "kalman_observation_variance",
                    models.DecimalField(
                        decimal_places=6, default=0.5, help_text="Kalman 观测方差", max_digits=20
                    ),
                ),
                ("description", models.TextField(blank=True, help_text="描述")),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "滤波器配置",
                "verbose_name_plural": "滤波器配置",
                "db_table": "filter_config",
            },
        ),
        migrations.CreateModel(
            name="KalmanStateModel",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                (
                    "indicator_code",
                    models.CharField(
                        db_index=True, help_text="指标代码", max_length=50, unique=True
                    ),
                ),
                ("level", models.DecimalField(decimal_places=6, help_text="水平值", max_digits=20)),
                ("slope", models.DecimalField(decimal_places=6, help_text="斜率值", max_digits=20)),
                (
                    "level_variance",
                    models.DecimalField(decimal_places=10, help_text="水平方差", max_digits=20),
                ),
                (
                    "slope_variance",
                    models.DecimalField(decimal_places=10, help_text="斜率方差", max_digits=20),
                ),
                (
                    "level_slope_cov",
                    models.DecimalField(
                        decimal_places=10, help_text="水平-斜率协方差", max_digits=20
                    ),
                ),
                ("params", models.JSONField(default=dict, help_text="使用的滤波参数")),
                ("last_observed_date", models.DateField(help_text="最后观测日期")),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Kalman 滤波器状态",
                "verbose_name_plural": "Kalman 滤波器状态",
                "db_table": "kalman_filter_state",
                "ordering": ["-updated_at"],
            },
        ),
        migrations.CreateModel(
            name="FilterResultModel",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
                (
                    "indicator_code",
                    models.CharField(
                        db_index=True, help_text="指标代码 (e.g., PMI, CPI)", max_length=50
                    ),
                ),
                ("date", models.DateField(db_index=True, help_text="数据日期")),
                (
                    "filter_type",
                    models.CharField(
                        choices=[("HP", "HP Filter"), ("KALMAN", "Kalman Filter")],
                        help_text="滤波器类型",
                        max_length=20,
                    ),
                ),
                ("params", models.JSONField(default=dict, help_text="滤波参数")),
                (
                    "original_value",
                    models.DecimalField(decimal_places=6, help_text="原始值", max_digits=20),
                ),
                (
                    "filtered_value",
                    models.DecimalField(
                        decimal_places=6, help_text="滤波后值（趋势）", max_digits=20
                    ),
                ),
                (
                    "cycle_value",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="周期分量（原始-趋势）",
                        max_digits=20,
                        null=True,
                    ),
                ),
                (
                    "trend_slope",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="趋势斜率（仅 Kalman）",
                        max_digits=20,
                        null=True,
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "滤波结果",
                "verbose_name_plural": "滤波结果",
                "db_table": "filter_result",
                "ordering": ["-date", "indicator_code"],
                "indexes": [
                    models.Index(
                        fields=["indicator_code", "-date"], name="filter_resu_indicat_fc09be_idx"
                    ),
                    models.Index(fields=["filter_type"], name="filter_resu_filter__3e5e8a_idx"),
                    models.Index(fields=["-date"], name="filter_resu_date_d54855_idx"),
                ],
                "unique_together": {("indicator_code", "date", "filter_type")},
            },
        ),
    ]
