Files
ETB/ETB-API/analytics_predictive_insights/migrations/0001_initial.py
Iliyan Angelov 6b247e5b9f Updates
2025-09-19 11:58:53 +03:00

312 lines
25 KiB
Python

# Generated by Django 5.2.6 on 2025-09-18 17:16
import django.core.validators
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('incident_intelligence', '0004_incident_oncall_assignment_incident_sla_override_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='HeatmapData',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('heatmap_type', models.CharField(choices=[('INCIDENT_FREQUENCY', 'Incident Frequency'), ('RESOLUTION_TIME', 'Resolution Time'), ('COST_IMPACT', 'Cost Impact'), ('ANOMALY_DENSITY', 'Anomaly Density'), ('SLA_PERFORMANCE', 'SLA Performance')], max_length=20)),
('time_period_start', models.DateTimeField()),
('time_period_end', models.DateTimeField()),
('time_granularity', models.CharField(choices=[('HOUR', 'Hour'), ('DAY', 'Day'), ('WEEK', 'Week'), ('MONTH', 'Month')], max_length=20)),
('data_points', models.JSONField(help_text='Heatmap data points with coordinates and values')),
('color_scheme', models.CharField(default='viridis', help_text='Color scheme for the heatmap', max_length=50)),
('aggregation_method', models.CharField(choices=[('SUM', 'Sum'), ('AVERAGE', 'Average'), ('COUNT', 'Count'), ('MAX', 'Maximum'), ('MIN', 'Minimum')], max_length=20)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
options={
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['heatmap_type', 'time_period_start'], name='analytics_p_heatmap_61786e_idx'), models.Index(fields=['time_granularity'], name='analytics_p_time_gr_6c8e73_idx')],
},
),
migrations.CreateModel(
name='KPIMetric',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('description', models.TextField()),
('metric_type', models.CharField(choices=[('MTTA', 'Mean Time to Acknowledge'), ('MTTR', 'Mean Time to Resolve'), ('MTBF', 'Mean Time Between Failures'), ('MTBSI', 'Mean Time Between Service Incidents'), ('AVAILABILITY', 'Service Availability'), ('INCIDENT_COUNT', 'Incident Count'), ('RESOLUTION_RATE', 'Resolution Rate'), ('ESCALATION_RATE', 'Escalation Rate'), ('CUSTOM', 'Custom Metric')], max_length=20)),
('aggregation_type', models.CharField(choices=[('AVERAGE', 'Average'), ('MEDIAN', 'Median'), ('MIN', 'Minimum'), ('MAX', 'Maximum'), ('SUM', 'Sum'), ('COUNT', 'Count'), ('PERCENTILE_95', '95th Percentile'), ('PERCENTILE_99', '99th Percentile')], max_length=20)),
('incident_categories', models.JSONField(default=list, help_text='List of incident categories this metric applies to')),
('incident_severities', models.JSONField(default=list, help_text='List of incident severities this metric applies to')),
('incident_priorities', models.JSONField(default=list, help_text='List of incident priorities this metric applies to')),
('calculation_formula', models.TextField(blank=True, help_text='Custom calculation formula for complex metrics', null=True)),
('time_window_hours', models.PositiveIntegerField(default=24, help_text='Time window for metric calculation in hours')),
('is_active', models.BooleanField(default=True)),
('is_system_metric', models.BooleanField(default=False, help_text='Whether this is a system-defined metric')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='KPIMeasurement',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('value', models.DecimalField(decimal_places=4, max_digits=15)),
('unit', models.CharField(help_text='Unit of measurement (minutes, hours, percentage, etc.)', max_length=50)),
('measurement_period_start', models.DateTimeField()),
('measurement_period_end', models.DateTimeField()),
('incident_count', models.PositiveIntegerField(default=0, help_text='Number of incidents included in this measurement')),
('sample_size', models.PositiveIntegerField(default=0, help_text='Total sample size for this measurement')),
('metadata', models.JSONField(default=dict, help_text='Additional metadata for this measurement')),
('calculated_at', models.DateTimeField(auto_now_add=True)),
('metric', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='measurements', to='analytics_predictive_insights.kpimetric')),
],
options={
'ordering': ['-calculated_at'],
},
),
migrations.CreateModel(
name='PredictiveModel',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('description', models.TextField()),
('model_type', models.CharField(choices=[('ANOMALY_DETECTION', 'Anomaly Detection'), ('INCIDENT_PREDICTION', 'Incident Prediction'), ('SEVERITY_PREDICTION', 'Severity Prediction'), ('RESOLUTION_TIME_PREDICTION', 'Resolution Time Prediction'), ('ESCALATION_PREDICTION', 'Escalation Prediction'), ('COST_PREDICTION', 'Cost Impact Prediction')], max_length=30)),
('algorithm_type', models.CharField(choices=[('ISOLATION_FOREST', 'Isolation Forest'), ('LSTM', 'Long Short-Term Memory'), ('RANDOM_FOREST', 'Random Forest'), ('XGBOOST', 'XGBoost'), ('SVM', 'Support Vector Machine'), ('NEURAL_NETWORK', 'Neural Network'), ('ARIMA', 'ARIMA'), ('PROPHET', 'Prophet')], max_length=20)),
('model_config', models.JSONField(default=dict, help_text='Model-specific configuration parameters')),
('feature_columns', models.JSONField(default=list, help_text='List of feature columns used by the model')),
('target_column', models.CharField(help_text='Target column for prediction', max_length=100)),
('training_data_period_days', models.PositiveIntegerField(default=90, help_text='Number of days of training data to use')),
('min_training_samples', models.PositiveIntegerField(default=100, help_text='Minimum number of samples required for training')),
('accuracy_score', models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('precision_score', models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('recall_score', models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('f1_score', models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('status', models.CharField(choices=[('TRAINING', 'Training'), ('ACTIVE', 'Active'), ('INACTIVE', 'Inactive'), ('RETRAINING', 'Retraining'), ('ERROR', 'Error')], default='TRAINING', max_length=20)),
('version', models.CharField(default='1.0', max_length=20)),
('model_file_path', models.CharField(blank=True, help_text='Path to the trained model file', max_length=500, null=True)),
('last_trained_at', models.DateTimeField(blank=True, null=True)),
('training_duration_seconds', models.PositiveIntegerField(blank=True, null=True)),
('training_samples_count', models.PositiveIntegerField(blank=True, null=True)),
('auto_retrain_enabled', models.BooleanField(default=True)),
('retrain_frequency_days', models.PositiveIntegerField(default=7)),
('performance_threshold', models.FloatField(default=0.8, help_text='Performance threshold below which model should be retrained', validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='PredictiveInsight',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('insight_type', models.CharField(choices=[('INCIDENT_PREDICTION', 'Incident Prediction'), ('SEVERITY_PREDICTION', 'Severity Prediction'), ('RESOLUTION_TIME_PREDICTION', 'Resolution Time Prediction'), ('COST_PREDICTION', 'Cost Prediction'), ('TREND_ANALYSIS', 'Trend Analysis'), ('PATTERN_DETECTION', 'Pattern Detection')], max_length=30)),
('title', models.CharField(max_length=200)),
('description', models.TextField()),
('confidence_level', models.CharField(choices=[('LOW', 'Low Confidence'), ('MEDIUM', 'Medium Confidence'), ('HIGH', 'High Confidence'), ('VERY_HIGH', 'Very High Confidence')], max_length=20)),
('confidence_score', models.FloatField(validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('predicted_value', models.JSONField(help_text='Predicted value or values')),
('prediction_horizon', models.PositiveIntegerField(help_text='Prediction horizon in hours')),
('prediction_date', models.DateTimeField(help_text='When the prediction is for')),
('input_features', models.JSONField(help_text='Input features used for the prediction')),
('supporting_evidence', models.JSONField(default=list, help_text='Supporting evidence for the prediction')),
('affected_services', models.JSONField(default=list, help_text='Services that may be affected')),
('recommendations', models.JSONField(default=list, help_text='AI-generated recommendations based on the insight')),
('risk_assessment', models.TextField(blank=True, help_text='Risk assessment based on the prediction', null=True)),
('is_acknowledged', models.BooleanField(default=False)),
('acknowledged_at', models.DateTimeField(blank=True, null=True)),
('is_validated', models.BooleanField(default=False)),
('actual_value', models.JSONField(blank=True, help_text='Actual value when prediction is validated', null=True)),
('validation_accuracy', models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('generated_at', models.DateTimeField(auto_now_add=True)),
('expires_at', models.DateTimeField(help_text='When this insight expires')),
('acknowledged_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='acknowledged_insights', to=settings.AUTH_USER_MODEL)),
('related_incidents', models.ManyToManyField(blank=True, related_name='predictive_insights', to='incident_intelligence.incident')),
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='insights', to='analytics_predictive_insights.predictivemodel')),
],
options={
'ordering': ['-generated_at'],
},
),
migrations.CreateModel(
name='AnomalyDetection',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('anomaly_type', models.CharField(choices=[('STATISTICAL', 'Statistical Anomaly'), ('TEMPORAL', 'Temporal Anomaly'), ('PATTERN', 'Pattern Anomaly'), ('THRESHOLD', 'Threshold Breach'), ('BEHAVIORAL', 'Behavioral Anomaly')], max_length=20)),
('severity', models.CharField(choices=[('LOW', 'Low'), ('MEDIUM', 'Medium'), ('HIGH', 'High'), ('CRITICAL', 'Critical')], max_length=20)),
('status', models.CharField(choices=[('DETECTED', 'Detected'), ('INVESTIGATING', 'Investigating'), ('CONFIRMED', 'Confirmed'), ('FALSE_POSITIVE', 'False Positive'), ('RESOLVED', 'Resolved')], default='DETECTED', max_length=20)),
('confidence_score', models.FloatField(validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('anomaly_score', models.FloatField(help_text='Raw anomaly score from the model')),
('threshold_used', models.FloatField(help_text='Threshold used for anomaly detection')),
('detected_at', models.DateTimeField(auto_now_add=True)),
('time_window_start', models.DateTimeField()),
('time_window_end', models.DateTimeField()),
('affected_services', models.JSONField(default=list, help_text='Services affected by this anomaly')),
('affected_metrics', models.JSONField(default=list, help_text='Metrics that showed anomalous behavior')),
('description', models.TextField(help_text='Description of the anomaly')),
('root_cause_analysis', models.TextField(blank=True, help_text='Root cause analysis of the anomaly', null=True)),
('impact_assessment', models.TextField(blank=True, help_text="Assessment of the anomaly's impact", null=True)),
('actions_taken', models.JSONField(default=list, help_text='Actions taken in response to the anomaly')),
('resolved_at', models.DateTimeField(blank=True, null=True)),
('metadata', models.JSONField(default=dict, help_text='Additional metadata for this anomaly')),
('related_incidents', models.ManyToManyField(blank=True, related_name='anomaly_detections', to='incident_intelligence.incident')),
('resolved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='resolved_anomalies', to=settings.AUTH_USER_MODEL)),
('model', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='anomaly_detections', to='analytics_predictive_insights.predictivemodel')),
],
options={
'ordering': ['-detected_at'],
},
),
migrations.CreateModel(
name='CostImpactAnalysis',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('cost_type', models.CharField(choices=[('DOWNTIME', 'Downtime Cost'), ('LOST_REVENUE', 'Lost Revenue'), ('PENALTY', 'Penalty Cost'), ('RESOURCE_COST', 'Resource Cost'), ('REPUTATION_COST', 'Reputation Cost'), ('COMPLIANCE_COST', 'Compliance Cost')], max_length=20)),
('cost_amount', models.DecimalField(decimal_places=2, help_text='Cost amount in USD', max_digits=15)),
('currency', models.CharField(default='USD', max_length=3)),
('calculation_method', models.CharField(help_text='Method used to calculate the cost', max_length=50)),
('calculation_details', models.JSONField(default=dict, help_text='Detailed breakdown of cost calculation')),
('downtime_hours', models.DecimalField(blank=True, decimal_places=2, help_text='Total downtime in hours', max_digits=10, null=True)),
('affected_users', models.PositiveIntegerField(blank=True, help_text='Number of users affected', null=True)),
('revenue_impact', models.DecimalField(blank=True, decimal_places=2, help_text='Revenue impact in USD', max_digits=15, null=True)),
('business_unit', models.CharField(blank=True, help_text='Business unit affected', max_length=100, null=True)),
('service_tier', models.CharField(blank=True, help_text='Service tier (e.g., Premium, Standard)', max_length=50, null=True)),
('is_validated', models.BooleanField(default=False)),
('validated_at', models.DateTimeField(blank=True, null=True)),
('validation_notes', models.TextField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('incident', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='cost_analyses', to='incident_intelligence.incident')),
('validated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='validated_cost_analyses', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
'indexes': [models.Index(fields=['incident', 'cost_type'], name='analytics_p_inciden_c66cda_idx'), models.Index(fields=['cost_amount'], name='analytics_p_cost_am_92cb70_idx'), models.Index(fields=['is_validated'], name='analytics_p_is_vali_bf5116_idx')],
},
),
migrations.CreateModel(
name='DashboardConfiguration',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=200)),
('description', models.TextField()),
('dashboard_type', models.CharField(choices=[('EXECUTIVE', 'Executive Dashboard'), ('OPERATIONAL', 'Operational Dashboard'), ('TECHNICAL', 'Technical Dashboard'), ('CUSTOM', 'Custom Dashboard')], max_length=20)),
('layout_config', models.JSONField(default=dict, help_text='Dashboard layout configuration')),
('widget_configs', models.JSONField(default=list, help_text='Configuration for dashboard widgets')),
('is_public', models.BooleanField(default=False)),
('allowed_roles', models.JSONField(default=list, help_text='List of roles that can access this dashboard')),
('auto_refresh_enabled', models.BooleanField(default=True)),
('refresh_interval_seconds', models.PositiveIntegerField(default=300)),
('is_active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('allowed_users', models.ManyToManyField(blank=True, related_name='accessible_dashboards', to=settings.AUTH_USER_MODEL)),
('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['name'],
'indexes': [models.Index(fields=['dashboard_type', 'is_active'], name='analytics_p_dashboa_a8155f_idx'), models.Index(fields=['is_public'], name='analytics_p_is_publ_c4c7bd_idx')],
},
),
migrations.CreateModel(
name='IncidentRecurrenceAnalysis',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('recurrence_type', models.CharField(choices=[('EXACT_DUPLICATE', 'Exact Duplicate'), ('SIMILAR_PATTERN', 'Similar Pattern'), ('SEASONAL', 'Seasonal Recurrence'), ('TREND', 'Trend-based Recurrence'), ('CASCADE', 'Cascade Effect')], max_length=20)),
('confidence_score', models.FloatField(validators=[django.core.validators.MinValueValidator(0.0), django.core.validators.MaxValueValidator(1.0)])),
('recurrence_rate', models.FloatField(help_text='Rate of recurrence (incidents per time period)')),
('common_keywords', models.JSONField(default=list, help_text='Common keywords across recurring incidents')),
('common_categories', models.JSONField(default=list, help_text='Common categories across recurring incidents')),
('time_pattern', models.JSONField(default=dict, help_text='Time-based pattern analysis')),
('total_affected_users', models.PositiveIntegerField(default=0)),
('total_downtime_hours', models.DecimalField(decimal_places=2, default=0, max_digits=10)),
('estimated_cost_impact', models.DecimalField(decimal_places=2, default=0, max_digits=15)),
('prevention_recommendations', models.JSONField(default=list, help_text='AI-generated recommendations to prevent recurrence')),
('automation_opportunities', models.JSONField(default=list, help_text='Potential automation opportunities identified')),
('is_resolved', models.BooleanField(default=False)),
('resolution_actions', models.JSONField(default=list, help_text='Actions taken to resolve the recurrence pattern')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('model_version', models.CharField(default='v1.0', max_length=50)),
('primary_incident', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='recurrence_analyses_as_primary', to='incident_intelligence.incident')),
('recurring_incidents', models.ManyToManyField(related_name='recurrence_analyses_as_recurring', to='incident_intelligence.incident')),
],
options={
'ordering': ['-confidence_score', '-created_at'],
'indexes': [models.Index(fields=['recurrence_type', 'confidence_score'], name='analytics_p_recurre_420fe9_idx'), models.Index(fields=['is_resolved'], name='analytics_p_is_reso_cdecdd_idx')],
},
),
migrations.AddIndex(
model_name='kpimetric',
index=models.Index(fields=['metric_type', 'is_active'], name='analytics_p_metric__8e1291_idx'),
),
migrations.AddIndex(
model_name='kpimetric',
index=models.Index(fields=['incident_categories'], name='analytics_p_inciden_fcc290_idx'),
),
migrations.AddIndex(
model_name='kpimetric',
index=models.Index(fields=['incident_severities'], name='analytics_p_inciden_601d71_idx'),
),
migrations.AddIndex(
model_name='kpimeasurement',
index=models.Index(fields=['metric', 'measurement_period_start'], name='analytics_p_metric__5c1184_idx'),
),
migrations.AddIndex(
model_name='kpimeasurement',
index=models.Index(fields=['calculated_at'], name='analytics_p_calcula_e8b072_idx'),
),
migrations.AddIndex(
model_name='predictivemodel',
index=models.Index(fields=['model_type', 'status'], name='analytics_p_model_t_b1e3f4_idx'),
),
migrations.AddIndex(
model_name='predictivemodel',
index=models.Index(fields=['algorithm_type'], name='analytics_p_algorit_1f51a1_idx'),
),
migrations.AddIndex(
model_name='predictivemodel',
index=models.Index(fields=['status'], name='analytics_p_status_ad4300_idx'),
),
migrations.AddIndex(
model_name='predictiveinsight',
index=models.Index(fields=['insight_type', 'confidence_score'], name='analytics_p_insight_ac65ec_idx'),
),
migrations.AddIndex(
model_name='predictiveinsight',
index=models.Index(fields=['prediction_date'], name='analytics_p_predict_d606fb_idx'),
),
migrations.AddIndex(
model_name='predictiveinsight',
index=models.Index(fields=['is_acknowledged'], name='analytics_p_is_ackn_16014e_idx'),
),
migrations.AddIndex(
model_name='anomalydetection',
index=models.Index(fields=['anomaly_type', 'severity'], name='analytics_p_anomaly_d51ee4_idx'),
),
migrations.AddIndex(
model_name='anomalydetection',
index=models.Index(fields=['status', 'detected_at'], name='analytics_p_status_c15b14_idx'),
),
migrations.AddIndex(
model_name='anomalydetection',
index=models.Index(fields=['confidence_score'], name='analytics_p_confide_c99920_idx'),
),
]