Ejemplo n.º 1
0
    def parse_file(self, file) -> Iterable[Purchase]:
        try:
            # note this is easier with Pandas, but Alpine docker images have trouble with that!
            with open(file) as f:
                rows = f.readlines()
                for raw_row in rows:
                    row = raw_row.split('\t')
                    customer = Customer()
                    customer.id = int(row[0])
                    customer.first_name = row[1]
                    customer.last_name = row[2]
                    customer.address = row[3]
                    customer.state = row[4]
                    customer.zip_code = str(row[5])

                    status = PurchaseStatusChange.canceled if row[
                        6] == 'canceled' else PurchaseStatusChange.new

                    product = Product()
                    product.id = int(row[7])
                    product.name = row[8]

                    purchase = Purchase()
                    purchase.customer = customer
                    purchase.product = product
                    purchase.status_change = status
                    purchase.amount = float(row[9])
                    purchase.datetime = dateutil.parser.parse(row[10])

                    yield purchase
        except Exception as e:
            log(ERROR, '', e)
            yield None
Ejemplo n.º 2
0
 def update_product_by_id(self, product_id: str, data: dict) -> Product:
     LOGGER.debug(f'Updating product {product_id} in database')
     product = Product.objects(id=product_id).first()  # pylint: disable=no-member
     if not product:
         raise NotFoundException
     product.update(**data)  # pylint: disable=no-member
     product = Product.objects(id=product_id).first()
     return product
Ejemplo n.º 3
0
 def get_products(self, page: int) -> (list, int):
     LOGGER.debug(f'Getting products page {page}')
     products_total = Product.objects().count()
     if page == 1:
         products = Product.objects().limit(LIMIT_PER_PAGE)
     else:
         products = Product.objects.skip(
             (page - 1) * LIMIT_PER_PAGE).limit(page * LIMIT_PER_PAGE)
     return products, products_total
def create_purchase():
    product = Product()
    product.name = 'Widget'
    product.id = 1
    test_purchase = Purchase()
    test_purchase.customer = create_customer()
    test_purchase.product = product
    test_purchase.amount = 99.99
    test_purchase.datetime = datetime.now()
    test_purchase.status_change = PurchaseStatusChange.new
    return test_purchase
Ejemplo n.º 5
0
 def get_product_by_id(self, product_id: str) -> Product:
     LOGGER.debug(f'Getting product {product_id} in database')
     product = Product.objects(id=product_id).first()  # pylint: disable=no-member
     if not product:
         LOGGER.debug('None product found to product_id informed')
         raise NotFoundException
     return product
Ejemplo n.º 6
0
    def inserting_products(self):
        """
        Inserting products into Product table via downloaded JSON
        """

        if len(self.session.query(Product).all()) == 0:
            print(f'{CONSTANTS.GREEN}Insertion des produits.')

            with open(
                    f'{CONSTANTS.PRODUCTS_JSON_DIR}{CONSTANTS.PRODUCTS_JSON}',
                    'r',
                    encoding='utf-8') as infile:
                data = json.load(infile)

                for each_product in data['products']:
                    for each_shop in each_product['selling points']:
                        if "β" not in each_shop:
                            cat, name, note, _, url = each_product.values()

                            category_id = self.session.query(Category).filter(
                                Category.name == cat)

                            for row in category_id:
                                self.session.add(
                                    Product(row.id, name, note, each_shop,
                                            url))

            self.session.commit()
        else:
            print(f"{CONSTANTS.GREEN}Produits déjà insérés !")
Ejemplo n.º 7
0
    def findById(self, id):

        conn = ConnectionManagment.getConnection()

        cursor = conn.cursor()
        tupleId = (id, )
        sql = 'select * from product where product_id = %s'
        cursor.execute(sql, tupleId)

        item = cursor.fetchone()

        conn.commit()
        conn.close

        try:
            product = Product(item[0], item[1], item[2], item[3])
        except:
            product = Product(None, None, None, None)

        return product
Ejemplo n.º 8
0
def add_product():
    category_id = request.forms.get('category')
    title = request.forms.get('title')
    description = request.forms.get('desc')
    favorite = request.forms.get('favorite')
    price = request.forms.get('price')
    img_url = request.forms.get('img_url')
    product = Product(category_id, description, price, title, favorite,
                      img_url)
    result = _db_adapter.add_product(product)
    return result
Ejemplo n.º 9
0
    def create_product(self, data: dict):
        try:
            LOGGER.debug('Creating product service')
            self.__validations.product_data(data=data)
            product = Product(**data)
            product = self.__database.save(document=product)
            return self.__parser.raw_to_json(data=product.to_mongo().to_dict())

        except ValidationError as exception:
            LOGGER.debug(traceback.format_exc())
            LOGGER.debug('Invalid fields value')
            raise InvalidFieldsValuesException(validations=exception.to_dict())

        except MissingRequiredFieldsException as exception:
            raise exception

        except Exception as exception:
            LOGGER.debug(traceback.format_exc())
            LOGGER.critical(exception)
            raise exception
def predict_new_product_price(product: ProductRequest, response: Response):
    product_ = Product(id=uuid.uuid4(),
                       product_type=product.product_type,
                       furnish_type=product.furnish_type,
                       floor_number=product.floor_number,
                       number_of_floors=product.number_of_floors,
                       size=product.size,
                       year_of_construction=product.year_of_construction,
                       location_id=product.location_id,
                       number_of_rooms=product.number_of_rooms)
    return_val = linear_regression.estimate_price(product_)
    if isinstance(return_val, str):
        response.status_code = 400
    return {"message": return_val}
Ejemplo n.º 11
0
    def findAll(self):

        conn = ConnectionManagment.getConnection()

        cursor = conn.cursor()
        sql = 'select * from product'
        cursor.execute(sql)
        data = cursor.fetchall()

        conn.commit()
        conn.close

        productList = []
        for item in data:
            product = Product(item[0], item[1], item[2], item[3])
            productList.append(product)

        return productList
Ejemplo n.º 12
0
    def process_line_for_db(line):
        address = unidecode.unidecode(line[4])
        if address == 'N/A' or len(address) <= 0:
            return None, None, None

        if address in locations.keys():
            location_id = locations[address]
        else:
            location_id = uuid.uuid4()
        location = Location(id=location_id, address=address, city_id=city.id)

        product_size = get_size(line)
        if product_size == "NULL" or float(product_size) < 10 or product_size is nan:
            return None, None, None

        product_id = uuid.uuid4()
        product = Product(id=product_id,
                          product_type=get_product_type(line),
                          furnish_type=get_furnish_type(line),
                          floor_number=get_floor_number(line),
                          number_of_floors=get_number_of_floors(line),
                          size=product_size,
                          year_of_construction=get_year(line),
                          location_id=location_id,
                          number_of_rooms=get_number_of_rooms(line))
        product_price = line[2]
        if product_price == "N/A":
            return None, None, None
        product_price = float(product_price) * 1000

        history_date = get_date(line)
        if history_date is None:
            return None, None, None

        history_id = uuid.uuid4()
        history = ProductHistory(id=history_id,
                                 product_id=product_id,
                                 date=history_date,
                                 price=product_price,
                                 currency_type="EUR")

        return product, history, location
Ejemplo n.º 13
0
def get_all_products():
    global full_product_list
    if full_product_list is None:
        conn = get_connection()
        cursor = conn.cursor()

        cursor.execute("select * from product")
        product_list = cursor.fetchall()

        products = []

        for product in product_list:
            products.append(
                Product(product[0],
                        product[1], product[2], product[3], product[4],
                        float(product[5]), product[6], product[7], product[8]))
            # products.append(Product(product[0], product[2], product[3], product[5], product[7],
            #                        float(product[4]), product[8], product[1], product[6]))

        cursor.close()
        full_product_list = products
    return full_product_list
 def setUpClass(cls):
     cls.identicalProducts = IdenticalProducts()
     cls.product1 = Product(1, ProductType.Detached, FurnishType.Furnished,
                            1, 3, 60.1, 2000, 1, 3)
     cls.product2 = Product(2, ProductType.Detached, FurnishType.Furnished,
                            1, 3, 60.0, 2000, 2, 3)
     cls.product3 = Product(3, ProductType.Detached, FurnishType.Furnished,
                            1, 6, 60.0, 1980, 3, 3)
     cls.product4 = Product(4, ProductType.Semi_detached,
                            FurnishType.Furnished, 0, 8, 60.0, 1900, 4, 3)
     cls.product5 = Product(5, ProductType.Semi_detached,
                            FurnishType.Furnished, -1, 3, 30.0, 2020, 5, 1)
     cls.product6 = Product(6, ProductType.Semi_detached,
                            FurnishType.Furnished, 1, 5, 50.0, 2000, 6, 2)
     cls.product7 = Product(7, ProductType.Semi_detached,
                            FurnishType.Furnished, 6, 6, 30.0, 2000, 7, 1)
     cls.products = [
         cls.product3, cls.product4, cls.product5, cls.product6,
         cls.product7
     ]
Ejemplo n.º 15
0
    def createproductobject(self):
        """
        Use datas of api.rawproductdata.
        Instanciate Product class objects with those datas.

        return : list of Product class objects.
        """

        productlist = []

        for products in self.api.rawproductdata:
            keys = [
                "categories_tags_fr",
                "url",
                "product_name",
                "nutriscore_grade",
                "stores_tags",
            ]
            values = dict(
                categories=products.get(keys[0]),
                linktourl=products.get(keys[1]),
                nutriscore=products.get(keys[3]),
                productname=products.get(keys[2]),
                shop=products.get(keys[4]),
            )
            if values["productname"] is not None and values[
                    "nutriscore"] is not None:
                productlist.append(
                    Product(
                        nutriscore=values["nutriscore"],
                        productname=values["productname"],
                        linktourl=values["linktourl"],
                        categories=values["categories"],
                        shop=values["shop"],
                    ))
        return productlist
 def setUpClass(cls):
     cls.pricePrediction = PricePrediction()
     cls.model_path = '../machine_learning/machinelearning'
     cls.product1 = Product(1, ProductType.Detached, FurnishType.Furnished, 1, 3, 60.1, 2000, 1, 3)
     cls.product2 = Product(2, ProductType.Detached, FurnishType.Furnished, 1, 3, 60.0, 2000, 2, 3)
Ejemplo n.º 17
0
 def delete_product_by_id(self, product_id: str) -> None:
     LOGGER.debug(f'Deleting product {product_id} in database')
     product = Product.objects(id=product_id).delete()  # pylint: disable=no-member
     if not product:
         raise NotFoundException
Ejemplo n.º 18
0
    return int(float(output_y))


if __name__ == '__main__':
    convert_locations_from_csv_to_json()
    create_model(model_path=model_all_features)
    create_model(model_path=model_size_and_location,
                 product_type=False,
                 furnish_type=False,
                 floor_number=False,
                 number_of_floors=False,
                 year_of_construction=False,
                 number_of_rooms=False)

    my_product_1 = Product("bdc1d015-0a37-48bb-abc9-c3fa5aaa164b", "HOUSE",
                           "FURNISHED", "NULL", "NULL", "136", "2019",
                           "665e1fb1-2622-4ac4-9750-c9dbff5fad72",
                           "5\n")  # 110.000
    my_product_2 = Product("a260f9b8-542b-4603-8aed-e8ff8b20c73f",
                           "SEMI_DETACHED", "UNFURNISHED", "9", "9", "43",
                           "2020", "665e1fb1-2622-4ac4-9750-c9dbff5fad72",
                           "2\n")  # 43.000
    my_product_3 = Product("e1433dbd-e4be-43bd-8fcb-da3f6aee997f", "HOUSE",
                           "FURNISHED", "NULL", "NULL", "400", "2020",
                           "68169837-39df-467b-bccd-5ebbd8d6aeed",
                           "0\n")  # 500.000
    my_product_4 = Product("6c8e8511-6ac6-48f0-b990-6ea75a20c851", "DETACHED",
                           "UNFURNISHED", "0", "4", "44", "2020",
                           "2997d39e-090f-46f2-99fe-e4c5c5ef21d8",
                           "2\n")  # 58.200
    my_product_5 = Product(id="6c8e8511-6ac6-48f0-b990-6ea75a20c852",
                           product_type="SEMI_DETACHED",
Ejemplo n.º 19
0
from entities.contact import Contact
from entities.address import Address
from entities.entity import Session, engine, Base

# generate database schema
entity.Base.metadata.create_all(entity.engine)

# start session
session = entity.Session()

manufacturer1 = Manufacturer('Star Knits')
factory1 = Factory('Palsana')
address1 = Address('Palsana', 'Surat', '394315')
contact1 = Contact('Yatiraj', '9737633000')
machine1 = Machine('RugMaker2000', 9001)
product1 = Product('Fine Rug', 'Rug')
machine1.products.append(product1)
factory1.machines.append(machine1)

manufacturer2 = Manufacturer('Milan Textiles')
factory2 = Factory('Kim')
address2 = Address('Kim', 'Surat', '394111')
contact2 = Contact('Brijesh', '9327922333')

manufacturer3 = Manufacturer('Unique Fur N Fabric P. Ltd')
factory3 = Factory('Sachin')
address3 = Address('Sachin', 'AwwShucksville', '31041')
contact3 = Contact('Vikash', '9825116375')

manufacturer4 = Manufacturer('CMC Textile ')
factory4 = Factory('Mumbai')