"""Centralized constants for the TianXuan analysis module.

All magic numbers from analysis/tools/ and analysis/views/ are defined here
so they can be updated in one place. Import with::

    from analysis.constants import RANDOM_SEED, MAX_SAMPLE_ROWS, ...
"""

import polars as pl

# ---------------------------------------------------------------------------
#  Clustering / UMAP
# ---------------------------------------------------------------------------

MAX_SAMPLE_ROWS = 30000
"""Maximum rows for clustering sample (downsampling threshold, tuned for 8GB RAM)."""

MAX_DISTRIBUTION_SAMPLE = 10000
"""Default sample size for distribution exploration and scoring."""

UMAP_TRAIN_SAMPLE = 10000
"""Max rows used to train a UMAP reducer in extract_features."""

UMAP_BATCH_SIZE = 1000
"""Batch size for UMAP transform when dataset exceeds UMAP_TRAIN_SAMPLE."""

LOW_MEMORY_THRESHOLD_GB = 2
"""If available memory < this (in GiB), enable low-memory clustering path."""

LOW_MEMORY_THRESHOLD_ROWS = 100000
"""Row count above which low-memory downsampling is triggered."""

RANDOM_SEED = 42
"""Default random seed for all sklearn/numpy operations."""

# ---------------------------------------------------------------------------
#  Globe
# ---------------------------------------------------------------------------

GLOBE_MAX_ROWS = 300
"""Max rows to load per run for 3D globe visualization."""

# ---------------------------------------------------------------------------
#  Filter
# ---------------------------------------------------------------------------

FILTER_MAX_ROWS = 5
"""Maximum visible filter rows in the manual analysis UI (deprecated / reserved)."""

MAX_COLUMNS_PROFILE = 200
"""Max columns to include in a dataset profile summary."""

# ---------------------------------------------------------------------------
#  File upload limits
# ---------------------------------------------------------------------------

FILE_UPLOAD_MAX_SIZE = 500 * 1024 * 1024  # 500 MB
"""Maximum size for a single uploaded file."""

TOTAL_UPLOAD_MAX_SIZE = 50 * 1024 * 1024 * 1024  # 50 GB
"""Maximum total upload size across all files."""

# ---------------------------------------------------------------------------
#  Tool limits (numeric type tuples used across tools/)
# ---------------------------------------------------------------------------

NUMERIC_DTYPES: tuple[type[pl.DataType], ...] = (
    pl.Int8, pl.Int16, pl.Int32, pl.Int64,
    pl.UInt8, pl.UInt16, pl.UInt32, pl.UInt64,
    pl.Float32, pl.Float64,
)
"""Polars numeric data types — used for column selection in clustering,
entity aggregation, anomaly detection, and feature extraction."""

# ---------------------------------------------------------------------------
#  Diagnostics / Validation
# ---------------------------------------------------------------------------

MAX_VALIDATE_SAMPLE = 1000
"""Max rows sampled during validate_data."""

MAX_DIAGNOSE_SAMPLE = 5000
"""Max rows sampled for clustering diagnosis (SVD)."""

MAX_CLUSTER_FEATURES = 50
"""Feature count threshold above which TruncatedSVD is applied."""

CLUSTER_MAX_FEATURES_TOP = 10
"""Max feature columns selected by auto-detection in clustering tools."""

# ---------------------------------------------------------------------------
#  Globe / Flow extraction
# ---------------------------------------------------------------------------

GLOBE_FLOW_MAX_ROWS = 300
"""Alias for GLOBE_MAX_ROWS — max rows loaded for flow extraction."""
