Spaces:
Sleeping
Sleeping
Update metrics/montoring_analytics.py
Browse files
metrics/montoring_analytics.py
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# analytics/monitoring_analysis.py
|
| 2 |
+
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
from metrics.vintage_metrics import (
|
| 6 |
+
calculate_vintage_dpd,
|
| 7 |
+
calculate_vintage_ncl
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def generate_monitoring_table(df):
|
| 12 |
+
|
| 13 |
+
dpd_30_mob3 = calculate_vintage_dpd(
|
| 14 |
+
df=df,
|
| 15 |
+
mob=3,
|
| 16 |
+
dpd_threshold=30,
|
| 17 |
+
metric_type="count"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
dpd_30_mob6 = calculate_vintage_dpd(
|
| 21 |
+
df=df,
|
| 22 |
+
mob=6,
|
| 23 |
+
dpd_threshold=30,
|
| 24 |
+
metric_type="count"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
dpd_60_mob6 = calculate_vintage_dpd(
|
| 28 |
+
df=df,
|
| 29 |
+
mob=6,
|
| 30 |
+
dpd_threshold=60,
|
| 31 |
+
metric_type="count"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
ncl_y1 = calculate_vintage_ncl(
|
| 35 |
+
df=df,
|
| 36 |
+
mob=12
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
final_table = (
|
| 40 |
+
dpd_30_mob3[
|
| 41 |
+
["reporting_month", "dpd_rate"]
|
| 42 |
+
]
|
| 43 |
+
.rename(
|
| 44 |
+
columns={
|
| 45 |
+
"dpd_rate": "30+@3"
|
| 46 |
+
}
|
| 47 |
+
)
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
final_table = final_table.merge(
|
| 51 |
+
dpd_30_mob6[
|
| 52 |
+
["reporting_month", "dpd_rate"]
|
| 53 |
+
].rename(
|
| 54 |
+
columns={
|
| 55 |
+
"dpd_rate": "30+@6"
|
| 56 |
+
}
|
| 57 |
+
),
|
| 58 |
+
on="reporting_month",
|
| 59 |
+
how="outer"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
final_table = final_table.merge(
|
| 63 |
+
dpd_60_mob6[
|
| 64 |
+
["reporting_month", "dpd_rate"]
|
| 65 |
+
].rename(
|
| 66 |
+
columns={
|
| 67 |
+
"dpd_rate": "60+@6"
|
| 68 |
+
}
|
| 69 |
+
),
|
| 70 |
+
on="reporting_month",
|
| 71 |
+
how="outer"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
final_table = final_table.merge(
|
| 75 |
+
ncl_y1[
|
| 76 |
+
["reporting_month", "ncl_rate"]
|
| 77 |
+
].rename(
|
| 78 |
+
columns={
|
| 79 |
+
"ncl_rate": "Yr1_NCL"
|
| 80 |
+
}
|
| 81 |
+
),
|
| 82 |
+
on="reporting_month",
|
| 83 |
+
how="outer"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
return final_table
|