Challenge Overview
Challenge Objectives
-
Python Rest API development using Flask framework - refactor existing codebase
NOTE: The review/appeals timeline is shorter than usual - pay attention to the deadlines
Project Background
-
Our client has developed a specific method of calculating CEC and Eff from minerals weight percentage data
-
All the calculations are currently in an Excel workbook - our goal is to create an API to process the data, i.e. move the calculations from Excel into the codebase.
-
In this challenge, we’ll refactor the api endpoints and remove all database related features
Technology Stack
-
Python 3
-
Flask
-
Flask-Restplus
Code access
The base code is available in the forums.
Individual requirements
-
1. Remove all database related features
Goal here is to make the calculations backend stateles, ie remove all the db related features - importing data, optimization, searching, etc. Minerals catalogue should also be removed. Remove all the db models and all api endpoints except two endpoints:-
POST /calculation endpoint (that is the current POST /data endpoint) that takes the input parameters, calculates and returns both the inputs and outputs. Rename the “startingMineralDensities” parameter to “mineralDensities”. Inputs should also contain the minerals catalogue (since we can’t load them from the database). Output should contain the results of steps “six” and “totals” - ie, the output of the current DataCalculateGrainClay and DataFetchTotals endpoints. All other endpoints/calculations/charts/csv/xlsx imports/exports can be removed. Update RestPlus models and test suite.
-
POST /optimize endpoint that takes all the parameters as the calculation endpoint, plus the optimization type (“objective” parameter), runs the optimization and returns the final mineral densities
-
-
2. Add logging
Configure app logger to print all the logging output to stdout. Log level should be configurable via environment variable <API_NAME>_LOG_LEVEL. All requests (method, url, query params) and responses (response code) should be logged with INFO level. Use WARN and ERROR levels to log unusual scenarios (ex empty array that doesn’t break the rest of the calculations) or error cases (division by zero, our of range, etc) respectively. Log the request and response body with DEBUG level and log all the calculations (ex steps, loops, etc) with TRACE level.
General requirements
-
Unit tests are required for all endpoints.
-
All endpoints should be annotated with Swagger annotations and swagger UI should be served by the API.
-
All endpoint routes should be prefixed with “API_NAME_”
-
All configuration parameters should be extracted to a common settings module. All environment variables have to be prefixed with “API_NAME_”
-
Please make sure your code is well-documented. Use the following style guides Google Python Style Guide, Python Style Guide, and Docstring Conventions. Code linter is required. Please make sure it is well-engineered but not over-engineered (YAGNI and KISS) solution. We're looking for well-structured and tested code. Well-structured code follows good design principles like the SOLID principles and well-tested code has comprehensive unit tests.
-
The code should be implemented using Python3 only.
-
Use matrix operations with numpy/pandas where possible
What To Submit
-
All source code
-
Deployment guide
-
Postman collection containing sample calls for all endpoints (success/failure)
-
Verification guide - how to set up the environment, start the API, and verification screenshots
-
The unit tests coverage report