def create_product(self, row):
     """ Helper function to save a product."""
     p = Product()
     p.plan_id = int(row[0])
     p.institution = row[1]
     p.loan_purpose = row[2]
     p.pmt_type = row[3]
     p.loan_type = row[4]
     p.loan_term = int(row[5])
     p.int_adj_term = self.c.nullable_int(row[6])
     p.adj_period = self.c.nullable_int(row[7])
     p.io = self.c.string_to_boolean(row[8])
     p.arm_index = self.c.nullable_string(row[9])
     p.int_adj_cap = self.c.nullable_int(row[10])
     p.annual_cap = self.c.nullable_int(row[11])
     p.loan_cap = self.c.nullable_int(row[12])
     p.arm_margin = self.c.nullable_decimal(row[13])
     p.ai_value = self.c.nullable_decimal(row[14])
     p.min_ltv = float(row[15])
     p.max_ltv = float(row[16])
     p.min_fico = int(row[17])
     p.max_fico = int(row[18])
     p.min_loan_amt = Decimal(row[19])
     p.max_loan_amt = Decimal(row[20])
     p.data_timestamp = datetime.strptime('20140101', '%Y%m%d')
     p.save()
     return p
Exemplo n.º 2
0
 def create_product(self, row):
     """ Helper function to save a product."""
     p = Product()
     p.plan_id = int(row[0])
     p.institution = row[1]
     p.loan_purpose = row[2]
     p.pmt_type = row[3]
     p.loan_type = row[4]
     p.loan_term = int(row[5])
     p.int_adj_term = self.c.nullable_int(row[6])
     p.adj_period = self.c.nullable_int(row[7])
     p.io = self.c.string_to_boolean(row[8])
     p.arm_index = self.c.nullable_string(row[9])
     p.int_adj_cap = self.c.nullable_int(row[10])
     p.annual_cap = self.c.nullable_int(row[11])
     p.loan_cap = self.c.nullable_int(row[12])
     p.arm_margin = self.c.nullable_decimal(row[13])
     p.ai_value = self.c.nullable_decimal(row[14])
     p.min_ltv = Decimal(row[15]).quantize(Decimal('.001'))
     p.max_ltv = Decimal(row[16]).quantize(Decimal('.001'))
     p.min_fico = int(row[17])
     p.max_fico = int(row[18])
     p.min_loan_amt = Decimal(row[19])
     p.max_loan_amt = Decimal(row[20])
     p.data_timestamp = datetime.strptime('20140101', '%Y%m%d')
     p.save()
     return p
Exemplo n.º 3
0
    def load_product_data(self, data_date, zfile):
        """ Load the daily product data."""
        filename = "%s_product.txt" % data_date
        data_date = timezone.make_aware(datetime.strptime(data_date, '%Y%m%d'),
                                        timezone.get_current_timezone())

        product_reader = reader(StringIO.StringIO(zfile.read(filename)),
                                delimiter='\t')

        #Skip the first row as it contains column documentation
        iterproducts = iter(product_reader)
        next(iterproducts)

        products = []
        total_products = 0
        for row in iterproducts:
            total_products += 1
            p = Product()
            p.plan_id = int(row[0])
            p.institution = row[1]
            p.loan_purpose = row[2]
            p.pmt_type = row[3]
            p.loan_type = row[4]
            p.loan_term = int(row[5])
            p.int_adj_term = self.nullable_int(row[6])
            p.adj_period = self.nullable_int(row[7])
            p.io = self.string_to_boolean(row[8])
            p.arm_index = self.nullable_string(row[9])
            p.int_adj_cap = self.nullable_int(row[10])

            p.annual_cap = self.nullable_int(row[11])
            p.loan_cap = self.nullable_int(row[12])
            p.arm_margin = self.nullable_decimal(row[13])
            p.ai_value = self.nullable_decimal(row[14])

            p.min_ltv = Decimal(row[15]).quantize(Decimal('.001'))
            p.max_ltv = Decimal(row[16]).quantize(Decimal('.001'))
            p.min_fico = int(row[17])
            p.max_fico = int(row[18])
            p.min_loan_amt = Decimal(row[19])
            p.max_loan_amt = Decimal(row[20])

            p.data_timestamp = data_date
            products.append(p)

            if len(products) > 1000:
                Product.objects.bulk_create(products)
                products[:] = []

        Product.objects.bulk_create(products)
        if not total_products or Product.objects.count() != total_products:
            raise OaHException("Couldn't load product data from %s" %
                               zfile.filename)
    def load_product_data(self, data_date, zfile):
        """ Load the daily product data."""
        filename = "%s_product.txt" % data_date
        data_date = timezone.make_aware(
            datetime.strptime(data_date, '%Y%m%d'),
            timezone.get_current_timezone())

        product_reader = reader(StringIO.StringIO(zfile.read(filename)), delimiter='\t')

        #Skip the first row as it contains column documentation
        iterproducts = iter(product_reader)
        next(iterproducts)

        products = []
        total_products = 0
        for row in iterproducts:
            total_products += 1
            p = Product()
            p.plan_id = int(row[0])
            p.institution = row[1]
            p.loan_purpose = row[2]
            p.pmt_type = row[3]
            p.loan_type = row[4]
            p.loan_term = int(row[5])
            p.int_adj_term = self.nullable_int(row[6])
            p.adj_period = self.nullable_int(row[7])
            p.io = self.string_to_boolean(row[8])
            p.arm_index = self.nullable_string(row[9])
            p.int_adj_cap = self.nullable_int(row[10])

            p.annual_cap = self.nullable_int(row[11])
            p.loan_cap = self.nullable_int(row[12])
            p.arm_margin = self.nullable_decimal(row[13])
            p.ai_value = self.nullable_decimal(row[14])

            p.min_ltv = float(row[15])
            p.max_ltv = float(row[16])
            p.min_fico = int(row[17])
            p.max_fico = int(row[18])
            p.min_loan_amt = Decimal(row[19])
            p.max_loan_amt = Decimal(row[20])

            p.data_timestamp = data_date
            products.append(p)

            if len(products) > 1000:
                Product.objects.bulk_create(products)
                products[:] = []

        Product.objects.bulk_create(products)
        if not total_products or Product.objects.count() != total_products:
            raise OaHException("Couldn't load product data from %s" % zfile.filename)
    def load_product_data(self, data_date, product_filename):
        """ Load the daily product data."""

        with open(product_filename) as product_csv:
            product_reader = reader(product_csv, delimiter="\t")

            # Skip the first row as it contains column documentation
            iterproducts = iter(product_reader)
            next(iterproducts)

            products = []
            for row in iterproducts:

                p = Product()
                p.plan_id = int(row[0])
                p.institution = row[1]
                p.loan_purpose = row[2]
                p.pmt_type = row[3]
                p.loan_type = row[4]
                p.loan_term = int(row[5])
                p.int_adj_term = self.nullable_int(row[6])
                p.adj_period = self.nullable_int(row[7])
                p.io = self.string_to_boolean(row[8])
                p.arm_index = self.nullable_string(row[9])
                p.int_adj_cap = self.nullable_int(row[10])

                p.annual_cap = self.nullable_int(row[11])
                p.loan_cap = self.nullable_int(row[12])
                p.arm_margin = self.nullable_decimal(row[13])
                p.ai_value = self.nullable_decimal(row[14])

                p.min_ltv = float(row[15])
                p.max_ltv = float(row[16])
                p.min_fico = int(row[17])
                p.max_fico = int(row[18])
                p.min_loan_amt = Decimal(row[19])
                p.max_loan_amt = Decimal(row[20])

                p.data_timestamp = data_date
                products.append(p)

                if len(products) > 1000:
                    Product.objects.bulk_create(products)
                    products[:] = []

            Product.objects.bulk_create(products)