|
21 | 21 | } |
22 | 22 |
|
23 | 23 | def load_csv(csv_path: Path) -> pd.DataFrame: |
24 | | - """Loads the risk matrix from CSV.""" |
| 24 | + """ |
| 25 | + Loads the risk matrix from CSV. |
| 26 | +
|
| 27 | + - En local : lit 02-Matrices/risk_matrix.csv |
| 28 | + - En CI (GitHub Actions) : si le fichier est absent (gitignore), génère un dataset de démo |
| 29 | + """ |
| 30 | + # Cas 1 : fichier absent (runner CI ou repo public sans CSV réel) |
| 31 | + if not csv_path.exists(): |
| 32 | + print(f"Warning: {csv_path} not found. Using demo dataset (CI mode).") |
| 33 | + |
| 34 | + demo_data = [ |
| 35 | + { |
| 36 | + "ID": "R001", |
| 37 | + "Asset": "Demo infusion pump", |
| 38 | + "Threat": "Ransomware", |
| 39 | + "Vulnerability": "Unpatched OS", |
| 40 | + "Probability": 4, |
| 41 | + "Impact": 5, |
| 42 | + "Risk": 20, |
| 43 | + "Decision": "Reduce", |
| 44 | + "Recommendation": "Patch management + network segmentation" |
| 45 | + }, |
| 46 | + { |
| 47 | + "ID": "R002", |
| 48 | + "Asset": "Demo patient monitor", |
| 49 | + "Threat": "Unauthorized access", |
| 50 | + "Vulnerability": "Weak credentials", |
| 51 | + "Probability": 3, |
| 52 | + "Impact": 4, |
| 53 | + "Risk": 12, |
| 54 | + "Decision": "Reduce", |
| 55 | + "Recommendation": "Strong auth + MFA where possible" |
| 56 | + }, |
| 57 | + ] |
| 58 | + |
| 59 | + df = pd.DataFrame(demo_data) |
| 60 | + return df |
| 61 | + |
| 62 | + # Cas 2 : fichier présent (ton environnement local) |
25 | 63 | try: |
| 64 | + print(f"Loading CSV from: {csv_path}") |
26 | 65 | df = pd.read_csv(csv_path) |
27 | | - # Required English Column Names |
28 | | - required_cols = ['ID', 'Asset', 'Threat', 'Vulnerability', |
29 | | - 'Probability', 'Impact', 'Risk', 'Decision', 'Recommendation'] |
| 66 | + |
| 67 | + required_cols = [ |
| 68 | + 'ID', 'Asset', 'Threat', 'Vulnerability', |
| 69 | + 'Probability', 'Impact', 'Risk', 'Decision', 'Recommendation' |
| 70 | + ] |
30 | 71 |
|
31 | 72 | if not all(col in df.columns for col in required_cols): |
32 | 73 | print(f"Error: Missing columns in CSV. Expected: {required_cols}") |
33 | 74 | sys.exit(1) |
34 | 75 |
|
35 | | - # Ensure Risk is calculated correctly (since it might be missing or pre-calculated) |
| 76 | + # Recalcule le risque pour être sûr |
36 | 77 | df['Risk'] = df['Probability'] * df['Impact'] |
37 | 78 |
|
38 | 79 | return df |
@@ -259,7 +300,7 @@ def main(): |
259 | 300 |
|
260 | 301 | print("Creating Excel file...") # Pas besoin de f-string ici |
261 | 302 | print("Success: Excel file generated successfully!") # Pas besoin de f-string ici |
262 | | - print(f" - {len(df)} risks processed") # F-string nécessaire ici pour afficher len(df) |
| 303 | + print(" - " + str(len(df)) + " risks processed") # F-string nécessaire ici pour afficher len(df) |
263 | 304 | print(" - 3 tabs created: Matrix + Heatmap + Dashboard") # Pas besoin de f-string ici |
264 | 305 |
|
265 | 306 | if __name__ == '__main__': |
|
0 commit comments