Ejemplo n.º 1
0
def test_select_category():
    holder = "template"
    network = "Mastercard"
    issuer = "Citi"
    name = "Double Cash"
    sub_info = "0,0,0"
    categories = "else-2"
    balance = 0
    age = 0
    points_cash_back = "C"
    card1 = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                   categories, balance, age, points_cash_back)
    holder = "template"
    network = "AMEX"
    issuer = "AMEX"
    name = "Gold"
    sub_info = "60000,4000,6"
    categories = "dining-4,grocery-4,flight(AMEX)-3,else-1"
    balance = 0
    age = 0
    points_cash_back = "P"
    cpp = 2
    card2 = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                   categories, balance, age, points_cash_back,
                                   cpp)
    assert (card1.check_categories("dining") == 2)
    assert (card2.check_categories("dining") == 8)
    assert (card2.check_categories("gas") == 2)
    return True
Ejemplo n.º 2
0
def test_decider():
    holder = "template"
    network = "AMEX"
    issuer = "AMEX"
    name = "Gold"
    sub_info = "60000,4000,6"
    categories = "dining-4,grocery-4,flight(AMEX)-3,else-1"
    balance = 6000
    age = 10
    points_cash_back = "P"
    cpp = 2
    card = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                  categories, balance, age, points_cash_back,
                                  cpp)
    holder = "template"
    network = "Mastercard"
    issuer = "Citi"
    name = "Double Cash"
    sub_info = "0,0,0"
    categories = "else-2"
    balance = 0
    age = 0
    points_cash_back = "C"
    card1 = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                   categories, balance, age, points_cash_back)
    assert (card.get_sign_up_bonus().check_active() is False)
    wallet = list()
    wallet.append(card)
    wallet.append(card1)
    print("Type 1, then 1 or 2, then N for the first test.")
    result = decider(wallet)
    if result[0] != "tie":
        assert result[0] == "AMEX"
    print("Type 4, then N for the second test.")
    result = decider(wallet)
    assert (result[0] == "tie")
    holder = "template"
    network = "Mastercard"
    issuer = "Chase"
    name = "Freedom Flex"
    sub_info = "500,200,3"
    categories = "quarterly-5,travel(Chase)-5,dining-3,drugstores-3,else-1"
    balance = 0
    age = 0
    points_cash_back = "P"
    card2 = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                   categories, balance, age, points_cash_back,
                                   2)
    assert card2.get_sign_up_bonus().check_active()
    wallet.append(card2)
    result = decider(wallet)
    assert result[2] == 0
    assert result[1] == "Freedom Flex"
    return True
Ejemplo n.º 3
0
 def construct_template_wallet(self, database):
     """
     This takes an input file and parses through, creating a number of
     template cards
     :param database: is the opened credit card db file.
     :return: None
     """
     line = database.readline()
     line = line[:len(line) - 1]
     while line != "END":
         card_parts = list(line.split(":"))
         network = card_parts[0]
         issuer = card_parts[1]
         card_name = card_parts[2]
         cash_back_points = card_parts[3]
         if "," in cash_back_points:
             cpp = float(cash_back_points[2:])
             cash_back_points = cash_back_points[0]
         else:
             cpp = 1
         sub_info = card_parts[5]
         categories = card_parts[7]
         balance = 0
         age = 0
         card = credit_card.CreditCard("template", network, issuer,
                                       card_name, sub_info, categories,
                                       balance, age, cash_back_points, cpp)
         self.add_card(card)
         line = database.readline()
         line = line[:len(line) - 1]
Ejemplo n.º 4
0
 def add_new_customer(self):
     new_card = credit_card.CreditCard()
     self.db_cursor.execute(f'''INSERT INTO card
     VALUES({new_card.get_id()},
     {new_card.get_card_number()},
     {new_card.get_pin()},
     {new_card.get_balance()});''')
     self.db_connect.commit()
     return [new_card.get_card_number(), new_card.get_pin()]
Ejemplo n.º 5
0
 def __init__(self, image=None):
     """
     Constructor of the DocRecognition class.
     :param image: source image for document recognition.
     """
     self.__set_image(image)
     self._credit_card = credit_card.CreditCard()
     self.__recognition_result = None
     self.__recognition_report = None
Ejemplo n.º 6
0
    def get_credit_cards(self):
        db = database.connect()
        cursor = database.get_cursor(db)
        card_list = []

        cursor.execute("select credit_cards.id from credit_cards join persons \
                        on persons.id = credit_cards.person_id \
                        where persons.id = :input_id"                                                     , \
                        input_id = self.get_id())
        all_cards = cursor.fetchall()

        database.disconnect(db)

        if all_cards:
            for card_id in all_cards:
                card_list.append(credit_card.CreditCard(card_id[0]))

        return card_list
Ejemplo n.º 7
0
 def construct_user_wallet(self, user_data):
     """
     This parses through the user's saved credit card info and populates
     their wallet
     :param user_data: is the open user cards text file
     :return:
     """
     line = user_data.readline()
     line = line[:len(line) - 1]
     while line is not "":
         card_parts = list(line.split(":"))
         holder = card_parts[0]
         network = card_parts[1]
         issuer = card_parts[2]
         card_name = card_parts[3]
         cash_back_points = card_parts[4]
         if "," in cash_back_points:
             cpp = float(cash_back_points[2:])
             cash_back_points = cash_back_points[0]
         else:
             cpp = 1.0
         sub_info = card_parts[6]
         sub_list = list(sub_info.split(","))
         if sub_list[0] == "False":
             sub_str = sub_info
         else:
             sub_str = sub_list[1] + "," + sub_list[2] + "," + sub_list[4]
         categories = card_parts[8]
         balance = card_parts[10]
         age = card_parts[9]
         card = credit_card.CreditCard(holder, network, issuer, card_name,
                                       sub_str, categories, balance, age,
                                       cash_back_points, cpp)
         if sub_list[0] == "True":
             sub = card.get_sign_up_bonus()
             sub.set_progress(int(sub_list[3]))
         self.add_card(card)
         line = user_data.readline()
         line = line[:len(line) - 1]
Ejemplo n.º 8
0
def test_setup_and_changes():
    holder = "template"
    network = "Mastercard"
    issuer = "Citi"
    name = "Double Cash"
    sub_info = "0,0,0"
    categories = "else-2"
    balance = 0
    age = 0
    points_cash_back = "C"
    card = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                  categories, balance, age, points_cash_back)
    card.purchase(1000)
    card.pay_off_card(700)
    assert (card.check_balance() == 300)
    assert (card.get_cents_per_point() == 1)
    assert (card.check_points_or_cash() == "C")
    test = "template:Mastercard:Citi:Double Cash:C:SUB:False:Categories:" \
           "else-2:0:300"
    repstr = card.__repr__()
    assert (test == repstr)
    return True
Ejemplo n.º 9
0
def test_sign_up_bonus():
    holder = "template"
    network = "AMEX"
    issuer = "AMEX"
    name = "Gold"
    sub_info = "60000,4000,6"
    categories = "dining-4,grocery-4,flight(AMEX)-3,else-1"
    balance = 0
    age = 0
    points_cash_back = "P"
    cpp = 2
    card = credit_card.CreditCard(holder, network, issuer, name, sub_info,
                                  categories, balance, age, points_cash_back,
                                  cpp)
    sub = card.get_sign_up_bonus()
    assert (sub.check_active())
    assert (sub.get_progress() == 0)
    card.purchase(3000)
    assert (sub.get_progress() == 3000)
    card.purchase(1000)
    assert (sub.check_active() is False)
    card.purchase(5000)
    assert (sub.get_progress() == 4000)
    return True
Ejemplo n.º 10
0
def add_card(wallet, template_wallet):
    """
    This is adds a new card to the user wallet from the template_wallet, but
    it is populated with any user provided information, such as age of account
    and account balance.
    :param wallet: is the list of credit cards for this given user
    :param template_wallet: is list of all credit cards this program can handle
    :return: True or False depending on the success of the function.
    """
    name = input("What is the name on the card? ")
    issuer = input("Which bank is the issuer? ")
    selected = False
    new_card = None
    yes_no = ""
    for card in template_wallet.get_cards():
        if card.get_issuer() != issuer:
            continue
        while yes_no != "Y" or yes_no != "N":
            yes_no = input("Is it the " + card.get_card_name() +
                           "(Input Y or N)? ")
            if yes_no == "Y":
                selected = True
                new_card = card
                break
            elif yes_no == "N":
                break
            else:
                print("Error! Please enter in Y or N!")
        if selected:
            break
    if selected is False:
        return
    result = None
    while yes_no != "Y" or yes_no != "N":
        yes_no = input("Is the card new (Input Y or N)? ")
        sub = new_card.get_sign_up_bonus()
        network = new_card.get_network()
        issuer = new_card.get_issuer()
        card_name = new_card.get_card_name()
        cats = new_card.print_categories()
        p_or_c = new_card.check_points_or_cash()
        cpp = new_card.get_cents_per_point()
        sub_info = str(sub.get_reward()) + "," + str(sub.get_minimum_spend()) \
            + "," + str(sub.get_months())
        if yes_no == "Y":
            balance = 0
            age = 0
            result = credit_card.CreditCard(name, network, issuer, card_name,
                                            sub_info, cats, balance, age,
                                            p_or_c, cpp)
            break
        elif yes_no == "N":
            while True:
                try:
                    balance = float(input("Please enter the balance in USD: "))
                    age = int(
                        input("Please enter the age in months of the "
                              "card: "))
                    break
                except ValueError:
                    print("Please enter valid numbers!")

            result = credit_card.CreditCard(name, network, issuer, card_name,
                                            sub_info, cats, balance, age,
                                            p_or_c, cpp)
            break
        else:
            print("Error! Please enter in Y or N!")

    if selected:
        wallet.add_card(result)
    return selected
Ejemplo n.º 11
0
import nn_linreg_sklearn as NN_Franke_sklearn
from neural_network import NN
from nn_linreg_new import MLP

# -----------------------------------------------------------------------------
seed = 0
np.random.seed(seed)

eta_range = [0.1, 0.01, 0.001, 0.0001, 1e-5, 1e-6, 1e-7]
gamma_range = [0.1, 0.01, 0.001, 0.0001, 1e-5, 1e-6, 1e-7]
eta = 1e-4
gamma = 0.001
thresholds = np.linspace(0.1, 0.9, 100)
# -----------------------------------------------------------------------------

features, target = CD.CreditCard(Corr_matrix=False)
X, y = CD.DesignMatrix(features, target)
# Calculating the beta values
#betas = func.next_beta(X, y, eta, gamma)

# Checking how many 1s and 0s we have
print('----------- Data information --------------')
print('Actual number of defaulters:    ', np.sum(y == 1))
print('Actual number of not defaulters:', np.sum(y == 0))
print('-------------------------------------------')

# Splitting X and y in a train and test set
X_train, X_test, y_train, y_test = func.splitting(X,
                                                  y,
                                                  TrainingShare=0.75,
                                                  seed=seed)
Ejemplo n.º 12
0
def get_credit_card(card_id):
    return credit_card.CreditCard(card_id)
Ejemplo n.º 13
0
"""
run: pytest -W ignore::DeprecationWarning
"""

# Import project functions
import functions as func
import credit_card as CD

features, target = CD.CreditCard()
X, y = CD.DesignMatrix(features, target)

# Splitting X and y in a train and test set
X_train, X_test, y_train, y_test = func.splitting(X,
                                                  y,
                                                  TrainingShare=0.75,
                                                  seed=0)

eta = 0.01
gamma = 0.1  # learning rate?

# Calculating the beta values based og the training set
betas_train = func.steepest(X_train, y_train, gamma)
#betas_train = func.SGD_beta(X_train, y_train, eta, gamma)

# Calculating ytilde and the model of logistic regression
z = X_test @ betas_train  # choosing best beta here?
model = func.logistic_function(z)
model = func.IndicatorFunc(model)

acc_scikit, TPR_scikit, precision_scikit, f1_score_scikit, AUC_scikit, predict_proba_scikit = func.scikit(
    X_train, X_test, y_train, y_test, model)
Ejemplo n.º 14
0
def test_person_through_credit_card():
    card = credit_card.CreditCard(TEST_PERSON.get_credit_cards()[0].get_id())
    assert( isinstance(card, credit_card.CreditCard)), \
        "get credit cards failed in person"