Skip to content

zazabe/cargo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This command aims to retrieve information from a social graph.

Data

A JSON file with the following structure:

[
  {
    "id": 1,
    "firstName": "Paul",
    "surname": "Crowe",
    "age": 28,
    "gender": "male",
    "friends": [
      2
    ]
  },
  ...
]

Link between friends consist in an adjacency list of ids, defined with the friends attribute.

Objective

The solution must allow to retrieve the following information:

  • Direct friends: Return those people who are directly connected to the chosen person.
  • Friends of friends: Return those who are two steps away, but not directly connected to the chosen person.
  • Suggested friends: Return people in the group who know 2 or more direct friends of the chosen person, but are not directly connected to her.

Solution

The solution is based on python, built around a command line tool. I focused on providing a solution within 3 hours, without wasting time in managing HTTP request for a REST API or defining a database model, which is not required to solve this problem.

Installation

Requirements

  • python, >=2.7
  • pip package manager, >=7.0.3

Setup

  • for production
    pip install https://github.com/zazabe/cargo/archive/master.zip

  • for development

    git clone https://github.com/zazabe/cargo.git /opt/source/cargo
    cd /opt/source/cargo 
    pip install -e .
    

Notes:

  • the code has only been tested on Ubuntu 14.04, but should work on any unix distribution supporting at least python 2.7.
  • to run unit tests, you must at least clone the repository and run tests from the root of the repo.

Usage

The command support a --help option for each sub-command.

Get direct friends of a person

cargo social <JSON_DATA_FILE> direct <PERSON_ID>

$ cargo social tests/fixtures.json direct 2
2 friend(s) found for Rob Fitz
- Paul Crowe
- Ben O'Carolan

Get people with a 2 steps relation with a person

cargo social <JSON_DATA_FILE> steps <PERSON_ID> --steps [NB_STEPS] (default: 2)

$ cargo social tests/fixtures.json steps 2
3 relation with 2 steps for Rob Fitz
- Victor
- Peter Mac
- Sarah Lane

Suggest people with at least 2 common friends for a person

cargo social <JSON_DATA_FILE> suggest <PERSON_ID>

$ cargo social tests/fixtures.json suggest 5
1 friend(s) suggestion for Peter Mac
- Katy Couch

Tests

Build Status

Unit tests are written with py.test, you must clone the source code to have all required files (fixtures, etc...) and run test properly.

Run all tests (at the root of the repository folder):

$ py.test tests/social.py

Additionally, tests are run by Travis CI at every commit.

About

Command to retrieve info from social graph data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages