Services API¶
Backup - admin.services.backup¶
admin.services.backup.create_backup ¶
create_backup(label: str = 'auto') -> str
Create a WAL-consistent snapshot of the SQLite DB.
Uses sqlite3's online backup API instead of shutil.copy2 so that any data still sitting in the -wal file is included. Do NOT swap this back to a plain file copy while journal_mode=WAL is active.
Source code in admin/services/backup.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
admin.services.backup.list_backups ¶
list_backups() -> list
Return backup filenames (newest first).
Source code in admin/services/backup.py
57 58 59 60 61 62 63 64 | |
admin.services.backup.restore_backup ¶
restore_backup(backup_filename: str) -> str
Atomically restore a backup into the live DB.
- Verifies the backup file's integrity before touching anything.
- Uses sqlite3's backup API (WAL-aware) to overwrite the live DB.
- Removes stale -wal / -shm sidecar files.
- Refuses to run if the backup path escapes BACKUP_DIR.
Returns the absolute path of the restored backup on success. Raises RuntimeError on any failure (caller should catch and st.error).
Source code in admin/services/backup.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Audit - admin.services.audit¶
admin.services.audit.init_audit ¶
init_audit() -> None
Source code in admin/services/audit.py
9 10 11 12 | |
admin.services.audit.log_audit ¶
log_audit(action: str, entity: str, entity_id, details: str = '') -> None
Source code in admin/services/audit.py
15 16 17 18 19 20 21 22 23 24 25 26 | |
Anomaly detection - radar.services.anomaly¶
radar.services.anomaly.detect_anomalies ¶
detect_anomalies(cdrs_df: DataFrame, cells_df: DataFrame, sig_findings: dict) -> list[dict]
Return a list of anomaly dicts (type, entity, value, z_score, ...).
Detects
- Hourly traffic outliers
- City traffic outliers
- Weak cells outliers
- System-wide encryption failure spikes
- CLIR abuse spikes
- VoLTE fallback routing anomalies
Source code in radar/services/anomaly.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Period comparison - radar.services.period¶
radar.services.period.split_periods ¶
split_periods(cdrs_f: DataFrame, split_ratio: float = 0.5)
Split a time-sorted CDR DataFrame into (previous, current).
Source code in radar/services/period.py
15 16 17 18 19 20 21 | |
radar.services.period.period_stats ¶
period_stats(df) -> dict
Return a dict of per-period totals. Empty for empty input.
Source code in radar/services/period.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
radar.services.period.delta_pct ¶
delta_pct(curr: float, prev: float)
Percent change from prev to curr. None when undefined.
Source code in radar/services/period.py
49 50 51 52 53 | |
PDF reports - radar.services.pdf¶
radar.services.pdf.build_pdf ¶
build_pdf(title: str, sections: list[dict]) -> bytes | None
Build a PDF report and return its bytes (or None if reportlab absent).
Each section is a dict with optional keys
heading : str text : str table : pandas.DataFrame
Source code in radar/services/pdf.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |