Giter Club home page Giter Club logo

recommendations's Introduction

Recommendations Service

Build Status codecov

This repo contains details of our Recommendations Service. The resource model has no persistence to keep the application simple. It's purpose is to show the correct API and return codes that should be used for a Recommendations Service API.

Prerequisite Installation using Vagrant

The easiest way to use this service is with Vagrant and VirtualBox. if you don't have this software the first step is to download and install it.

Download VirtualBox

Download Vagrant

Clone the project to your development folder and create your Vagrant VM

$ git clone https://github.com/NYU-DevOps-S18-Recommendations/recommendations.git
$ cd recommendations
$ vagrant up

Once the VM is up you can use it with:

$ vagrant ssh
$ cd /vagrant
$ python service.py

When you are done, you can use Ctrl+C to stop the server and then exit and shut down the vm with:

$ exit
$ vagrant halt

If the VM is no longer needed you can remove it with:

$ vagrant destroy

Manually running the Tests

Run the tests using nosetests and coverage

$ nosetests
$ coverage report -m --include=service.py

API Calls with specified inputs available within this service

GET  /recommendations - Retrieves a list of recommendations from the database
GET  /recommendations/{id} - Retrieves a recommendation with a specific id
POST /recommendations - Creates a recommendation in the datbase from the posted database
PUT  /recommendations/{id} - Updates a recommendation in the database from the posted database
PUT  /recommendations/{id}/likes - Updates the count of likes for a given product id from the posted database
DELETE /recommendations{id} - Removes a recommendation from the database that matches the id

Valid content description of JSON file

{
  "id": <int> #the id of a recommendation 
  "product_id": <int> #the id of the product in the recommendation 
  "recommended_product_id": <int> #the id of the product that's being recommended with a given product
  "recommendation_type": <string> #describes the type of recommendation(Up-sell, Cross-Sell, Accessory)
  "likes" : <int> #a count of the number of people who like the recommendation 
}

What's featured in the project?

* service.py -- the main Recommendation Service using Python Flask
* models.py -- the data model using in-memory model
* tests/test_service.py -- test cases against the service
* tests/test_models.py -- test cases against the Recommendation model

recommendations's People

Contributors

nguyenkatie1 avatar jaewhyun avatar gau820827 avatar annelai avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

recommendations's Issues

Download and install the Bluemix CLI

As a developer
I need the CLI to interact with Bluemix
So that the service can be deployed through the command line

Assumptions:

  • There's a vagrant file for setting up the service

Acceptance Criteria:

Given the service is deployed
When the vagrant up
Then the Bluemix CLI would be installed

Add .vagrant/ to .gitignore file

As a developer
I need to add .vagrant/ to the .gitignore file
So that this directory does not get checked into Github.

Assumptions:

  • The .vagrant/ directory contains personal keys for our vagrant VM, so we want to make sure this does not get uploaded to Github

Acceptance Criteria:

.vagrant/ will be ignored

I need to deploy my service automatically

As a developer
I need to build an automated CI/CD DevOps Pipeline
So that I can deploy my service automatically

Assumptions:

  • Travis CI account is available

Acceptance Criteria:

Given the .travis.yml file
When someone pushes to the master branch or submits a Pull Request
Then it'll be used to configure Travis CI for automatic deployment

Create Vagrantfile

As a Developer
I need a vagrant file to install all of the needed software to run the service
So that members of the team can quickly get a development environment running

Assumptions:

  • Members of the team will use Vagrant for the same development environment

Acceptance Criteria:

Given a team member downloads the vagrant file
When she/he does vagrant up && vagrant ssh
Then she/he should be able to start developing

Modify models.py file to add persistence to model definition

As a developer
I need my model to be added to the persistence
So that the data would be saved correctly

Assumptions:

  • We had a service and a database setup

Acceptance Criteria:

Given the service starts with a persistence database
When the resources are modified
Then the actions will be saved correctly

I need to QUERY a recommendation

As a Service Provider
I need a way to query the recommendations
So that they can be searched for a certain recommendations

Assumptions:

  • A Recommendations database already exists for products

Acceptance Criteria:

Given a product id #
When I call GET product/ id/ #
Then I should see all recommendations matching all my query specific parameters

Add a Unit Test Stage to the pipeline in Bluemix

As a developer
I need a unit test stage in the pipeline
So that I can run units tests with nosetests

Assumptions:

  • Already have a pipeline in Bluemix. And we use the unit test stage to run all unit tests.

Acceptance Criteria:

Given a unit test stage and unit tests
When the master branch is updated or someone submits a Pull Request
Then all units tests will be run with nosetests

Write a features and steps file for READ

As a Developer
I need .features and .steps file for the READ feature written Gherkins syntax
So that I can confirm a feature is behaving the way it is supposed to

Assumptions:

  • There is existing READ API

Acceptance Criteria:

Given the Behave command
When assuming the server is running
Then the scenario output will be green

Write a .features and .scripts for QUERY

As a Developer
I need .features file for QUERY feature in Gherkins syntax
So that I can confirm a feature is behaving the way it is supposed to

Assumptions:

  • There is an existing QUERY API

Acceptance Criteria:

Given the Behave command
When assuming the server is running
Then the scenario output (@given, @when, @then) will be green

Need an Action api call for increasing numbers of like

As a User
I need an action to like the recommendation
So that I can show my feedback on the recommendation

Assumptions:

  • The recommendation model has a field "like" storing the counts of being liked
  • One user can like one certain recommendation at one time

Acceptance Criteria:

Given a unique recommendation id #
When I call PUT /recommendations/#/like
Then the counts of likes for # will increase one

Need to create a README file

As a Service Provider
I need a README file that gives instructions on what calls are available, what inputs to expect and how to run/test our code
So that users of our service know how our service works and new team members would know how to set up their environment

Assumptions:

  • The content of the README file is readable, understandable, with easy to follow instructions where applicable.

Acceptance Criteria:

Given a user of our service
With a need to understand how our service works
Then they would be able to consult our README file to get started 

Create a UI with our APIs

As a customer
I need a UI incorporating APIs
So that we can retrieve the resources easily

Assumptions:

  • Given a service and APIs

Acceptance Criteria:

Given the service and APIs
When the user hits the UI
Then the user would able to retrieve the resources

Add a Dev Deployment Stage to the pipeline in Bluemix

As a developer
I need a dev deployment stage in the pipeline
So that I can deploy to the Dev space

Assumptions:

  • Already have a pipeline in Bluemix and a unit test stage to run all unit tests. Only deploy the service if the unit tests pass.

Acceptance Criteria:

Given a dev deployment stage and a dev space
When the updated service pass all unit tests  
Then the service will be deployed to dev space

I need to LIST recommendations

As a Service Provider
I need a way to get a list of all my recommendations for all products
So that I could easily check my resources

Assumptions:

  • We had our recommendation relations database.

Acceptance Criteria:

Given a person want to get all resources
When GET /recommends/ is called
Then an array of all recommendations should be returned

Add an Integration Test Stage to the pipeline

As a developer
I need an integration test stage in the pipeline
So that I can deploy the project when the master branch changes.

Assumptions:

  • The DevOps pipeline exists in Bluemix

Acceptance Criteria:

Given the integration test stage in the DevOps pipeline in Bluemix
When "behave" on the Dev deployment
Then integration tests will be run

Add a Production Deploy Stage to the pipeline

As a developer
I need to add a Production Deploy Stage to the pipeline
So that the service will be automatically deployed after the passing the test

Assumptions:

  • We had set up our integration test part

Acceptance Criteria:

Given someone pushes to the master branch or submits a Pull Request
When the service passed all the integration test cases
Then the service would be deployed automatically

Create a setup.cfg file

As a developer
I need a convenient script to run all test cases automatically
So that I could easily ensure our products pass all tests

Assumptions:
We're using nosetests to run the test suite.

Acceptance Criteria:

Given a setup.cfg file with nosetests options
When I type nosetests
Then I can run the test suites

Write a features and steps file for LIST

As a service provider
I need .features and .steps file for the LIST feature written in Gherkins syntax
So that when a user calls LIST, the service will behave as expected

Assumptions:

  • There is an existing LIST API that the user can call.

Acceptance Criteria:

Given a call to the LIST API
When running behave
Then the scenario output will be green

Set up a .gitignore file

As a developer
I need to have a file that lists all the files that should be ignored
So that the team can determine which files and directions to ignore before committing. Everyone who clones that repo will than have those files ignored.

Assumptions:

  • Assume that these files will be ignored

Acceptance Criteria:

Given a file listed in the .gitignore file
When a file is listed those files will be ignored
Then only relevant files will be executed

Create a requirements.txt file

As a developer
I need to know all used python libraries
So that I can have my environment settings align with others on team

Assumptions:

  • All libraries should be specified with a version in use.

Acceptance Criteria:

Given the requirements.txt file
When I type pip install -r requirements.txt
Then it automatically installs all required python libraries

I need to CREATE a recommendation

As a Service Provider
I need a way to create recommendations
So that they can be retrieved later and used to recommend products

Assumptions:

  • A Recommendations database already exists to create new recommendations
  • A recommendation does not yet exist for a particular product
  • A Products database already exists to retrieve the necessary information for the recommended products

Acceptance Criteria:

Given a product with an id #
When I call POST /id /#
Then I should create a new entry of recommendation/recommendations (based on how many products are frequently bought together) for id #  in the Recommendations database.

Write a features and steps file for ACTION

As a service provider
I need .features and .steps file for the ACTION feature written in Gherkins syntax
So that when a user calls ACTION, the service will behave as expected

Assumptions:

  • There is an existing ACTION API that the user can call.

Acceptance Criteria:

Given a call to the Action API
When running behave
Then the scenario output will be green

Write a features and steps file for DELETE

As a service provider
I need .features and .steps file for the DELETE feature written in Gherkins syntax
So that when a user calls Delete, the service will behave as expected

Assumptions:

  • There is an existing Delete API that the user can call.

Acceptance Criteria:

Given a call to the Delete API
When running behave
Then the scenario output will be green

I need to DELETE a recommendation

As a Service Provider
I need a way to delete recommendations
So that they can be removed from the existing recommendations when the recommended items are no longer in the inventory

Assumptions:

  • A Recommendations database already exists for products
  • Recommended item/s are no longer in the inventory / does not exist in the database

Acceptance Criteria:

Given a product with an id #
When I call DELETE /id /#
Then I should no longer see the product in any recommendations of any products in the Recommendations database

Need to create a model that represents a recommendation

As a Service Provider
I need to create a model that represents a recommendation
So that they can be retrieved later and used to recommend products

Assumptions:

  • The model will be kept in the model.py file

Acceptance Criteria:

Given a product ID#
When a service request for a recommendation is made
Then the model best reflects the relationship between that product and another

Create Cloud Foundry metadata files

As a developer
I need Cloud Foundry metadata files
So that Bluemix will know how to correctly deploy the application

Assumptions:

  • already created a Cloud Foundry application in Bluemix

Acceptance Criteria:

Given all metadata files including manifest.yml, Procfile, and runtime.txt
When I push the application to IBM cloud
Then the service is running on Bluemix

Need to update Vagrantfile to include requirements file

As a developer
I need to have a requirements file and have it accompany the Vagrantfile
So that each team member implements these requirements to ensure the same coding standards are followed

Assumptions:

  • The requirements will be listed in the file, requirements.txt,
  • And will be provisioned in the Vagrantfile

Acceptance Criteria:

The requirements listed satisfies the needed applications and standards for our goals as a service

I need to READ a recommendation

As a Service Provider
I need a way to read recommendations
So that they can be read later to recommend products

Assumptions:

  • A Recommendations database already exists for products
  • A product has an existing recommendation/recommendations in the database

Acceptance Criteria:

Given a product with an id #
When I call GET /id /#
Then I should see recommendations for the id #

Add Swagger docs to document the APIs

As a developer
I need to describe the API endpoints, available resources, and operations that can be called against
these resources
So that other developers know how to call the APIs

Assumptions:

  • We have a swagger folder and some APIs in our service

Acceptance Criteria:

Given the service
When developers go to /apidocs/index.html
Then all documented APIs are available there

Set up Travis CI pipeline

As a Developer
I need a way to automatically build and test code when a commit has been made and pushed to a GitHub repository
So that our code can implement continuous integration

Assumptions:

  • .travis.yml file will be used to test whether code can be continuously integrated

Acceptance Criteria:

Given a new update in code,
When a code is committed and pushed
Then Travis CI will tell us whether the code passed or not

Create a ./tests folder

As a developer
I need tests folder
So that I can keep all test cases in it

Assumptions:

  • pass all the test cases before pushing the code

Acceptance Criteria:

Given a tests folder
When I have a new test case
Then I can put it inside

Add persistence to Vagrantfile as a Docker container

As a developer
I need to add Redis docker container to the Vagrantfile
So that the database will be setup everytime

Assumptions:

  • We had a Vagrant file

Acceptance Criteria:

Given a Vagrant file and corresponding Docker settings
When the service starts
Then the environment for running Redis will be set up

I need to deploy my application to the cloud

As a developer,
I need to deploy my application to the cloud
So that I can take advantage of the horizontal scaling capabilities of the cloud

Assumptions:

  • Cloud Foundry cloud in IBM Bluemix is available

Acceptance Criteria:

Given the application
When deployed to the Cloud Foundry application in Bluemix
Then the cloud will create another instance of the application

Add persistent storage

As a developer
I need to add persistent storage to our service for continuous integration
So that the data could be kept every time the service starts

Assumptions:

  • We had a service running on the cloud

Acceptance Criteria:

Given a service running on the cloud
When the service started
Then the Redis database would be connected

Need a service template for recommendations

As a Developer
I need a template to contain the skeleton for our service
So that I can develop and initialize the service

Assumptions:

  • The template uses Flask

Acceptance Criteria:

Given the Flask template
When we do python service.py
Then the server will start

Fix Host URL

As a service provider
I need my service URL to be renamed to nyu-recommendation-service-s18
So that it conforms to the requirements of the hw assignment

Create a Features folder for BDD automated testing environment

As a developer
I need to set-up a Features folder
So that we can utilize behave to implement BDD automated testing

Assumptions:

  • The features folder will describe the features of our service, using Gherkin syntax. The folder will also contain an environment.py file and a step.py file for each feature

Acceptance Criteria:

Given a feature file
When a feature is written
Then there should be accompanying steps.py file

Create a dev environment

As a Developer
I need a dev environment to quickly provision complex configurations and to automate the creation of a VM set-up
So that all members of the team share the same development environment.

Assumptions:

  • Our dev environment will be created via a Vagrantfile which will set-up the same environment for all members.

Acceptance Criteria:

Given each member has the latest Vagrantfile downloaded
When a member issues Vagrant up && Vagrant ssh command
Then a VM environment will have been created according to configurations defined 
in the Vagrantfile.

Write .features and .steps file for UPDATE

As a developer
I need .features and .steps file for UPDATE feature
So that I can test the behavior of the UPDATE feature

Assumptions:

  • There is an UPDATE API in our service

Acceptance Criteria:

Given an Update API 
When assuming the server is running
Then the scenario output will be green

Install PhantomJS for Selenium browser support

As a developer
I need a web browser without a graphical interface
So that I can run behave tests faster

Assumptions:

  • Selenium is already available

Acceptance Criteria:

Given the Vagrant file
When vagrant up --provision and "behave" 
Then I'll be able to see the behavior of our features

Write .features and .steps file for CREATE

As a Developer
I need .features file for CREATE feature in Gherkins syntax
So that I can confirm a feature is behaving the way it is supposed to

Assumptions:

  • There is existing CREATE API

Acceptance Criteria:

Given the Behave command
When assuming the server is running
Then the scenario output will be green

I need to UPDATE a recommendation

As a Service Provider
I need a way to update recommendations
So that they can be updated in accordance to new/incoming products

Assumptions:

  • A Recommendations database already exists for products
  • A product has an existing recommendation/recommendations in the database

Acceptance Criteria:

Given a product with an id #
When I call PUT  /id /#
Then it would update the recommendations for the product id #

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.