GithubHelp home page GithubHelp logo

location-code-test's Introduction

Introduction

Welcome to the coding challenge.

You are taking a spontaneous trip to a European city and want to find out a bit about it before you go. Being a rather nerdy type, you want to create an API that can be used to pull together multiple sources of information about a city.

This repository is the start of making that API. The API uses the python Tornado web framework (the version is in the requirements.txt file and can be installed with pip) to expose an api that allows you to request information about a city.

The minimum data points that you want the API to return about a city are:

  • Current temperature in celsius.
  • A text description of the current weather
  • The population of the city
  • The number of bars in the city
  • The quality of the public transport in the city

There is no limit to the amount of information that you can collect, but there are basic tests that check for the minimum data listed above.

You also want to develop a method of ranking cities. To do this, you need to create a unique 'city score' per city based on information of your choosing. There are no restrictions on how you decide to score a city, but given that you are planning on travelling to the city today, the current weather needs to be taken into account.

There is an accompanying csv file (details below) with other city data that can be used to assist you in creating the city score. Each city score should be out of 10, and multiple cities should be comparable with a single call to the API.

Instructions

Clone this repository and then create your own new repository for your code changes. Bitbucket have a free tier in case you don't already have an account on a GIT host. Once complete, please send a link to your repository to [email protected].

To get started on the coding, install Tornado via Pip and run the tests in 'test_location_handler.py' to exercise the code. You can also run the API by running the 'location_api.py' file.

There are two routes that need to be completed which can be found in files:

  • /app/location/_data/_handler.py
  • /app/location/_comparison_handler.py

In both cases you must complete the GET route. In tornado this is achieved by completing the get() function and returning data as shown in the initial version of the get() functions.

The location_data_handler get() function expects a city name to be passed into the URL and returns data about that city.

The location_comparison_handler route expects a list of cities to be passed in and returns the city score and rank for that city. E.g. if five cities are passed in, it will calculate the city score for each city and the rank of each city compared to the other cities that were passed in.

If running the server locally, sample valid routes are:

There are sample test in /tests/test_location_handler.py file that exercise the calls to the GET routes. Currently, these tests do not all pass, or pass because dummy data is returned from the routes. The objective of this exercise is not to make the tests pass, but to complete the APIs so that they return accurate and relevant data and allow you to make the right decision on what city to visit.

Please structure and write code as if it is to be used in a production environment, or clearly document changes you would make before putting the code into production. Use Python 3.5+.

Useful Data Sources

Feel free to use whatever data sources you see fit, but here are some sample ones:

Meta weather API for real-time weather information: https://www.metaweather.com/api/

There is a CSV file in the 'data' directory that contains sample information about 500 European cities. In this file, the cities are ranked by population and there are various other details about each city. Aside from the population, all other columns contain random data. The columns in this file are:

  • Index: The numeric index for each row/city
  • City: The city name
  • Country: The country the city is in
  • Population: The population of the city within city limits
  • Bars: Number of bars within the city limits
  • Museums: Number of museums within the city limits
  • Public Transport: Public transport rating out of 10 (10 being the best service)
  • Crime Rate: Crime rate out of 10 (10 being highest rate of crime)
  • Average Hotel Room Price: The average price in Euros of a hotel room per night

List of other open APIs that can be used to retrieve data: https://github.com/toddmotto/public-apis#weather

Notes

  • I was using Python 3.7. The most distinct feature is async/await keywords which are properly supported since Python3.5+ as far as I remember
  • I changed the way unit tests are performing queries since there is a known issue about @gen_test not working well together with AsyncHTTPTestCase.fetch
  • I deduplicated application configured in location_api.py and test_location_handlers.py so the tests are guaranteed to run against the same URL mapping and the same application.
  • I decided not to use database so the code could be executed and runned without additional efforts. I might have used SQLite, but then I would need to manage DB schema. To simplify solution I decided not to use it. However in real world, if we would expect the data growth - I would consider replacing in-memory data with a database.

location-code-test's People

Watchers

 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.