This project is to segment a given user into different groups based on predefined configuration.
Python with sqlalchemy sqlite3
- db_utils : contains DB utilities,
SessionFactorybeing the actual interface. contains relevant models and relationships. - segmentation : contains segmentation utils,
Segmentationbeing the actual interface. - main.py : entry point to segment a user
- db.sqlite3 : text db with prepopulated data
- Install python and run
pip install -r requirements.txt - Data is prepopulated into db.sqlite3
- Run main.py to get segment classification for pre populated user
python main.py
- Install python and run
pip install -r requirements.txt - Delete db.sqlite3
- Edit populate_data.py to add users, restaurants, user preferences, orders, dishes, etc.
- Run populate_data.py to populate data into database
python populate_data.py - Edit main.py file to query user you want to get segments for
- RUn main.py to get a list of segments this user belongs to
python main.py
db_utils/connection.py/Connection:: to connect to actual DBdb_utils/session_factory.py/SessionFactory:: handles provisioning a connection, committing, rolling back and closing the connectiondb_utils/models.py:: database models (User, Dish, Restaurant, Order, UserPreference)segmentation/operators.py/Operator:: defines different operators that will be used in the rule based configurationsegmentation/segmentation.py/Segmentation:: contains all utility functions for segmentation.__init__: initialise session, register operators, get all segments from databaseget_user_segments: get all segments that the user falls intoflatten_details: flatten user details to ease out the user details to segment config matching_resolve_seg_pref: resolve a section in config which is not an operation but an attribute to check for__resolve_seg_ope: resolve a section in config which is an operation like or/and
- Store all segments with respective config to database
- To get segments for a user, get the user details and flatten them.
- Next, pass the user details through every segment to check if it satisfies.
- Satisfaction algorithm:
Recursively,
- If section is an operation like or/and, pass it through
_resolve_seg_ope - If not, pass it through
resolve_seg_pref
- If section is an operation like or/and, pass it through