data generation code added
This commit is contained in:
+73
-1
@@ -15,7 +15,7 @@ from flask import (
|
|||||||
request,
|
request,
|
||||||
)
|
)
|
||||||
from flask_cors import CORS, cross_origin
|
from flask_cors import CORS, cross_origin
|
||||||
from datetime import timedelta, date
|
from datetime import timedelta, date, datetime
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import json
|
import json
|
||||||
import psycopg2.extras
|
import psycopg2.extras
|
||||||
@@ -24,6 +24,8 @@ import pandas as pd
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
#from datetime import datetime
|
||||||
|
|
||||||
# import socket
|
# import socket
|
||||||
#import SQLAlchemy
|
#import SQLAlchemy
|
||||||
#from werkzeug.utils import secure_filename
|
#from werkzeug.utils import secure_filename
|
||||||
@@ -691,7 +693,77 @@ def generate_simulation_transaction():
|
|||||||
def generate_simulation_credit():
|
def generate_simulation_credit():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@app.route('/transaction/generator')
|
||||||
|
def generate_transactions():
|
||||||
|
SQL_ACC = "SELECT id, accountid,counters FROM customer_account_list WHERE counters < 11 ORDER by counters, id ASC LIMIT 50"
|
||||||
|
with connection:
|
||||||
|
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||||
|
cursor.execute(SQL_ACC)
|
||||||
|
select_demoS = cursor.fetchall()
|
||||||
|
|
||||||
|
account_data = json.dumps( [dict(ix) for ix in select_demoS] )
|
||||||
|
accounts_result = json.loads( account_data)
|
||||||
|
# Iterate through the JSON array
|
||||||
|
for item in accounts_result:
|
||||||
|
accountid = item["accountid"].strip()
|
||||||
|
counters = item["counters"]
|
||||||
|
individual_transactions(accountid,counters)
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
|
def individual_transactions(accountid,counters):
|
||||||
|
SQL_UPDATE_COUNTERS = "UPDATE customer_account_list SET counters = counters + 1 WHERE trim(accountid) = '" + accountid + "' "
|
||||||
|
print(SQL_UPDATE_COUNTERS)
|
||||||
|
with connection:
|
||||||
|
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||||
|
cursor.execute(SQL_UPDATE_COUNTERS)
|
||||||
|
|
||||||
|
SQL_TRX_MODEL = "SELECT accountid, trx_start_date, trx_end_date, amount, d1, d2 , d3, description, d4 FROM trx_raw WHERE accountid='" + accountid + "'"
|
||||||
|
print(SQL_TRX_MODEL)
|
||||||
|
with connection:
|
||||||
|
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||||
|
cursor.execute(SQL_TRX_MODEL)
|
||||||
|
select_demoS = cursor.fetchall()
|
||||||
|
|
||||||
|
account_data = json.dumps( [dict(ix) for ix in select_demoS] )
|
||||||
|
strx_result = json.loads( account_data)
|
||||||
|
# Iterate through the JSON array
|
||||||
|
for item in strx_result:
|
||||||
|
accountid = item["accountid"]
|
||||||
|
trx_start_date = item["trx_start_date"].strip()
|
||||||
|
trx_end_date = item["trx_end_date"].strip()
|
||||||
|
|
||||||
|
date_string = "2025-03-28"
|
||||||
|
date_format = "%d-%m-%Y"
|
||||||
|
days_to_add = 365*6 + counters * 28 + random.randint(0, 5)
|
||||||
|
trx_start_date_cal = datetime.strptime(trx_start_date, date_format).date() + timedelta(days=days_to_add)
|
||||||
|
trx_end_date_cal = trx_start_date_cal
|
||||||
|
amount = item["amount"] * (1 + random.randint(0, 10)/100)
|
||||||
|
d1 = item["d1"].strip()
|
||||||
|
d2 = item["d2"].strip()
|
||||||
|
d3 = item["d3"].strip()
|
||||||
|
description = item["description"].strip()
|
||||||
|
d4 = item["d4"].strip()
|
||||||
|
|
||||||
|
new_data = (
|
||||||
|
accountid,
|
||||||
|
trx_start_date_cal,
|
||||||
|
trx_end_date_cal,
|
||||||
|
amount,
|
||||||
|
d1,
|
||||||
|
d2 ,
|
||||||
|
d3,
|
||||||
|
description,
|
||||||
|
d4
|
||||||
|
)
|
||||||
|
print(new_data)
|
||||||
|
SQL_INSERT = "INSERT INTO customer_account_transaction_hx (accountid, trx_start_date, trx_end_date, amount, d1, d2 , d3, description, d4) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
|
||||||
|
print(SQL_INSERT)
|
||||||
|
with connection:
|
||||||
|
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor:
|
||||||
|
cursor.execute(SQL_INSERT,new_data)
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=8000)
|
app.run(host='0.0.0.0', port=8000)
|
||||||
Reference in New Issue
Block a user