Files
tianxuan/analysis/migrations/0001_initial.py
T

85 lines
5.0 KiB
Python

# Generated by Django 4.2.30 on 2026-07-13 14:36
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='AnalysisRun',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('csv_glob', models.CharField(help_text='Glob pattern for CSV files', max_length=1024)),
('config', models.JSONField(blank=True, default=dict, help_text='YAML config snapshot')),
('status', models.CharField(choices=[('pending', 'Pending'), ('loading', 'Loading Data'), ('profiling', 'Profiling'), ('aggregating', 'Building Entity Profiles'), ('clustering', 'Clustering'), ('extracting', 'Extracting Features'), ('completed', 'Completed'), ('failed', 'Failed')], default='pending', max_length=32)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('error_message', models.TextField(blank=True, default='')),
('total_flows', models.IntegerField(blank=True, null=True)),
('entity_count', models.IntegerField(blank=True, null=True)),
('cluster_count', models.IntegerField(blank=True, null=True)),
('entity_column', models.CharField(blank=True, default='', help_text='Auto-detected entity column name', max_length=256)),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='ClusterResult',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cluster_label', models.IntegerField(help_text='Cluster label (-1 for noise)')),
('size', models.IntegerField(help_text='Number of entities in this cluster')),
('proportion', models.FloatField(blank=True, help_text='Proportion of total entities', null=True)),
('noise_ratio', models.FloatField(blank=True, help_text='Noise ratio of the clustering', null=True)),
('silhouette_score', models.FloatField(blank=True, help_text='Silhouette score (sampled if large)', null=True)),
('run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='clusters', to='tianxuan_analysis.analysisrun')),
],
options={
'unique_together': {('run', 'cluster_label')},
},
),
migrations.CreateModel(
name='EntityProfile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('entity_value', models.CharField(help_text='Entity identifier (IP, domain, etc.)', max_length=512)),
('cluster_label', models.IntegerField(blank=True, help_text='Assigned cluster (-1=noise)', null=True)),
('feature_json', models.JSONField(blank=True, default=dict, help_text='Aggregated entity features as dict')),
('embedding_x', models.FloatField(blank=True, help_text='PCA-2D X coordinate', null=True)),
('embedding_y', models.FloatField(blank=True, help_text='PCA-2D Y coordinate', null=True)),
('cluster', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='entities', to='tianxuan_analysis.clusterresult')),
('run', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='entities', to='tianxuan_analysis.analysisrun')),
],
options={
'unique_together': {('run', 'entity_value')},
},
),
migrations.CreateModel(
name='ClusterFeature',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('feature_name', models.CharField(max_length=256)),
('mean', models.FloatField(blank=True, null=True)),
('std', models.FloatField(blank=True, null=True)),
('median', models.FloatField(blank=True, null=True)),
('p25', models.FloatField(blank=True, null=True)),
('p75', models.FloatField(blank=True, null=True)),
('missing_rate', models.FloatField(blank=True, null=True)),
('distinguishing_score', models.FloatField(blank=True, help_text='Z-score or ANOVA F-score', null=True)),
('distinguishing_method', models.CharField(default='zscore', max_length=16)),
('cluster', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='features', to='tianxuan_analysis.clusterresult')),
],
options={
'unique_together': {('cluster', 'feature_name')},
},
),
]