Spaces:
Running
Running
Muhammad Ridzki Nugraha commited on
Deploy Gapura AI update (exclude models; models pulled at runtime)
Browse files- api/main.py +29 -0
- data/risk_service.py +3 -3
api/main.py
CHANGED
|
@@ -1559,11 +1559,13 @@ async def risk_summary(
|
|
| 1559 |
"required_headers": [
|
| 1560 |
"Report",
|
| 1561 |
"Root_Caused",
|
|
|
|
| 1562 |
"Irregularity_Complain_Category",
|
| 1563 |
"Area",
|
| 1564 |
"Airlines",
|
| 1565 |
"Branch",
|
| 1566 |
"HUB",
|
|
|
|
| 1567 |
],
|
| 1568 |
"max_rows": max_rows_per_sheet,
|
| 1569 |
},
|
|
@@ -1572,11 +1574,13 @@ async def risk_summary(
|
|
| 1572 |
"required_headers": [
|
| 1573 |
"Report",
|
| 1574 |
"Root_Caused",
|
|
|
|
| 1575 |
"Irregularity_Complain_Category",
|
| 1576 |
"Area",
|
| 1577 |
"Airlines",
|
| 1578 |
"Branch",
|
| 1579 |
"HUB",
|
|
|
|
| 1580 |
],
|
| 1581 |
"max_rows": max_rows_per_sheet,
|
| 1582 |
},
|
|
@@ -1594,6 +1598,31 @@ async def risk_summary(
|
|
| 1594 |
spreadsheet_id, "CGO", f"A1:Z{max_rows_per_sheet}", bypass_cache=bypass_cache
|
| 1595 |
)
|
| 1596 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1597 |
for row in non_cargo:
|
| 1598 |
row["_source_sheet"] = "NON CARGO"
|
| 1599 |
for row in cargo:
|
|
|
|
| 1559 |
"required_headers": [
|
| 1560 |
"Report",
|
| 1561 |
"Root_Caused",
|
| 1562 |
+
"Action_Taken",
|
| 1563 |
"Irregularity_Complain_Category",
|
| 1564 |
"Area",
|
| 1565 |
"Airlines",
|
| 1566 |
"Branch",
|
| 1567 |
"HUB",
|
| 1568 |
+
"Status",
|
| 1569 |
],
|
| 1570 |
"max_rows": max_rows_per_sheet,
|
| 1571 |
},
|
|
|
|
| 1574 |
"required_headers": [
|
| 1575 |
"Report",
|
| 1576 |
"Root_Caused",
|
| 1577 |
+
"Action_Taken",
|
| 1578 |
"Irregularity_Complain_Category",
|
| 1579 |
"Area",
|
| 1580 |
"Airlines",
|
| 1581 |
"Branch",
|
| 1582 |
"HUB",
|
| 1583 |
+
"Status",
|
| 1584 |
],
|
| 1585 |
"max_rows": max_rows_per_sheet,
|
| 1586 |
},
|
|
|
|
| 1598 |
spreadsheet_id, "CGO", f"A1:Z{max_rows_per_sheet}", bypass_cache=bypass_cache
|
| 1599 |
)
|
| 1600 |
|
| 1601 |
+
if (len(non_cargo) + len(cargo)) == 0:
|
| 1602 |
+
if fast:
|
| 1603 |
+
data_map_retry = sheets_service.fetch_sheets_selected_columns(
|
| 1604 |
+
spreadsheet_id, reqs, bypass_cache=True
|
| 1605 |
+
)
|
| 1606 |
+
non_cargo = data_map_retry.get("NON CARGO", [])
|
| 1607 |
+
cargo = data_map_retry.get("CGO", [])
|
| 1608 |
+
if (len(non_cargo) + len(cargo)) == 0:
|
| 1609 |
+
sheet_ranges = [
|
| 1610 |
+
{"name": "NON CARGO", "range": f"A1:Z{max_rows_per_sheet}"},
|
| 1611 |
+
{"name": "CGO", "range": f"A1:Z{max_rows_per_sheet}"},
|
| 1612 |
+
]
|
| 1613 |
+
data_map_wide = sheets_service.fetch_sheets_batch_data(
|
| 1614 |
+
spreadsheet_id, sheet_ranges, bypass_cache=True
|
| 1615 |
+
)
|
| 1616 |
+
non_cargo = data_map_wide.get("NON CARGO", [])
|
| 1617 |
+
cargo = data_map_wide.get("CGO", [])
|
| 1618 |
+
else:
|
| 1619 |
+
non_cargo = sheets_service.fetch_sheet_data(
|
| 1620 |
+
spreadsheet_id, "NON CARGO", f"A1:Z{max_rows_per_sheet}", bypass_cache=True
|
| 1621 |
+
)
|
| 1622 |
+
cargo = sheets_service.fetch_sheet_data(
|
| 1623 |
+
spreadsheet_id, "CGO", f"A1:Z{max_rows_per_sheet}", bypass_cache=True
|
| 1624 |
+
)
|
| 1625 |
+
|
| 1626 |
for row in non_cargo:
|
| 1627 |
row["_source_sheet"] = "NON CARGO"
|
| 1628 |
for row in cargo:
|
data/risk_service.py
CHANGED
|
@@ -283,9 +283,9 @@ class RiskScoringService:
|
|
| 283 |
if self._cached_summary:
|
| 284 |
return self._cached_summary
|
| 285 |
|
| 286 |
-
airlines = self.risk_data.get("airlines", {})
|
| 287 |
-
branches = self.risk_data.get("branches", {})
|
| 288 |
-
hubs = self.risk_data.get("hubs", {})
|
| 289 |
|
| 290 |
def get_risk_counts(data):
|
| 291 |
counts = {"Critical": 0, "High": 0, "Medium": 0, "Low": 0}
|
|
|
|
| 283 |
if self._cached_summary:
|
| 284 |
return self._cached_summary
|
| 285 |
|
| 286 |
+
airlines = self.risk_data.get("airlines", {}) or {}
|
| 287 |
+
branches = self.risk_data.get("branches", {}) or {}
|
| 288 |
+
hubs = self.risk_data.get("hubs", {}) or {}
|
| 289 |
|
| 290 |
def get_risk_counts(data):
|
| 291 |
counts = {"Critical": 0, "High": 0, "Medium": 0, "Low": 0}
|