From 759c06a289a2b34c2ae1b6564a4c5647209acd9f Mon Sep 17 00:00:00 2001 From: Samuel Paccoud - DINUM Date: Fri, 8 Mar 2024 07:56:32 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB(demo)=20impro?= =?UTF-8?q?ve=20distribution=20in=20number=20of=20identities=20per=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current implementation of our product demo via the make command lacks user identity for a significant portion of generated users, limiting the realism of the showcased scenarios. As it stands, users created by the make command lack complete information, such as full names and email addresses, because they don't have any identity. I tried to come up with the simplest solution: We now generate a very small portion of our users with 0 identities. The probability for users to have only 1 identity is the highest but they can have up to 4 with decreasing probabilities. I removed the possibility to set a maximum number of identities as it doesn't bring any value. 3% percent of the identities created will have no email and 3% no name. Fixes https://github.com/numerique-gouv/people/issues/90 --- src/backend/demo/defaults.py | 1 - src/backend/demo/management/commands/create_demo.py | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/demo/defaults.py b/src/backend/demo/defaults.py index a43e253..4981569 100644 --- a/src/backend/demo/defaults.py +++ b/src/backend/demo/defaults.py @@ -3,6 +3,5 @@ NB_OBJECTS = { "users": 1000, "teams": 100, - "max_identities_per_user": 3, "max_users_per_team": 100, } diff --git a/src/backend/demo/management/commands/create_demo.py b/src/backend/demo/management/commands/create_demo.py index 3ec1440..a60e3f3 100755 --- a/src/backend/demo/management/commands/create_demo.py +++ b/src/backend/demo/management/commands/create_demo.py @@ -129,16 +129,19 @@ def create_demo(stdout): users_values = list(models.User.objects.values("id", "email")) for user_dict in users_values: for i in range( - random.randint(0, defaults.NB_OBJECTS["max_identities_per_user"]) + random.choices(range(5), weights=[5, 50, 30, 10, 5], k=1)[0] ): user_email = user_dict["email"] queue.push( models.Identity( user_id=user_dict["id"], sub=uuid4(), - email=f"identity{i:d}{user_email:s}", is_main=(i == 0), - name=fake.name(), + # Leave 3% of emails and names empty + email=f"identity{i:d}{user_email:s}" + if random.random() < 0.97 + else None, + name=fake.name() if random.random() < 0.97 else None, ) ) queue.flush()