Description
Data Service for World Bank Economic Indicators
For this assignment we are interested in annual values of a user specified indicator from 2013 to 2018 for one or all countries. The content of the file is quite straightforward. The data service specification will ask you to ‘import’ this data into a ‘data storage’.
You should inspect the content of the file carefully and decide on a data model and storage method. You will find that a JSON format is suitable to accessing data and publishing it. The database we used in this assignment is SQLite .
You need to determine the way about how to store the data. We don’t care about your storage format as long as your data is correct and reasonable stored instead of hard-code. The way you used to handle the space, we don’t care just make a notice on your swagger page. Please download the python code template a2.py.
Don’t change the function signature “create_db” which you need to use it to create the database. All the other function, it’s flexible. Also, no auto-test will be provided. Note: You may need some additional key in the record for storage purpose. Don’t send too much requests to the source API as it will ban your IP address, be careful. Please make sure your have a swaggerUI page on you API.
How to create database in SQLite: http://www.sqlitetutorial.net/sqlite-python/creating-database/ (http://www.sqlitetutorial.net/sqlite-python/creating-database/) Assignment Specification The data service should use JSON format to publish its data and implement following operations. 1- Import a collection from the data service This operation can be considered as an on-demand ‘import’ operation. The service will download the JSON data for all countries (http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD? date=2012:2017&format=json) respective to the year 2013 to 2018 and identified by the indicator id given by the user and process the content into an internal data format.
Parameters should be given to the endpoint (in the payload) by the user: indicator_id : an indicator (http://api.worldbank.org/v2/indicators) http://api.worldbank.org/v2/indicators (http://api.worldbank.org/v2/indicators) After importing the collection, the service should return a response containing at least the following information: location : the URL with which the imported collection can be retrieved collection_id : a unique identifier automatically generated creation_time : the time the collection stored in the database Specification Make Submission Check Submission Collect Submission 2019/6/4 Data Service for World Bank Economic Indicators |
Example: HTTP operation: POST / Input Payload: { “indicator_id” : “NY.GDP.MKTP.CD” } Returns: 201 Created { “location” : “//”, “collection_id” : “”, “creation_time”: “2019-03-09T12:06:11Z”, “indicator” : “” } The return response contains the location of the data entry created as the result of the processing the import. You should return appropriate responses in case of invalid indicators or any invalid attempts to use the endpoint ( e.g. If the input indicator id doesn’t exist in the data source, return error 404 ) If an input contains a n indicator that already has been imported before, you should still return the location of the data entry – but with status code 200 OK (instead of 20 1 Created). A POINT TO PONDER ABOUT: An `asynchronous POST’?? If a POST takes too long, you may not want the client to wait. What you would do? You do not need to address this in the assignment.
The source API has pagination; in order to get all of data you need to send many request to import a single collection; however, you are required to get only first two pages instead of all: http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD? date=2013:2018&format=json&page=2 (http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD? date=2013:2018&format=json&page=2) The data entries inside the collection must be converted as described below: Data entry conversion: Here is an example of source data entry as it is in the source API (http://api.worldbank.org/v2/countries/all/indicators/NY.GDP.MKTP.CD?date=2013:2018&format=json) : { “indicator”: { “id”: “NY.GDP.MKTP.CD”, “value”: “GDP (current US$)” }, “country”: { “id”: “1A”, “value”: “Arab World” }, “countryiso3code”: “”, “date”: “2016”, “value”: 2513935702899.65, “unit”: “”, “obs_status”: “”, “decimal”: 0 } 2019/6/4 Data Service for World Bank Economic Indicators |
However, you do not need to store all of its attributes; instead convert it to a JSON format as below: { “country”: “Arab World”, “date”: “2016”, “value”: 2513935702899.65 } And as a result a collection should be formatted and stored in the database as follow: 2- Deleting a collection with the data service This operation deletes an existing collection from the database. The interface should look like as below: HTTP operation: DELETE //{collection_id} Returns: 200 OK { “message” :”Collection = is removed from the database!” }
3 – Retrieve the list of available collections This operation retrieves all available collections. The interface should look like as like below: HTTP operation: GET / Returns: 200 OK { “collection_id” : “”, “indicator”: “NY.GDP.MKTP.CD”, “indicator_value”: “GDP (current US$)”, “creation_time” : “” “entries” : [ { “country”: “Arab World”, “date”: “2016”, “value”: 2513935702899.65 }, … { “country”: “Caribbean small states”, “date”: “2017”, “value”: 68823642409.7 … ] } 2019/6/4 Data Service for World Bank Economic Indicators |
[ “location” : “//”, “collection_id” : “collection_id_1”, “creation_time”: “