From 7f90eb9ec3f42f48722a3a55e4a3de0d814538c6 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Thu, 28 Apr 2022 18:49:00 +0200 Subject: [PATCH] Update dummy baskets generation to make it look more realistic --- src/purchase/fixtures/products.json | 45 ++++++++++++++++--- .../commands/generate_dummy_baskets.py | 8 +++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/purchase/fixtures/products.json b/src/purchase/fixtures/products.json index 8d9c08a..d04f895 100644 --- a/src/purchase/fixtures/products.json +++ b/src/purchase/fixtures/products.json @@ -14,33 +14,66 @@ "model": "purchase.product", "fields": { "created_at": "2022-04-26T20:30:22.959Z", - "updated_at": "2022-04-26T20:30:22.959Z", + "updated_at": "2022-04-27T21:04:04.197Z", "name": "Villard'Ain", "image": "", "unit_price_cents": 290, - "display_order": 1 + "display_order": 2 } }, { "model": "purchase.product", "fields": { "created_at": "2022-04-26T20:30:22.959Z", - "updated_at": "2022-04-26T20:30:22.959Z", + "updated_at": "2022-04-28T16:09:00.142Z", "name": "Herbier", "image": "", "unit_price_cents": 330, - "display_order": 1 + "display_order": 4 } }, { "model": "purchase.product", "fields": { "created_at": "2022-04-26T20:30:22.959Z", - "updated_at": "2022-04-26T20:30:22.959Z", + "updated_at": "2022-04-27T21:04:04.192Z", "name": "Blanc vache", "image": "", "unit_price_cents": 650, - "display_order": 1 + "display_order": 3 + } + }, + { + "model": "purchase.product", + "fields": { + "created_at": "2022-04-28T16:08:08.298Z", + "updated_at": "2022-04-28T16:09:13.196Z", + "name": "Ap\u00e9rich\u00e8vres", + "image": "", + "unit_price_cents": 330, + "display_order": 5 + } + }, + { + "model": "purchase.product", + "fields": { + "created_at": "2022-04-28T16:08:16.542Z", + "updated_at": "2022-04-28T16:09:25.690Z", + "name": "Clougert", + "image": "", + "unit_price_cents": 450, + "display_order": 6 + } + }, + { + "model": "purchase.product", + "fields": { + "created_at": "2022-04-28T16:08:20.471Z", + "updated_at": "2022-04-28T16:09:34.003Z", + "name": "Brique", + "image": "", + "unit_price_cents": 290, + "display_order": 7 } } ] diff --git a/src/purchase/management/commands/generate_dummy_baskets.py b/src/purchase/management/commands/generate_dummy_baskets.py index bad5540..6e00ebc 100644 --- a/src/purchase/management/commands/generate_dummy_baskets.py +++ b/src/purchase/management/commands/generate_dummy_baskets.py @@ -32,13 +32,17 @@ class Command(BaseCommand): def generate_baskets(self, payment_methods, products): count = int(random.normalvariate(20, 10)) + methods_weights = [random.randint(1, 6) for _ in range(len(payment_methods))] + products_weights = [1 / product.display_order for product in products] for _ in range(count): - method = random.choice(payment_methods) + method: PaymentMethod = random.choices( + payment_methods, weights=methods_weights + )[0] basket = Basket.objects.create(payment_method=method) items = [] item_count = int(random.normalvariate(3, 2)) for _ in range(item_count): - product = random.choice(products) + product: Product = random.choices(products, weights=products_weights)[0] items.append( BasketItem( product=product,