rahuljauhari3 / onbo-backend-intenship-assignment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Climate Data POC

This is a proof-of-concept (POC) project for managing and retrieving climate data. The project provides RESTful API endpoints for saving climate data, fetching records, and calculating climate change metrics.

Getting Started

Follow these instructions to set up and run the project locally.

Prerequisites

  • Python 3.x
  • Flask
  • Flask-SQLAlchemy

You can install the required Python packages using pip:

pip install Flask Flask-SQLAlchemy

This files contains the complete implementation of the climate data POC using Flask and SQLite with proper thread safety using flask_sqlalchemy. This code includes all the required endpoints and database operations:

  1. First install the required libraries:

    • pip install Flask Flask-SQLAlchemy
  2. Create app.py Python file

  3. Create seed_data.py Python file

Initialize the SQLite database and insert sample data:

python seed_data.py
  1. Run the Flask application (app.py) to start the API server
python app.py

The application will be running at http://127.0.0.1:5000.

API Endpoints

Save Climate Data

URL: /save_data Method: POST
To send data to this endpoint, you can use a tool like curl or Postman, or you can integrate it into your frontend application as needed. Here's an example curl request:

curl -X POST -H "Content-Type: application/json" -d '{
  "climate":"hot",
  "area_code": 555,
  "temperature": 30,
  "humidity": 70,
  "chances_of_rain": 50
}' http://localhost:5000/send_data

Fetch All Records

URL: /fetch_all_records Method: GET Response: JSON response containing all climate data records

Fetch Records by Area Code

URL: /fetch_records_by_area/<area_code> Method: GET Response: JSON response containing climate data records for the specified area code

Fetch Records by Climate

URL: /fetch_records_by_climate/<climate> Method: GET Response: JSON response containing climate data records for the specified climate

Calculate Climate Change Metrics

URL: /calculate_metrics Method: POST Payload: JSON payload containing climate data including from_climate, to_climate, and area_code
To test this endpoint, you can use a tool like curl or Postman, or you can integrate it into your frontend application. Here's an example curl request:

curl -X POST -H "Content-Type: application/json" -d '{
  "from_climate":"hot",
  "to_climate":"cold",
  "area_code": 555
}' http://localhost:5000/calculate_metrics

Authors

Rahul Jauhari

About


Languages

Language:Python 100.0%