I have little experience coding and I am having trouble coming up with a design for this specific application (the first one I am trying on my own). The app should be able to read and extract the info from a qrcode printed on a shopping receipt, use this info to access a web page and retrieve a table from it. Every tuple in the table corresponds to a product and it has 3 columns: the product description (str), the quantity (float), and a code (int).
Then it will use this information to search for the details of each product in a data base. I have 2 different data bases to search from: one for industrial products (that I search using the code attribute), and one for perishable products (that I search using the description attribute - using the fuzz package). These 2 sources will give me a json file containing detailed information about the products, but with a different schema. I also would like to have a 3rd source, which would be populated with information previously got from the 2 external sources.
The receipt would contain the information to instantiate an Order object and the json files the information to instantiate an Product objects. Also, Product objects could mean different things (items like food (that would have nutrition facts) or hygiene (that would not have nutrition facts), for example). And lastly, I would have a Person object, so that each Order would have a relation with a single Person, but the Person could be related to multiple Orders.
I am having trouble figuring out what would be the best design pattern, how to segregate and organize modules, what should be a class or when just using functions are fine and also how to store and access information. I am starting to study these subjects, but some guidance here would be very much appreciated. That is a lot of stuff, so here is what I have so far and some specific things I have in mind:
app
│ main.py (ask for user input to select receipt image and call other modules.
| In the end I have some json files for order info and product information)
│ qrcode.py (only functions that read the image and return the information)
│ search_order.py (only functions to access web page and return json file with order information)
| search_product.py (only functions to access data base and return json file with product details)
| order.json (store order details)
| product_by_code.json (store list of industrial products in json format)
| product_by_description.json (store list of perishable products in json format)
*Shortly I will look to store the info a sql DBMS, but that is what I have so far.
Some questions I have:
-
Order would be a class that will only store information and be composed of a unique ID attribute, a date of creation, a RetailStore object and a list of Product objects, and the quantity (weight or units) of each product. I believe those attribute should be created when a object is instantiated and not change after that. Is that a correct thinking or should it be more flexible? Should search_order.py be responsible for instantiating the object, since it is the source of the information? But one day the abstraction of Order could change, how to deal with that then?
-
Since I have different sources for the products detail information, should I have a single file dealing with all the sources or one for each and something to deal with them and provide an simpler interface for the instantiation of a Product?
-
Product would be a class that will only store information and be composed of description, category, brand, Nutrifacts object (if food), Ingredients object. Should I have an abstract Product class, and, in the same file, concrete sub classes like (Food, Cleaning, Hygiene, etc)? How to instantiate an object considering I have different sources for most of the information used here? Should I have different Product methods decorated with @classmethod to have alternative constructors? Should the Product class be in the same file as the Order class?
-
Once I have a Person object, with its Order objects (with its Product objects), how should I serialize (and then deserialize) all this information? Should I store locally in a json file?
I feel I am living in a tree recursive maze trying to figure these things out. I have many other doubts, but I hope clearing up those questions is a good above start.
Aucun commentaire:
Enregistrer un commentaire