|
| 1 | + |
| 2 | +High-level design document |
| 3 | +========================== |
| 4 | + |
| 5 | + |
| 6 | +Data model |
| 7 | +---------- |
| 8 | + |
| 9 | + - Users: Django built in user model |
| 10 | + - Session: Django session is used to store information under the following keys: |
| 11 | + - `experiments_enrollments` **WHAT SHOULD THIS CONTAIN?** |
| 12 | + - `experiments_goals` |
| 13 | + - `experiments_session_key` **WHEN IS IT WRITTEN?** |
| 14 | + - `experiments_verified_human` |
| 15 | + - Cookies: |
| 16 | + - `sessionid` used to associate with Django session stored on server side |
| 17 | + - Experiments: |
| 18 | + - Experiments and experiment alternatives are automatically created when first |
| 19 | + occurrence in a template or view code appears. They are stored in table `experiments_experiment` |
| 20 | + |
| 21 | + +-----------+-------------+---------------+---------------------+--------------------+-------+------------+----------+ |
| 22 | + | name (PK) | description | alternatives" | relevant_chi2_goals | relevant_mwu_goals | state | start_date | end_date | |
| 23 | + |
| 24 | + - Enrolments |
| 25 | + - Bots are ignored |
| 26 | + - Session-based users are enroled based on session id **STORED WHERE?** |
| 27 | + - Logged in users are enroled based on their user id using table `experiments_enrollment` |
| 28 | + |
| 29 | + +-----+-----------------+-----------+-------------+---------------+---------+ |
| 30 | + | id | enrollment_date | last_seen | alternative | experiment_id | user_id | |
| 31 | + |
| 32 | + - Goals: |
| 33 | + - Definitions, goals must be created in advance and described in `settings.EXPERIMENTS_GOALS`. |
| 34 | + - Counters are stored in Redis using the following key names: |
| 35 | + |
| 36 | + COUNTER_CACHE_KEY = 'experiments:participants:' |
| 37 | + PARTICIPANT_KEY = '%s:%s:participant' % (experiment.name, alternative_name) |
| 38 | + COUNTER_FREQ_CACHE_KEY = 'experiments:freq:%s' |
| 39 | + GOAL_KEY = '%s:%s:%s:goal' % (experiment.name, alternative_name, goal_name) |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +Request-response cycle |
| 44 | +---------------------- |
| 45 | +The workflow is different for logged in users and session-based auth. |
| 46 | + |
| 47 | +### Session users |
| 48 | + |
| 49 | + - `experiments.utils.SessionUser` |
| 50 | + - **WHAT KEYS ARE USED ON SESSION?** |
| 51 | + - **WHEN ARE THESE STORED?** |
| 52 | + |
| 53 | + |
| 54 | +### Logged in users |
| 55 | + |
| 56 | + - `experiments.utils.AuthenticatedUser` |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +Goal tracking |
| 61 | +------------- |
| 62 | + |
| 63 | + - Check if user is enrolled |
| 64 | + - Increment appropriate counter in Redis |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +Analytics |
| 72 | +--------- |
| 73 | + |
| 74 | + - Read goal counters and enrolment denominator to compute rates |
| 75 | + - Compute stats |
| 76 | + |
| 77 | + |
| 78 | + |
0 commit comments