generated from dhairya/scenario_template
System save at 07/11/2024 15:35 by user_client2024
This commit is contained in:
parent
0d638798e8
commit
79bc7cb401
@ -7,44 +7,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "77134554-e1dc-4e5b-aaa2-bb432789aa01",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
"seq = SQLQueryInterface(schema=\"transactionschema\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9a13f2ec-d02f-4151-9d9a-17edd4f29063",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"seq.execute_raw(\"show tables\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "32c443d5-c51f-425c-be6f-bcd8c9908ef4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"query = \"\"\"\n",
|
||||
" select final.CUSTOMER_NUMBER_main as Focal_id,\n",
|
||||
" final.Credit_transaction_amount,\n",
|
||||
" final.Total_no_of_credit_transactions,\n",
|
||||
" final.Debit_transaction_amount,\n",
|
||||
" final.Total_no_of_debit_transactions,\n",
|
||||
" final.Wash_Ratio,\n",
|
||||
" final.SEGMENT,\n",
|
||||
" final.RISK,\n",
|
||||
" final.SAR_FLAG\n",
|
||||
@ -61,12 +31,7 @@
|
||||
" case\n",
|
||||
" when subquery.Total_no_of_debit_transactions is NULL then 0\n",
|
||||
" else Total_no_of_debit_transactions\n",
|
||||
" end as Total_no_of_debit_transactions,\n",
|
||||
" case\n",
|
||||
" when subquery.Debit_transaction_amount = 0\n",
|
||||
" or subquery.Debit_transaction_amount is NULL then 0\n",
|
||||
" else subquery.Credit_transaction_amount / subquery.Debit_transaction_amount\n",
|
||||
" end as Wash_Ratio\n",
|
||||
" end as Total_no_of_debit_transactions\n",
|
||||
" from \n",
|
||||
" (\n",
|
||||
" (\n",
|
||||
@ -76,7 +41,7 @@
|
||||
" from \n",
|
||||
" (\n",
|
||||
" select * \n",
|
||||
" from {trans_data} as trans_table left join {acc_data} as acc_table\n",
|
||||
" from {trans_data} trans_table left join {acc_data} acc_table\n",
|
||||
" on trans_table.benef_account_number = acc_table.account_number\n",
|
||||
" )\n",
|
||||
" where account_number not in ('None')\n",
|
||||
@ -89,7 +54,7 @@
|
||||
" from \n",
|
||||
" (\n",
|
||||
" select * \n",
|
||||
" from {trans_data} as trans_table left join {acc_data} as acc_table\n",
|
||||
" from {trans_data} trans_table left join {acc_data} acc_table\n",
|
||||
" on trans_table.orig_account_number = acc_table.account_number\n",
|
||||
" )\n",
|
||||
" where account_number not in ('None')\n",
|
||||
@ -126,34 +91,57 @@
|
||||
" ) subquery\n",
|
||||
" ) cust_alert on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main\n",
|
||||
" ) final\n",
|
||||
"\"\"\""
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
" \n",
|
||||
"class Scenario:\n",
|
||||
" seq = SQLQueryInterface(schema=\"transactionschema\")\n",
|
||||
" \n",
|
||||
" def logic(self, **kwargs):\n",
|
||||
" row_list = self.seq.execute_raw(query.format(trans_data=\"transaction10m\",\n",
|
||||
" cust_data=\"customer_data_v1\",\n",
|
||||
" acc_data=\"account_data_v1\",\n",
|
||||
" alert_data=\"alert_data_v1\")\n",
|
||||
" )\n",
|
||||
" cols = [\"Focal_id\", \"Credit_transaction_amount\", \"Total_no_of_credit_transactions\",\n",
|
||||
" \"Debit_transaction_amount\", \"Total_no_of_debit_transactions\",\n",
|
||||
" \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
|
||||
" df = pd.DataFrame(row_list, columns = cols)\n",
|
||||
" return df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "77134554-e1dc-4e5b-aaa2-bb432789aa01",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9a13f2ec-d02f-4151-9d9a-17edd4f29063",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "32c443d5-c51f-425c-be6f-bcd8c9908ef4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c34dc466-7bb5-471e-b0c5-0bfcd81b761c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
"\n",
|
||||
"class Scenario:\n",
|
||||
" seq = SQLQueryInterface(schema=\"transactionschema\")\n",
|
||||
"\n",
|
||||
" def logic(self, **kwargs):\n",
|
||||
" row_list = self.seq.execute_raw(query.format(trans_data=\"transaction10m\",\n",
|
||||
" cust_data=\"customer_data_v1\",\n",
|
||||
" acc_data=\"account_data_v1\",\n",
|
||||
" alert_data=\"alert_data_v1\")\n",
|
||||
" )\n",
|
||||
" cols = [\"Focal_id\", \"Credit_transaction_amount\",\n",
|
||||
" \"Total_no_of_credit_transactions\",\n",
|
||||
" \"Debit_transaction_amount\", \"Total_no_of_debit_transactions\",\n",
|
||||
" \"Wash_Ratio\", \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
|
||||
" df = pd.DataFrame(row_list, columns = cols)\n",
|
||||
" return df"
|
||||
]
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
||||
108
main.ipynb
108
main.ipynb
@ -7,44 +7,14 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "77134554-e1dc-4e5b-aaa2-bb432789aa01",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
"seq = SQLQueryInterface(schema=\"transactionschema\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9a13f2ec-d02f-4151-9d9a-17edd4f29063",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"seq.execute_raw(\"show tables\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "32c443d5-c51f-425c-be6f-bcd8c9908ef4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"query = \"\"\"\n",
|
||||
" select final.CUSTOMER_NUMBER_main as Focal_id,\n",
|
||||
" final.Credit_transaction_amount,\n",
|
||||
" final.Total_no_of_credit_transactions,\n",
|
||||
" final.Debit_transaction_amount,\n",
|
||||
" final.Total_no_of_debit_transactions,\n",
|
||||
" final.Wash_Ratio,\n",
|
||||
" final.SEGMENT,\n",
|
||||
" final.RISK,\n",
|
||||
" final.SAR_FLAG\n",
|
||||
@ -61,12 +31,7 @@
|
||||
" case\n",
|
||||
" when subquery.Total_no_of_debit_transactions is NULL then 0\n",
|
||||
" else Total_no_of_debit_transactions\n",
|
||||
" end as Total_no_of_debit_transactions,\n",
|
||||
" case\n",
|
||||
" when subquery.Debit_transaction_amount = 0\n",
|
||||
" or subquery.Debit_transaction_amount is NULL then 0\n",
|
||||
" else subquery.Credit_transaction_amount / subquery.Debit_transaction_amount\n",
|
||||
" end as Wash_Ratio\n",
|
||||
" end as Total_no_of_debit_transactions\n",
|
||||
" from \n",
|
||||
" (\n",
|
||||
" (\n",
|
||||
@ -76,7 +41,7 @@
|
||||
" from \n",
|
||||
" (\n",
|
||||
" select * \n",
|
||||
" from {trans_data} as trans_table left join {acc_data} as acc_table\n",
|
||||
" from {trans_data} trans_table left join {acc_data} acc_table\n",
|
||||
" on trans_table.benef_account_number = acc_table.account_number\n",
|
||||
" )\n",
|
||||
" where account_number not in ('None')\n",
|
||||
@ -89,7 +54,7 @@
|
||||
" from \n",
|
||||
" (\n",
|
||||
" select * \n",
|
||||
" from {trans_data} as trans_table left join {acc_data} as acc_table\n",
|
||||
" from {trans_data} trans_table left join {acc_data} acc_table\n",
|
||||
" on trans_table.orig_account_number = acc_table.account_number\n",
|
||||
" )\n",
|
||||
" where account_number not in ('None')\n",
|
||||
@ -126,34 +91,57 @@
|
||||
" ) subquery\n",
|
||||
" ) cust_alert on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main\n",
|
||||
" ) final\n",
|
||||
"\"\"\""
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
" \n",
|
||||
"class Scenario:\n",
|
||||
" seq = SQLQueryInterface(schema=\"transactionschema\")\n",
|
||||
" \n",
|
||||
" def logic(self, **kwargs):\n",
|
||||
" row_list = self.seq.execute_raw(query.format(trans_data=\"transaction10m\",\n",
|
||||
" cust_data=\"customer_data_v1\",\n",
|
||||
" acc_data=\"account_data_v1\",\n",
|
||||
" alert_data=\"alert_data_v1\")\n",
|
||||
" )\n",
|
||||
" cols = [\"Focal_id\", \"Credit_transaction_amount\", \"Total_no_of_credit_transactions\",\n",
|
||||
" \"Debit_transaction_amount\", \"Total_no_of_debit_transactions\",\n",
|
||||
" \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
|
||||
" df = pd.DataFrame(row_list, columns = cols)\n",
|
||||
" return df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "77134554-e1dc-4e5b-aaa2-bb432789aa01",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9a13f2ec-d02f-4151-9d9a-17edd4f29063",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "32c443d5-c51f-425c-be6f-bcd8c9908ef4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c34dc466-7bb5-471e-b0c5-0bfcd81b761c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from tms_data_interface import SQLQueryInterface\n",
|
||||
"\n",
|
||||
"class Scenario:\n",
|
||||
" seq = SQLQueryInterface(schema=\"transactionschema\")\n",
|
||||
"\n",
|
||||
" def logic(self, **kwargs):\n",
|
||||
" row_list = self.seq.execute_raw(query.format(trans_data=\"transaction10m\",\n",
|
||||
" cust_data=\"customer_data_v1\",\n",
|
||||
" acc_data=\"account_data_v1\",\n",
|
||||
" alert_data=\"alert_data_v1\")\n",
|
||||
" )\n",
|
||||
" cols = [\"Focal_id\", \"Credit_transaction_amount\",\n",
|
||||
" \"Total_no_of_credit_transactions\",\n",
|
||||
" \"Debit_transaction_amount\", \"Total_no_of_debit_transactions\",\n",
|
||||
" \"Wash_Ratio\", \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
|
||||
" df = pd.DataFrame(row_list, columns = cols)\n",
|
||||
" return df"
|
||||
]
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
||||
66
main.py
66
main.py
@ -6,30 +6,12 @@
|
||||
|
||||
import pandas as pd
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
from tms_data_interface import SQLQueryInterface
|
||||
seq = SQLQueryInterface(schema="transactionschema")
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
seq.execute_raw("show tables")
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
query = """
|
||||
select final.CUSTOMER_NUMBER_main as Focal_id,
|
||||
final.Credit_transaction_amount,
|
||||
final.Total_no_of_credit_transactions,
|
||||
final.Debit_transaction_amount,
|
||||
final.Total_no_of_debit_transactions,
|
||||
final.Wash_Ratio,
|
||||
final.SEGMENT,
|
||||
final.RISK,
|
||||
final.SAR_FLAG
|
||||
@ -46,12 +28,7 @@ query = """
|
||||
case
|
||||
when subquery.Total_no_of_debit_transactions is NULL then 0
|
||||
else Total_no_of_debit_transactions
|
||||
end as Total_no_of_debit_transactions,
|
||||
case
|
||||
when subquery.Debit_transaction_amount = 0
|
||||
or subquery.Debit_transaction_amount is NULL then 0
|
||||
else subquery.Credit_transaction_amount / subquery.Debit_transaction_amount
|
||||
end as Wash_Ratio
|
||||
end as Total_no_of_debit_transactions
|
||||
from
|
||||
(
|
||||
(
|
||||
@ -61,7 +38,7 @@ query = """
|
||||
from
|
||||
(
|
||||
select *
|
||||
from {trans_data} as trans_table left join {acc_data} as acc_table
|
||||
from {trans_data} trans_table left join {acc_data} acc_table
|
||||
on trans_table.benef_account_number = acc_table.account_number
|
||||
)
|
||||
where account_number not in ('None')
|
||||
@ -74,7 +51,7 @@ query = """
|
||||
from
|
||||
(
|
||||
select *
|
||||
from {trans_data} as trans_table left join {acc_data} as acc_table
|
||||
from {trans_data} trans_table left join {acc_data} acc_table
|
||||
on trans_table.orig_account_number = acc_table.account_number
|
||||
)
|
||||
where account_number not in ('None')
|
||||
@ -113,25 +90,20 @@ query = """
|
||||
) final
|
||||
"""
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
from tms_data_interface import SQLQueryInterface
|
||||
|
||||
|
||||
class Scenario:
|
||||
seq = SQLQueryInterface(schema="transactionschema")
|
||||
|
||||
|
||||
def logic(self, **kwargs):
|
||||
row_list = self.seq.execute_raw(query.format(trans_data="transaction10m",
|
||||
cust_data="customer_data_v1",
|
||||
acc_data="account_data_v1",
|
||||
alert_data="alert_data_v1")
|
||||
)
|
||||
cols = ["Focal_id", "Credit_transaction_amount",
|
||||
"Total_no_of_credit_transactions",
|
||||
cols = ["Focal_id", "Credit_transaction_amount", "Total_no_of_credit_transactions",
|
||||
"Debit_transaction_amount", "Total_no_of_debit_transactions",
|
||||
"Wash_Ratio", "Segment", "Risk", "SAR_FLAG"]
|
||||
"Segment", "Risk", "SAR_FLAG"]
|
||||
df = pd.DataFrame(row_list, columns = cols)
|
||||
return df
|
||||
|
||||
@ -141,3 +113,27 @@ class Scenario:
|
||||
|
||||
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# In[ ]:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user