Skip to content

t-satwik/crop-disease-detection-app-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crop-Disease-Detection-App

Backend Repo

Setup

  1. Download the Repository to your local machine
  2. Create a Virtual Environment in the crop-disease-detection-app-backend folder with this command below
    python -m venv venv
  3. Activate the environment with this command
    .\venv\Scripts\activate
  4. Install the dependencies (like Django, Django-Rest-FrameWork)
    pip install -r requirements.txt

Running the Application

  1. Activate the environment with this command.
    .\venv\Scripts\activate
  2. Start the application by running this command (Run the command where manage.py is located) or cd crop_disease_detection_app
  3. python manage.py runserver

Accessing the Admin Panel

  1. You can access the admin panel by running the server and opening http://localhost:8000/admin
  2. Run python manage.py createsuperuser to create a user to access the admin panel.
  3. Set up the Username and Password
  4. You can log in and change the database values anytime.

Testing the Admin Panel

AN instance of this server is running on a machin at IIT Dharwad, and it can be accessed by using the URl: http://farmbook.iitdh.ac.in

API References

  1. apis/Login/
  2. apis/SignUp/
  3. apis/SetData/
  4. apis/GetPastData/
  5. apis/GetSensorValueData/
  6. apis/SetVideoFrame/
  7. apis/SetSensorData/
  8. apis/GetCropRecommendation/
  9. apis/GetCropRecommendationWithGivenData/

APIs Descriptions

apis/Login/

This Api is used to validate the credentials entered by a user.

How to Use?

Send a POST request to apis/login/

Associated View:

checkLogin

Request_Body:

{
  "user_name":"user1"
  "password":"123"
}

Response

{
  "message":"User Verified"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK User Verified
401 UNAUTHORIZED Wrong Password
401 UNAUTHORIZED Enter Password
404 NOT FOUND User not found
400 NOT FOUND Bad Request

apis/SignUp/

This Api is used to create a new user with the given details.

How to Use?

Send a POST request to apis/SignUp/

Associated View:

newSignup

Request_Body:

{
  "user_name":"user1",
  "email":"[email protected]",
  "password":"123"
}

Response

{
  "message":"User Created"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK User Created
400 NOT FOUND Bad Request

apis/SetData/

This Api is used to create a new data object corresponding to the location data and the image.

How to Use?

Send a POST request to apis/SetData/

Associated View:

setData

Request_Body:

{
  "time_stamp":"08/04/2022 16:28:24",
  "latitude":"0.0",
  "longitude":"0.0",
  "probability":"0.95",
  "predicted_class":"healthy",
  "crop_name":"maize",
  "user_name":"user1",
  "image":"image file"
}

Response

{
  "message":"Data Object Created"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Data Object Created
404 NOT FOUND Predicted class not foundd
404 NOT FOUND Crop not found
404 NOT FOUND User not found
400 NOT FOUND Bad Request - python Exception

apis/GetPastData/

This Api is used to get the data and the images associated with a user.

How to Use?

Send a POST request to apis/GetPastData/

Associated View:

getPastData

Request_Body:

{
  "user_name":"user1",
  "starting_index":"0"
}

Response

{
  "message":"Data Fetch Successful",
  "data0":{
    "time_stamp":"08/04/2022 16:19:27",
    "latitude":"0.0" ,
    "longitude":"0.0" ,
    "predicted_class":"healthy" ,
    "probability":"0.95",
    "user":"user1",
    "crop_type":"maize",
    "file_name":"user1_maize_08-04-2022_16-19-27.png",
  }
  "max_index":0

}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Data Fetch Successful
400 NOT FOUND Bad Request - python Exception

apis/GetSensorValueData/

This Api is used to get the sensor values associated to a user.

How to Use?

Send a POST request to apis/GetSensorValueData/

Associated View:

getSensorValuesData

Request_Body:

{
 "user_name":"user1"
}

Response

{
  "message":"Sensors Data Fetch Successful",
  "total_count":1,
  "sensor_type":"humidity",
  "latitude":"0.0",
  "longitude":"0.0",
  "user":"user1",
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Sensors Data Fetch Successful
400 NOT FOUND Bad Request - python Exception

apis/SetVideoFrame/

This Api is used to create a video frame object to store in the database.

How to Use?

Send a POST request to apis/SetVideoFrame/

Associated View:

setVideoFrame

Request_Body:

{
  "time_stamp":"08/04/2022 16:28:24",
  "start_latitude":"0.0",
  "end_latitude":"0.0",
  "start_latitude":"0.0",
  "end_longitude":"0.0",
  "probability":"0.95",
  "predicted_class":"healthy",
  "crop_name":"maize",
  "user_name":"user1",
  "image":"image file",
}

Response

{
  "message":"Data Object Created"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Data Object Created
404 NOT FOUND Predicted class not foundd
404 NOT FOUND Crop not found
404 NOT FOUND User not found
400 NOT FOUND Bad Request - python Exception

apis/setSensorData/

This Api is used to create a sensor value object to store in the database.

How to Use?

Send a POST request to apis/setSensorData/

Associated View:

setSensorData

Request_Body:

{
  "time_stamp":"08/04/2022 16:28:24",
  "latitude":"0.0",
  "longitude":"0.0",
  "sensor_type":"humidity",
  "value":"100.00"
}

Response

{
  "message":"Value Added to the sensor"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Value Added to the sensor
200 OK New sensor added and appended value
404 NOT FOUND Predicted class not foundd
404 NOT FOUND sensor type not found
404 NOT FOUND user not found
400 NOT FOUND Bad Request

apis/GetCropRecommendation/

This Api is used to give a recommendation based on the existing data in the database.

How to Use?

Send a POST request to apis/GetCropRecommendation/

Associated View:

getCropRecommendation

Request_Body:

{
  "latitude":"0.0",
  "longitude":"0.0",
  "user_name":"user1",
}

Response

{
  "message":"Data present",
  "full_data":1,
  "predicted_crop":"maize"

}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Data present
200 OK Data not present
400 NOT FOUND Bad Request - python Exception

apis/GetCropRecommendationWithGivenData/

This Api is used to give a recommendation based on the given data in the request.

How to Use?

Send a POST request to apis/GetCropRecommendationWithGivenData/

Associated View:

GetCropRecommendationWithGivenData

Request_Body:

{
  "latitude":"0.0",
  "longitude":"0.0",
  "user_name":"user1",
  "nitrogen":"0.5",
  "phosphorus":"0.5",
  "potassium":"0.5",
  "pH":"7",
  "temperature":"40",
  "humidity":"40"
}

Response

{
  "message":"Crop recommended successfully",
  "full_data":1,
  "predicted_crop":"maize"
}

Status Codes

The possible responses for this api request are as follows

Status Codes Possible Messages
200 OK Crop recommended successfully
400 NOT FOUND Bad Request - python Exception

About

Django backend code for crop disease detection app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published