My scenario:
- User A is (fraudster).
- User B is not (fraudster). However, the system will not allow user B to do any action. Because B and A are using the same Phone Number(Shared attribute with Fraud User). (1 layer).
- User D is not (fraudster). But D is using the same Deviceid with B and B is sharing attribute with fraud User. Then block User D as well. In this case, there are 2 layers. D compare with B, B compares with A.
Recursive CTE (Error when I increased the data to 1000 rows)
Code:
with recursive cte as (
select ID, Email, MobileNo, DeviceId, IPAddress, id as tracking
from tableuser
where isfraudsterstatus = 1
union all
select u.id, u.email, u.mobileno, u.deviceid, u.ipaddress , concat_ws(',', cte.tracking, u.id)
from cte join
tableuser u
on u.email = cte.email or
u.mobileno = cte.mobileno or
u.deviceid = cte.deviceid or
u.ipaddress = cte.ipaddress
where find_in_set(u.id, cte.tracking) = 0
)
select *
from cte;
Error:
Using Pandas:(error when i increased the data from 1000rows to 500000rows)
Code:
import mysql.connector
from mysql.connector import Error
import pandas as pd
#DATABASE CONNECTION
##
try:
connection = mysql.connector.connect(host='localhost',
database='database',
user='root',
password='')
cursor = connection.cursor()
#Create Dataframe (temporary data)
#df = pd.read_sql("select * from MOCK_DATA",con=connection)
df = pd.read_sql("select * from tableuser",con=connection)
##
def expand_fraud(no_fraud, fraud, col_name):
t = pd.merge(no_fraud, fraud, on=col_name)
if len(t):
df.loc[df.ID.isin(t.ID_x), "IsFraudsterStatus"] = 1
return True
return False
while True:
added_fraud = False
fraud = df[df.IsFraudsterStatus == 1]
no_fraud = df[df.IsFraudsterStatus == 0]
added_fraud |= expand_fraud(no_fraud, fraud, "DeviceId")
added_fraud |= expand_fraud(no_fraud, fraud, "Email")
added_fraud |= expand_fraud(no_fraud, fraud, "MobileNo")
if not added_fraud:
break
print(df)
Id_list = df.values.tolist()
except Error as e:
print("Error reading data from MySQL table", e)
finally:
if (connection.is_connected()):
connection.close()
cursor.close()
print("MySQL connection is closed")
How to deal with this ? Is there any alternative way to do that ?