diff --git a/.ipynb_checkpoints/main-checkpoint.ipynb b/.ipynb_checkpoints/main-checkpoint.ipynb
new file mode 100644
index 0000000..7daeb9c
--- /dev/null
+++ b/.ipynb_checkpoints/main-checkpoint.ipynb
@@ -0,0 +1,368 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "e706cfb0-2234-4c4c-95d8-d1968f656aa0",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "2edb58c0-33a2-4436-8128-05645af9990d",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "from tms_data_interface import SQLQueryInterface\n",
+ "seq = SQLQueryInterface(schema=\"transactionschema\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "0ccc875a-6ff5-4741-9495-93c6871b1027",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[['account_data_v1'],\n",
+ " ['account_data_v2'],\n",
+ " ['alert_data_v1'],\n",
+ " ['alert_data_v2'],\n",
+ " ['customer_data_v1'],\n",
+ " ['customer_data_v2'],\n",
+ " ['transaction10m'],\n",
+ " ['transaction60m']]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "seq.execute_raw(\"show tables\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "01502887-b11f-46d2-9a52-e493df19d049",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "query = \"\"\"\n",
+ " select final.CUSTOMER_NUMBER_main as Focal_id,\n",
+ " CAST(final.Total_hrc_transaction_amount AS DECIMAL(18, 2)) AS Total_hrc_transaction_amount,\n",
+ " final.Unique_country_codes,\n",
+ " final.SEGMENT,\n",
+ " final.RISK,\n",
+ " final.SAR_FLAG\n",
+ " from \n",
+ " (\n",
+ " (\n",
+ " select subquery.CUSTOMER_NUMBER_1 as CUSTOMER_NUMBER_main,\n",
+ " subquery.Total_hrc_transaction_amount,\n",
+ " subquery.Unique_country_codes\n",
+ " from \n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_1, \n",
+ " sum(transaction_amount) as Total_hrc_transaction_amount, \n",
+ " array_join(array_agg(DISTINCT benef_cntry_code), ',') AS unique_country_codes\n",
+ " from \n",
+ " (\n",
+ " select * \n",
+ " from {trans_data} trans_table \n",
+ " left join {acc_data} acc_table\n",
+ " on trans_table.benef_account_number = acc_table.account_number\n",
+ " ) trans\n",
+ " where account_number not in ('None')\n",
+ " group by customer_number\n",
+ " ) subquery\n",
+ " ) main \n",
+ " left join \n",
+ " (\n",
+ " select cd.CUSTOMER_NUMBER_3 as CUSTOMER_NUMBER_cust,\n",
+ " cd.SEGMENT,\n",
+ " cd.RISK,\n",
+ " case\n",
+ " when ad.SAR_FLAG is NULL then 'N'\n",
+ " else ad.SAR_FLAG\n",
+ " end as SAR_FLAG \n",
+ " from\n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_3, \n",
+ " business_segment as SEGMENT,\n",
+ " case\n",
+ " when RISK_CLASSIFICATION = 1 then 'Low Risk'\n",
+ " when RISK_CLASSIFICATION = 2 then 'Medium Risk'\n",
+ " when RISK_CLASSIFICATION = 3 then 'High Risk'\n",
+ " else 'Unknown Risk'\n",
+ " end AS RISK\n",
+ " from {cust_data}\n",
+ " ) cd \n",
+ " left join\n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_4, \n",
+ " sar_flag as SAR_FLAG\n",
+ " from {alert_data}\n",
+ " ) ad \n",
+ " on cd.CUSTOMER_NUMBER_3 = ad.CUSTOMER_NUMBER_4\n",
+ " ) as cust_alert\n",
+ " on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main\n",
+ " ) as final\n",
+ "\"\"\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "c28e15b5-4b09-46a6-849e-7ffd5cefee7f",
+ "metadata": {
+ "tags": []
+ },
+ "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\", \"Total_hrc_transaction_amount\", \"Unique_country_codes\",\n",
+ " \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
+ " df = pd.DataFrame(row_list, columns = cols)\n",
+ " return df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "dc94e713-7267-499a-897f-672209d563c0",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Focal_id | \n",
+ " Total_hrc_transaction_amount | \n",
+ " Unique_country_codes | \n",
+ " Segment | \n",
+ " Risk | \n",
+ " SAR_FLAG | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " PN739187 | \n",
+ " 5288386944.18 | \n",
+ " None | \n",
+ " SME | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " PN573373 | \n",
+ " 3984448017.83 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " Low Risk | \n",
+ " Y | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " PN791113 | \n",
+ " 2203599126.03 | \n",
+ " None | \n",
+ " SME | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " PN572058 | \n",
+ " 4424937298.78 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " PN375785 | \n",
+ " 496146009.32 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 10009 | \n",
+ " PN759572 | \n",
+ " 42099733.92 | \n",
+ " IN | \n",
+ " Ultra High NetWorth | \n",
+ " Medium Risk | \n",
+ " Y | \n",
+ "
\n",
+ " \n",
+ " | 10010 | \n",
+ " PN147338 | \n",
+ " 39374120.63 | \n",
+ " IN | \n",
+ " Private Banking | \n",
+ " Medium Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10011 | \n",
+ " PN632196 | \n",
+ " 37892236.97 | \n",
+ " LK | \n",
+ " Others | \n",
+ " Medium Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10012 | \n",
+ " PN100406 | \n",
+ " 35620658.59 | \n",
+ " IN | \n",
+ " Others | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10013 | \n",
+ " PN452769 | \n",
+ " 35792822.47 | \n",
+ " AM | \n",
+ " Others | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
10014 rows × 6 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Focal_id Total_hrc_transaction_amount Unique_country_codes \\\n",
+ "0 PN739187 5288386944.18 None \n",
+ "1 PN573373 3984448017.83 None \n",
+ "2 PN791113 2203599126.03 None \n",
+ "3 PN572058 4424937298.78 None \n",
+ "4 PN375785 496146009.32 None \n",
+ "... ... ... ... \n",
+ "10009 PN759572 42099733.92 IN \n",
+ "10010 PN147338 39374120.63 IN \n",
+ "10011 PN632196 37892236.97 LK \n",
+ "10012 PN100406 35620658.59 IN \n",
+ "10013 PN452769 35792822.47 AM \n",
+ "\n",
+ " Segment Risk SAR_FLAG \n",
+ "0 SME Low Risk N \n",
+ "1 Whole Sale Banking Low Risk Y \n",
+ "2 SME High Risk N \n",
+ "3 Whole Sale Banking Low Risk N \n",
+ "4 Whole Sale Banking High Risk N \n",
+ "... ... ... ... \n",
+ "10009 Ultra High NetWorth Medium Risk Y \n",
+ "10010 Private Banking Medium Risk N \n",
+ "10011 Others Medium Risk N \n",
+ "10012 Others High Risk N \n",
+ "10013 Others Low Risk N \n",
+ "\n",
+ "[10014 rows x 6 columns]"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# sen = Scenario()\n",
+ "# sen.logic()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7e585bbc-7baf-41a5-8f05-ca25c08e7ca8",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/main.ipynb b/main.ipynb
index 3277afb..7daeb9c 100644
--- a/main.ipynb
+++ b/main.ipynb
@@ -1,33 +1,368 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "e706cfb0-2234-4c4c-95d8-d1968f656aa0",
- "metadata": {},
- "outputs": [],
- "source": "from tms_data_interface import SQLQueryInterface\n\nclass Scenario:\n\tseq = SQLQueryInterface()\n\n\tdef logic(self, **kwargs):\n\t\t# Write your code here\n"
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3 (ipykernel)",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.8.13"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 5
-}
\ No newline at end of file
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "e706cfb0-2234-4c4c-95d8-d1968f656aa0",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "import pandas as pd"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "2edb58c0-33a2-4436-8128-05645af9990d",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "from tms_data_interface import SQLQueryInterface\n",
+ "seq = SQLQueryInterface(schema=\"transactionschema\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "0ccc875a-6ff5-4741-9495-93c6871b1027",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[['account_data_v1'],\n",
+ " ['account_data_v2'],\n",
+ " ['alert_data_v1'],\n",
+ " ['alert_data_v2'],\n",
+ " ['customer_data_v1'],\n",
+ " ['customer_data_v2'],\n",
+ " ['transaction10m'],\n",
+ " ['transaction60m']]"
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "seq.execute_raw(\"show tables\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "01502887-b11f-46d2-9a52-e493df19d049",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "query = \"\"\"\n",
+ " select final.CUSTOMER_NUMBER_main as Focal_id,\n",
+ " CAST(final.Total_hrc_transaction_amount AS DECIMAL(18, 2)) AS Total_hrc_transaction_amount,\n",
+ " final.Unique_country_codes,\n",
+ " final.SEGMENT,\n",
+ " final.RISK,\n",
+ " final.SAR_FLAG\n",
+ " from \n",
+ " (\n",
+ " (\n",
+ " select subquery.CUSTOMER_NUMBER_1 as CUSTOMER_NUMBER_main,\n",
+ " subquery.Total_hrc_transaction_amount,\n",
+ " subquery.Unique_country_codes\n",
+ " from \n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_1, \n",
+ " sum(transaction_amount) as Total_hrc_transaction_amount, \n",
+ " array_join(array_agg(DISTINCT benef_cntry_code), ',') AS unique_country_codes\n",
+ " from \n",
+ " (\n",
+ " select * \n",
+ " from {trans_data} trans_table \n",
+ " left join {acc_data} acc_table\n",
+ " on trans_table.benef_account_number = acc_table.account_number\n",
+ " ) trans\n",
+ " where account_number not in ('None')\n",
+ " group by customer_number\n",
+ " ) subquery\n",
+ " ) main \n",
+ " left join \n",
+ " (\n",
+ " select cd.CUSTOMER_NUMBER_3 as CUSTOMER_NUMBER_cust,\n",
+ " cd.SEGMENT,\n",
+ " cd.RISK,\n",
+ " case\n",
+ " when ad.SAR_FLAG is NULL then 'N'\n",
+ " else ad.SAR_FLAG\n",
+ " end as SAR_FLAG \n",
+ " from\n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_3, \n",
+ " business_segment as SEGMENT,\n",
+ " case\n",
+ " when RISK_CLASSIFICATION = 1 then 'Low Risk'\n",
+ " when RISK_CLASSIFICATION = 2 then 'Medium Risk'\n",
+ " when RISK_CLASSIFICATION = 3 then 'High Risk'\n",
+ " else 'Unknown Risk'\n",
+ " end AS RISK\n",
+ " from {cust_data}\n",
+ " ) cd \n",
+ " left join\n",
+ " (\n",
+ " select customer_number as CUSTOMER_NUMBER_4, \n",
+ " sar_flag as SAR_FLAG\n",
+ " from {alert_data}\n",
+ " ) ad \n",
+ " on cd.CUSTOMER_NUMBER_3 = ad.CUSTOMER_NUMBER_4\n",
+ " ) as cust_alert\n",
+ " on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main\n",
+ " ) as final\n",
+ "\"\"\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "c28e15b5-4b09-46a6-849e-7ffd5cefee7f",
+ "metadata": {
+ "tags": []
+ },
+ "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\", \"Total_hrc_transaction_amount\", \"Unique_country_codes\",\n",
+ " \"Segment\", \"Risk\", \"SAR_FLAG\"]\n",
+ " df = pd.DataFrame(row_list, columns = cols)\n",
+ " return df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "dc94e713-7267-499a-897f-672209d563c0",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " Focal_id | \n",
+ " Total_hrc_transaction_amount | \n",
+ " Unique_country_codes | \n",
+ " Segment | \n",
+ " Risk | \n",
+ " SAR_FLAG | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " PN739187 | \n",
+ " 5288386944.18 | \n",
+ " None | \n",
+ " SME | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " PN573373 | \n",
+ " 3984448017.83 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " Low Risk | \n",
+ " Y | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " PN791113 | \n",
+ " 2203599126.03 | \n",
+ " None | \n",
+ " SME | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " PN572058 | \n",
+ " 4424937298.78 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " PN375785 | \n",
+ " 496146009.32 | \n",
+ " None | \n",
+ " Whole Sale Banking | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 10009 | \n",
+ " PN759572 | \n",
+ " 42099733.92 | \n",
+ " IN | \n",
+ " Ultra High NetWorth | \n",
+ " Medium Risk | \n",
+ " Y | \n",
+ "
\n",
+ " \n",
+ " | 10010 | \n",
+ " PN147338 | \n",
+ " 39374120.63 | \n",
+ " IN | \n",
+ " Private Banking | \n",
+ " Medium Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10011 | \n",
+ " PN632196 | \n",
+ " 37892236.97 | \n",
+ " LK | \n",
+ " Others | \n",
+ " Medium Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10012 | \n",
+ " PN100406 | \n",
+ " 35620658.59 | \n",
+ " IN | \n",
+ " Others | \n",
+ " High Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ " | 10013 | \n",
+ " PN452769 | \n",
+ " 35792822.47 | \n",
+ " AM | \n",
+ " Others | \n",
+ " Low Risk | \n",
+ " N | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
10014 rows × 6 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " Focal_id Total_hrc_transaction_amount Unique_country_codes \\\n",
+ "0 PN739187 5288386944.18 None \n",
+ "1 PN573373 3984448017.83 None \n",
+ "2 PN791113 2203599126.03 None \n",
+ "3 PN572058 4424937298.78 None \n",
+ "4 PN375785 496146009.32 None \n",
+ "... ... ... ... \n",
+ "10009 PN759572 42099733.92 IN \n",
+ "10010 PN147338 39374120.63 IN \n",
+ "10011 PN632196 37892236.97 LK \n",
+ "10012 PN100406 35620658.59 IN \n",
+ "10013 PN452769 35792822.47 AM \n",
+ "\n",
+ " Segment Risk SAR_FLAG \n",
+ "0 SME Low Risk N \n",
+ "1 Whole Sale Banking Low Risk Y \n",
+ "2 SME High Risk N \n",
+ "3 Whole Sale Banking Low Risk N \n",
+ "4 Whole Sale Banking High Risk N \n",
+ "... ... ... ... \n",
+ "10009 Ultra High NetWorth Medium Risk Y \n",
+ "10010 Private Banking Medium Risk N \n",
+ "10011 Others Medium Risk N \n",
+ "10012 Others High Risk N \n",
+ "10013 Others Low Risk N \n",
+ "\n",
+ "[10014 rows x 6 columns]"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# sen = Scenario()\n",
+ "# sen.logic()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7e585bbc-7baf-41a5-8f05-ca25c08e7ca8",
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.8"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..c4f54d8
--- /dev/null
+++ b/main.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+# In[1]:
+
+
+import pandas as pd
+
+
+# In[3]:
+
+
+from tms_data_interface import SQLQueryInterface
+seq = SQLQueryInterface(schema="transactionschema")
+
+
+# In[4]:
+
+
+seq.execute_raw("show tables")
+
+
+# In[5]:
+
+
+query = """
+ select final.CUSTOMER_NUMBER_main as Focal_id,
+ CAST(final.Total_hrc_transaction_amount AS DECIMAL(18, 2)) AS Total_hrc_transaction_amount,
+ final.Unique_country_codes,
+ final.SEGMENT,
+ final.RISK,
+ final.SAR_FLAG
+ from
+ (
+ (
+ select subquery.CUSTOMER_NUMBER_1 as CUSTOMER_NUMBER_main,
+ subquery.Total_hrc_transaction_amount,
+ subquery.Unique_country_codes
+ from
+ (
+ select customer_number as CUSTOMER_NUMBER_1,
+ sum(transaction_amount) as Total_hrc_transaction_amount,
+ array_join(array_agg(DISTINCT benef_cntry_code), ',') AS unique_country_codes
+ from
+ (
+ select *
+ from {trans_data} trans_table
+ left join {acc_data} acc_table
+ on trans_table.benef_account_number = acc_table.account_number
+ ) trans
+ where account_number not in ('None')
+ group by customer_number
+ ) subquery
+ ) main
+ left join
+ (
+ select cd.CUSTOMER_NUMBER_3 as CUSTOMER_NUMBER_cust,
+ cd.SEGMENT,
+ cd.RISK,
+ case
+ when ad.SAR_FLAG is NULL then 'N'
+ else ad.SAR_FLAG
+ end as SAR_FLAG
+ from
+ (
+ select customer_number as CUSTOMER_NUMBER_3,
+ business_segment as SEGMENT,
+ case
+ when RISK_CLASSIFICATION = 1 then 'Low Risk'
+ when RISK_CLASSIFICATION = 2 then 'Medium Risk'
+ when RISK_CLASSIFICATION = 3 then 'High Risk'
+ else 'Unknown Risk'
+ end AS RISK
+ from {cust_data}
+ ) cd
+ left join
+ (
+ select customer_number as CUSTOMER_NUMBER_4,
+ sar_flag as SAR_FLAG
+ from {alert_data}
+ ) ad
+ on cd.CUSTOMER_NUMBER_3 = ad.CUSTOMER_NUMBER_4
+ ) as cust_alert
+ on cust_alert.CUSTOMER_NUMBER_cust = main.CUSTOMER_NUMBER_main
+ ) as final
+"""
+
+
+# In[6]:
+
+
+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", "Total_hrc_transaction_amount", "Unique_country_codes",
+ "Segment", "Risk", "SAR_FLAG"]
+ df = pd.DataFrame(row_list, columns = cols)
+ return df
+
+
+# In[7]:
+
+
+# sen = Scenario()
+# sen.logic()
+
+
+# In[ ]:
+
+
+
+