From 139decf1d1a5d7a52bccb8aef59020813a924689 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sun, 16 Mar 2025 17:49:03 -0400 Subject: [PATCH] Fix Data --- SQL/salaryloan.sql | 49 +++++++++++++++++++++++++++++++++++++++++++++- app/app.py | 36 +++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/SQL/salaryloan.sql b/SQL/salaryloan.sql index e890ffb..5eb8932 100644 --- a/SQL/salaryloan.sql +++ b/SQL/salaryloan.sql @@ -124,4 +124,51 @@ ALTER TABLE ONLY loans {"cid": "1", "description": "Product Loan 01" , "active" : 0 }, {"cid": "2", "description": "Product Loan 02" , "active" : 0 }, -{"cid": "3", "description": "First Advance" , "active" : 1 }, \ No newline at end of file +{"cid": "3", "description": "First Advance" , "active" : 1 }, + + +CREATE TABLE trx_raw ( + id SERIAL, + AccountID VARCHAR(15) NOT NULL, + trx_start_date timestamp, + trx_end_date timestamp, + amount float DEFAULT 0.0, + D1 VARCHAR(3), + D2 VARCHAR(3), + D3 VARCHAR(3), + Description VARCHAR(75), + D4 VARCHAR(12) +); +ALTER TABLE ONLY trx_raw + ADD CONSTRAINT trx_raw_id_key UNIQUE (id); + +CREATE TABLE trx_raw ( + AccountID VARCHAR(15) NOT NULL, + trx_start_date VARCHAR(15), + trx_end_date VARCHAR(15), + amount float DEFAULT 0.0, + D1 VARCHAR(3), + D2 VARCHAR(3), + D3 VARCHAR(3), + Description VARCHAR(75), + D4 VARCHAR(12) +); + +CREATE TABLE accounts ( + id SERIAL, + AccountID VARCHAR(15) UNIQUE NOT NULL +); + +ALTER TABLE ONLY accounts + ADD CONSTRAINT accounts_id_key UNIQUE (id); + + + +1738039011 |15-03-2018|15-03-2018| 3000|T|CI|D|ATM WD @ 000000000001447 ACCESS NNEWI NG |1738039 +1738039011 |16-03-2018|16-03-2018| 2000|T|CI|D|ATM WD @ 000000000011446 Nnewi Nnewi NG |1738039 +1738039011 |19-03-2018|19-03-2018| 1065|T|CI|D|ATM WD @ NNEWI 05 NNEWI NNEWI ANNG |1738039 +1738039011 |20-03-2018|20-03-2018| 1065|T|CI|D|ATM WD @ 000000000001447 ACCESS NNEWI NG |1738039 +1778212012 |22-03-2018|22-03-2018| 8000|T|CI|D|240447189 ATM WD @ 10503184/ENG LA SATELITE |1778212 +1778212012 |19-03-2018|19-03-2018| 260000|T|CI|D|Online : kola |1778212 +1778212012 |19-03-2018|19-03-2018| 52.5|T|BI|D|TRANSACTION CHARGE-Online : kola |1778212 +1778212012 |16-03-2018|16-03-2018| 270000|T|CI|C|TRF B/O CHIBUZO BEATRICE UGOCHUKWU \ No newline at end of file diff --git a/app/app.py b/app/app.py index d12611b..b580299 100644 --- a/app/app.py +++ b/app/app.py @@ -144,7 +144,7 @@ def salary_demousers(): dList = [] - SELECT_DEMO_ENTRY = f"SELECT id,uid, bvn AS CustomerID, mobile AS AccountID, name,offers,salary_account,current_loans,mobile,bvn, email, pin, added::text, balance, updated::text AS updated FROM demo_bank_accounts ORDER BY id ASC" + SELECT_DEMO_ENTRY = f"SELECT id,uid, bvn AS CustomerID, mobile AS AccountID, name,offers,salary_account,current_loans,mobile,bvn, email, pin, added::text, balance, updated::text AS updated FROM demo_bank_accounts ORDER BY id DESC LIMIT 1500" # print(SELECT_DEMO_ENTRY) with connection: with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: @@ -639,6 +639,9 @@ def repay_loans(): @app.route('/simulation/generator') def generate_activities(): + + # insert_random_users() + generate_simulation_salary() generate_simulation_transaction() @@ -647,6 +650,37 @@ def generate_activities(): return [] +def insert_random_users(): + SQL_ACC = "SELECT accountid AS account_no FROM trx_raw GROUP BY accountid" + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(SQL_ACC) + select_demoS = cursor.fetchall() + + loan_data = json.dumps( [dict(ix) for ix in select_demoS] ) + accounts_result = json.loads( loan_data) + SQL_INSERT = "INSERT INTO demo_bank_accounts (name, salary_account, mobile, bvn, email, pin) VALUES(%s,%s,%s,%s,%s,%s)" + # Iterate through the JSON array + for item in accounts_result: + accountNo = item["account_no"] + new_data = ( + names.get_full_name() , + random.randint(0, 1), + '811-'+str( random.randint(100, 999) )+'-'+str( random.randint(1000, 9999) ) , + accountNo, + 'demo+'+ names.get_first_name() +'@chiefsoft.net', + random.randint(1100, 9999) + ) + + print(new_data) + with connection: + try: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(SQL_INSERT, new_data) + except Exception as e: + print(0) + + def generate_simulation_salary(): pass