Last active
September 4, 2018 20:43
-
-
Save mwacc/b308cfbbcad8b8f2556e884916261085 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
import datetime | |
TNX_NUM = int(sys.argv[1]) | |
ACCOUNT_NUM = int(sys.argv[2]) | |
RATES_NUM = int(sys.argv[3]) | |
PAR_ID = int(sys.argv[4]) | |
def get_random(top_limit): | |
"return random from [1;top_limit]" | |
return random.randint(1,top_limit) | |
def generate_tnx(id): | |
""" uuid source_id recipient_id amount_source_currency amount_recipient_currency ex_rate_id fraud_risk was_allowed ts """ | |
uuid = "transaction-uuid-is-%d-%d" % (PAR_ID,id) | |
source_id = get_random(ACCOUNT_NUM) | |
recipient_id = get_random(ACCOUNT_NUM) | |
amount_source_currency = get_random(5000) | |
amount_recipient_currency = get_random(6000) | |
ex_rate_id = get_random(RATES_NUM) | |
fraud_risk_tmp = get_random(100) + 1 | |
fraud_risk = get_random(int(fraud_risk_tmp/2)) if fraud_risk_tmp < 100 else 100 | |
if fraud_risk == 100: | |
was_allowed = False | |
else: | |
was_allowed = True | |
ts = datetime.datetime.now().isoformat() | |
return "\t".join(map(str,(uuid, source_id, recipient_id, amount_source_currency, amount_recipient_currency, ex_rate_id, fraud_risk_tmp, fraud_risk, was_allowed, ts))) | |
def generate_account(id): | |
""" id name type external_id currency esatblished_at country county city postal_code comment last_updated_date """ | |
uuid = PAR_ID + '-' + id | |
name = " %d some random name -%d-" % (id, get_random(id)) | |
type = get_random(10) | |
external_id = "=> %d <=" % id | |
currency = get_random(100) | |
esatblished_at = datetime.datetime.now().isoformat() | |
country = " %d country %d" % (get_random(200), get_random(200)) | |
county = "%d region %d" % (get_random(200), get_random(200)) | |
city = "%d city %d " % (get_random(200), get_random(200)) | |
postal_code = "%d ZZ %d" % (get_random(99), get_random(99)) | |
comment = " la %d la %d da %d" % (get_random(999), get_random(999), get_random(999)) | |
last_updated_date = datetime.datetime.now().isoformat() | |
return "\t".join(map(str,(uuid,name,type,external_id, currency,esatblished_at, country, county, city, postal_code, comment, last_updated_date))) | |
def generate_rate(id): | |
""" id date country from to rate """ | |
uuid = PAR_ID + '-' + id | |
dt = datetime.datetime.now().isoformat() | |
country = " %d country %d" % (get_random(200), get_random(200)) | |
from_c = "cur name %d" % get_random(180) | |
to_c = "cur name %d" % get_random(180) | |
rate = get_random(180) * 0.97 | |
return "\t".join(map(str,(uuid,dt,country, from_c, to_c, rate))) | |
with open("tnx_%d.tsv" % PAR_ID, "a") as tnx: | |
for i in range(TNX_NUM): | |
tnx.write(generate_tnx(i+1)) | |
tnx.write("\n") | |
with open("acc_%d.tsv" % PAR_ID, "a") as acc: | |
for i in range(ACCOUNT_NUM): | |
acc.write(generate_account(i+1)) | |
acc.write("\n") | |
with open("rate_%d.tsv" % PAR_ID, "a") as rt: | |
for i in range(RATES_NUM): | |
rt.write(generate_rate(i+1)) | |
rt.write("\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for ((i=1;i<=100;i++)); | |
do | |
echo "start $i.." | |
time python generator.py 71304000 433500 22000 $i & | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment