Пример #1
0
def simulate_startup():
    conn = mysql.connect()
    cursor = conn.cursor()
    t = Transaction(cursor, conn)
    ec = EmployeeCard(cursor, conn)

    for dept, e_list in client.department_employees.items():

        dept_bal = client.retrieve_balance(
            dept).gpa.available_balance * (random.randint(1, 19) / 100)

        employees = random.sample(e_list, 5)

        for e in employees:
            transfer = client.transfer(
                dept_bal, dept, e, dest_token_is_user=True)
            t.insert(dept, e, Transaction.current_time(
                transfer.created_time), dept_bal)
            card = client.client_sdk.cards.list_for_user(e)[0].token

            mid_identifer = random.choice(MIDS)
            employee_transaction = simulate(
                card, amount=dept_bal * (random.randint(1, 19) / 100), mid=mid_identifer)

            t.insert(card, mid_identifer, Transaction.current_time(
                employee_transaction.created_time), employee_transaction.amount, is_card=True)
            ec.insert(e, card)

    conn.close()
Пример #2
0
def load_values():
    conn = mysql.connect()
    cursor = conn.cursor()
    print('\n\nINITIALIZING DB\n\n')

    query1 = """
        INSERT INTO department_lookup (token, department)
        VALUES (%s,%s)"""
    for i, dept in enumerate(client.departments):
        cursor.execute(query1, (dept.token, client.DEPARTMENT_LIST[i]))
        print(dept.token + client.DEPARTMENT_LIST[i] + ' has been inserted.',
              file=stderr)

    emp = Employee(cursor, conn, immediate_commit=False)
    for e in client.employees:
        emp.insert(e.token, e.first_name, e.last_name, e.parent_token)
        print(e.token + 'h has been inserted.', file=stderr)

    desc = "My primary role is managing different banking sectors involved in asset management, sanctioning loans, " \
           "mortgages, investments, and account operations. I oversee the efficient day to day processes as well as " \
           "preparing forecasts and reports to drive the overall success of our clients and the department. "

    man = Manager(cursor, conn, immediate_commit=False)
    for dept in client.DEPARTMENT_LIST:
        man.insert(client.MANAGERS[dept]['email'],
                   client.MANAGERS[dept]['pass'],
                   client.MANAGERS[dept]['first_name'],
                   client.MANAGERS[dept]['last_name'], 'Sr. Division Manager',
                   desc, client.MANAGERS[dept]['manager_dept_FK'],
                   client.MANAGERS[dept]['gender'])

    trans = Transaction(cursor, conn, immediate_commit=False)
    for t in client.transactions:
        if t.recipient_user_token is None:
            trans.insert(
                t.sender_business_token,
                t.recipient_business_token,
                Transaction.current_time(t.created_time),
                t.amount,
            )
        else:
            trans.insert(
                t.sender_business_token,
                t.recipient_user_token,
                Transaction.current_time(t.created_time),
                t.amount,
            )
    conn.commit()
    conn.close()
    simulate_startup()
    session['db_init'] = True

    create_background_scheduler()
Пример #3
0
def dept_to_emp(plan_id):
    conn = mysql.connect()
    cursor = conn.cursor()
    query = 'SELECT * FROM plan WHERE id = %s'
    cursor.execute(query, plan_id)
    records = cursor.fetchall()
    funding_amount = records[0][2]
    source_fund_FK = records[0][7]

    query = 'SELECT token FROM department_lookup WHERE id = %s'
    cursor.execute(query, source_fund_FK)
    source_token = cursor.fetchall()[0][0]

    query = 'SELECT * FROM employee_plan WHERE ep_plan_FK = %s'
    cursor.execute(query, plan_id)
    records = cursor.fetchall()

    t = Transaction(cursor, conn)

    for row in records:
        query = 'SELECT token FROM employee WHERE id = %s'
        cursor.execute(query, row[0])
        dest_token = cursor.fetchall()[0][0]
        transfer = client.transfer(funding_amount, source_token, dest_token, dest_token_is_user=True)
        t.insert(source_token, dest_token, Transaction.current_time(transfer.created_time), funding_amount)

    conn.commit()
    conn.close()

    complete_employee_plan(plan_id)
    simulate_employee_plan(plan_id)
Пример #4
0
def dept_to_dept(plan_id):

    """
    for department to department transfers,
    gathers info from plan in db and
    enters it into Marqet API

     param: plan_id - the id of the plan in db to submit
     returns: 1 on success 0 on faliure
    """

    conn = mysql.connect()
    cursor = conn.cursor()
    query = 'SELECT * FROM plan WHERE id = %s'
    cursor.execute(query, plan_id)
    records = cursor.fetchall()
    funding_amount = records[0][2]
    source_fund_FK = records[0][7]
    dest_fund_FK = records[0][8]

    query = 'SELECT token FROM department_lookup WHERE id = %s'
    cursor.execute(query, source_fund_FK)
    source_token = cursor.fetchall()[0][0]

    query = 'SELECT token FROM department_lookup WHERE id = %s'
    cursor.execute(query, dest_fund_FK)
    dest_token = cursor.fetchall()[0][0]

    transfer = client.transfer(funding_amount, source_token, dest_token, dest_token_is_user=False)

    t = Transaction(cursor, conn=conn)
    t.insert(source_token, dest_token, Transaction.current_time(transfer.created_time), funding_amount)

    query = 'UPDATE plan SET complete = 1 WHERE id = %s'
    cursor.execute(query, plan_id)

    conn.commit()
    conn.close()
Пример #5
0
def simulate_employee_plan(plan_id):
    conn = mysql.connect()
    cursor = conn.cursor()
    query = '''
    SELECT e.token, ep_card_token FROM employee_plan ep 
    JOIN employee e ON ep.ep_employee_FK = e.id 
    WHERE ep_plan_FK = %s'''
    t = Transaction(cursor, conn=conn)

    # THIS WILL RETURN ALL EMPLOYEES AND THEIR ASSOCIATED CARDS WITH AN ACCORDING PLAN
    cursor.execute(query, (plan_id))
    for employee_card_pair in cursor.fetchall():
        mid_identifer = random.choice(MIDS)
        employee_token = employee_card_pair[0]
        card_token = employee_card_pair[1]
        # NEED TO FIND BALANCE OF THE USER AND TIMES THAT BY SOME PERCENTAGE
        e_balance = client.retrieve_balance(
            employee_token).gpa.available_balance * .1
        employee_transaction = simulate(
            card_token, amount=e_balance, mid=mid_identifer)
        t.insert(card_token, mid_identifer, Transaction.current_time(
            employee_transaction.created_time), employee_transaction.amount, is_card=True)

    conn.close()