Giter VIP home page Giter VIP logo

91cobotbackend's Introduction

91cobot-Web-API

A flask based web api for acquisition of memberships data from cobot and also calculate some required metrics from them to report analysis on monthly basis.

##Requirements

  1. Python 2.7+
  2. pip installed
  3. virtualenv

##Instructions

  1. First install some system dependency

        $ sudo apt-get install python-dev libssl-dev libffi-dev libmysqlclient-dev
  2. Install all python package dependencies by using pip

        $ pip install -r requirements.txt 
  3. Also, set some required environment variables for this prototype

        $ export CONFIG='local'             # 'dev' for production
        $ export COBOT_DB_URL='<database-url>'
        $ export COBOT_TOKEN='<cobot-access-token>'
        $ export LOG_FILE_PATH='<log-file-folder-path>'
  4. To run application with simple flask server

        $ python manage.py runserver
  5. To create database tables

        $ python manage.py create_db
  6. To delete database tables

        $ python manage.py drop_db
  7. To do database schema migrations

        $ python manage.py db [command]
    
        where command can be any of these {upgrade,heads,merge,migrate,stamp,show,current,edit,init,downgrade,branches,history,revision}
        upgrade             Upgrade to a later version
        heads               Show current available heads in the script directory
        merge               Merge two revisions together. Creates a new migration
                            file
        migrate             Alias for 'revision --autogenerate'
        stamp               'stamp' the revision table with the given revision;
                            don't run any migrations
        show                Show the revision denoted by the given symbol.
        current             Display the current revision for each database.
        edit                Upgrade to a later version
        init                Generates a new migration
        downgrade           Revert to a previous version
        branches            Show current branch points
        history             List changeset scripts in chronological order.
        revision            Create a new revision file
  8. To run task which gets data from cobot api and add that to database tables

        $ python manage.py run_task_data [-sd START_DATE or --startDate=START_DATE]
          [-ed END_DATE or --endDate=END_DATE] [ -h HUB_NAME or --hub=HUB_NAME]
          
          # DATE should be in format 'YYYY-MM-DD'

    Note: To run task for a specific date, then you should only pass that date as -sd or --startDate.

  9. To run task which calculate member report metrics and append them to database tables

        $ python manage.py run_task_report [-sd START_DATE or --startDate=START_DATE]
          [-ed END_DATE or --endDate=END_DATE] [ -h HUB_NAME or --hub=HUB_NAME]
          
          # DATE should be in format 'YYYY-MM'

    Note: To run task for a specific date, then you should only pass that date as -sd or --startDate.

  10. To run application within guicorn server

        $ python manage.py gunicorn
        # OR
        $ python manage.py gunicorn -c gunicorn-conf.py

    Note: This command also supports all gunicorn parameters

##Endpoints

Cards Endpoint

A api endpoint returns all necessary information to fill some basic card's data

/api/cards

By default, returns all information regarding all hubs

Parameters

  • hub_name : a hub name, to get report details regarding a particular hub

      /api/cards?hub_name=91sgurgaon
    

Response

Type - JSON

    [
        {
            "card_no": 1,
            "total_active_members": 520,
            "new_members": {
                "percent": 3.0,
                "duration": 30
            }
        },
        {
            "card_no": 2,
            "mrr_value": 4827354.00,
            "increment_revenue": {
                "percent": 4.0,
                "duration": 30
            }
        },
        {
            "card_no": 3,
            "new_members": {
                "count": 7,
                "duration": 7,
                "base_percent": 0.5
            }
        },
        {
            "card_no": 4,
            "leave_members": {
                "count": 3,
                "duration": 7,
                "base_percent": 0.6
            }
        }
    ]

Report Endpoint

A api endpoint returns all details of member's report of all hubs or specific hubs to plot that data on graph.

/api/reports

By default, returns all member's report regarding all hubs

Parameters

  • hub_name : a hub name, to get report details regarding a particular hub

      /api/reports?hub_name=91sgurgaon
    
  • plan_type : a plan type, to get report details regarding a particular types of plan. It's value can be of four types (i.e Full Time, Part Time, Others and Ignore)

      /api/reports?hub_name=91sgurgaon&plan_type=Full Time
    
  • from & to : a range of dates, to get report data of a specific duration

    Note:- Date should be in YYYY-MM format

      /api/reports?hub_name=91sgurgaon&plan_type=Full Time&from=2015-03&to=2015-09
    

Response

Type - JSON

    [
        {
            "hub_plan": {
                "hub": {
                    "name": "91springboard",
                    "location": {
                        "name": "Okhla"
                    }
                },
                "plan": {
                    "name": "Full Time (4+)",
                    "type": "FULL-TIME",
                    "price": 4999.00
                }
            },
            "time": {
                "month": 5,
                "year": 2015,
                "date": "2015-05"
            },
            "count": {
                "new_member": 23,
                "retain_member": 231,
                "leave_member": 2
            },
            "revenue": {
                "new_member": 114977.0000,
                "retain_member": 1154769.0000,
                "leave_member": 9998.0000
            }
        }
    ]

91cobotbackend's People

Contributors

kodekracker avatar

Watchers

James Cloos avatar Aman Kumar 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.