Git Product home page Git Product logo

usersegmentation's Introduction

Project Details

This project is to segment a given user into different groups based on predefined configuration.

Requirements

Python with sqlalchemy sqlite3

Directory Structure

  • db_utils : contains DB utilities, SessionFactory being the actual interface. contains relevant models and relationships.
  • segmentation : contains segmentation utils, Segmentation being the actual interface.
  • main.py : entry point to segment a user
  • db.sqlite3 : text db with prepopulated data

How to use?

Not from scratch
  • 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
From scratch
  • 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

Code Design and classes

  • db_utils/connection.py/Connection :: to connect to actual DB
  • db_utils/session_factory.py/SessionFactory :: handles provisioning a connection, committing, rolling back and closing the connection
  • db_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 configuration
  • segmentation/segmentation.py/Segmentation :: contains all utility functions for segmentation.
    • __init__: initialise session, register operators, get all segments from database
    • get_user_segments : get all segments that the user falls into
    • flatten_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

Algorithm

  • 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

usersegmentation's People

Contributors

sighthon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.