Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-113
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-113
2023-113
Commits
c8cc3752
Commit
c8cc3752
authored
May 25, 2023
by
di-nethra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flask backed added
parent
a4f7f641
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
2422 additions
and
1 deletion
+2422
-1
Soil Analyzer and Optimized Crop Finder - IT20233808/.DS_Store
...Analyzer and Optimized Crop Finder - IT20233808/.DS_Store
+0
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/RP-MobileAPP-FE/components/common/Home.js
...er - IT20233808/RP-MobileAPP-FE/components/common/Home.js
+2
-1
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/.DS_Store
...ized Crop Finder - IT20233808/soil-component-BE/.DS_Store
+0
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/.vscode/launch.json
...Finder - IT20233808/soil-component-BE/.vscode/launch.json
+16
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/__pycache__/app.cpython-311.pyc
...0233808/soil-component-BE/__pycache__/app.cpython-311.pyc
+0
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/app.py
...timized Crop Finder - IT20233808/soil-component-BE/app.py
+105
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/crop_data.csv
... Crop Finder - IT20233808/soil-component-BE/crop_data.csv
+64
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_crop.csv
... Crop Finder - IT20233808/soil-component-BE/soil_crop.csv
+2201
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_crop_model.joblib
...der - IT20233808/soil-component-BE/soil_crop_model.joblib
+0
-0
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_randomForest.py
...inder - IT20233808/soil-component-BE/soil_randomForest.py
+34
-0
No files found.
Soil Analyzer and Optimized Crop Finder - IT20233808/.DS_Store
View file @
c8cc3752
No preview for this file type
Soil Analyzer and Optimized Crop Finder - IT20233808/RP-MobileAPP-FE/components/common/Home.js
View file @
c8cc3752
...
...
@@ -2,8 +2,9 @@ import React from 'react';
import
{
View
,
Text
,
TouchableOpacity
,
StyleSheet
,
ImageBackground
}
from
'
react-native
'
;
const
HomePage
=
({
navigation
})
=>
{
const
handleOptionSelect
=
(
option
)
=>
{
// Handle navigation to the selected option
if
(
option
===
'
pestDisease
'
)
{
navigation
.
navigate
(
'
PestDiseasePage
'
);
}
else
if
(
option
===
'
soilData
'
)
{
...
...
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/.DS_Store
0 → 100644
View file @
c8cc3752
File added
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/.vscode/launch.json
0 → 100644
View file @
c8cc3752
{
//
Use
IntelliSense
to
learn
about
possible
attributes.
//
Hover
to
view
descriptions
of
existing
attributes.
//
For
more
information
,
visit:
https://go.microsoft.com/fwlink/?linkid=
830387
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"name"
:
"Python: Current File"
,
"type"
:
"python"
,
"request"
:
"launch"
,
"program"
:
"${file}"
,
"console"
:
"integratedTerminal"
,
"justMyCode"
:
true
}
]
}
\ No newline at end of file
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/__pycache__/app.cpython-311.pyc
0 → 100644
View file @
c8cc3752
File added
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/app.py
0 → 100644
View file @
c8cc3752
from
flask
import
Flask
,
request
,
jsonify
import
csv
app
=
Flask
(
__name__
)
class
Crop
:
def
__init__
(
self
,
name
,
nutrient_requirements
):
self
.
name
=
name
self
.
nutrient_requirements
=
nutrient_requirements
# Function to calculate the suitability score for a crop
def
calculate_suitability_score
(
crop
,
user_soil_nutrients
,
optimization_criteria
):
score
=
0
for
nutrient
in
user_soil_nutrients
:
nutrient_value
=
user_soil_nutrients
[
nutrient
]
required_value
=
crop
.
nutrient_requirements
.
get
(
nutrient
,
0
)
weight
=
optimization_criteria
[
nutrient
]
difference
=
abs
(
nutrient_value
-
required_value
)
if
required_value
==
0
:
if
difference
==
0
:
suitability
=
100.0
else
:
suitability
=
0.0
else
:
suitability
=
(
1
-
difference
/
required_value
)
*
100.0
weighted_suitability
=
suitability
*
weight
score
+=
weighted_suitability
return
score
def
convert_user_soil_nutrients
(
user_soil_nutrients
):
return
', '
.
join
(
f
"{key}: {value}"
for
key
,
value
in
user_soil_nutrients
.
items
())
def
append_crop_data
(
top_crops
,
user_soil_nutrients
,
optimization_criteria
):
field_names
=
[
'Crop Name'
,
'N'
,
'P'
,
'K'
]
csv_file_path
=
'crop_data.csv'
with
open
(
csv_file_path
,
mode
=
'a'
,
newline
=
''
)
as
file
:
writer
=
csv
.
DictWriter
(
file
,
fieldnames
=
field_names
)
is_file_empty
=
file
.
tell
()
==
0
if
is_file_empty
:
writer
.
writeheader
()
user_soil_nutrients_str
=
convert_user_soil_nutrients
(
user_soil_nutrients
)
for
crop
in
top_crops
:
crop_obj
=
Crop
(
crop
,
{})
crop_data
=
{
'Crop Name'
:
crop
,
'N'
:
user_soil_nutrients
.
get
(
'N'
,
0
),
'P'
:
user_soil_nutrients
.
get
(
'P'
,
0
),
'K'
:
user_soil_nutrients
.
get
(
'K'
,
0
)
}
writer
.
writerow
(
crop_data
)
@
app
.
route
(
'/npk-data'
,
methods
=
[
'POST'
])
def
receive_npk_data
():
npk_data
=
request
.
get_json
()
user_soil_nutrients
=
npk_data
crops
=
[
Crop
(
"Soybean"
,
{
'N'
:
0.4
,
'P'
:
0.3
,
'K'
:
0.4
}),
Crop
(
"Barley"
,
{
'N'
:
0.5
,
'P'
:
0.4
,
'K'
:
0.5
}),
Crop
(
"Wheat"
,
{
'N'
:
0.7
,
'P'
:
0.4
,
'K'
:
0.6
}),
Crop
(
"Rice"
,
{
'N'
:
0.1
,
'P'
:
0.2
,
'K'
:
0.1
}),
Crop
(
"Maize"
,
{
'N'
:
0.6
,
'P'
:
0.4
,
'K'
:
0.5
}),
Crop
(
"Potato"
,
{
'N'
:
0.3
,
'P'
:
0.4
,
'K'
:
0.5
}),
Crop
(
"Tomato"
,
{
'N'
:
0.6
,
'P'
:
0.6
,
'K'
:
0.6
}),
Crop
(
"Cotton"
,
{
'N'
:
0.6
,
'P'
:
0.4
,
'K'
:
0.6
})
]
optimization_criteria
=
{
'N'
:
1
,
'P'
:
1
,
'K'
:
1
}
crop_scores
=
[]
for
crop
in
crops
:
suitability_score
=
calculate_suitability_score
(
crop
,
user_soil_nutrients
,
optimization_criteria
)
crop_scores
.
append
((
crop
,
suitability_score
))
crop_scores
.
sort
(
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)
top_three_crops
=
[]
for
crop
,
score
in
sorted
(
crop_scores
[:
3
],
key
=
lambda
x
:
x
[
1
],
reverse
=
True
):
top_three_crops
.
append
(
crop
.
name
)
append_crop_data
(
top_three_crops
,
user_soil_nutrients
,
optimization_criteria
)
response_data
=
{
'top_crops'
:
top_three_crops
,
'highest_score'
:
crop_scores
[
0
][
1
]
}
return
jsonify
(
response_data
)
if
__name__
==
'__main__'
:
app
.
run
()
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/crop_data.csv
0 → 100644
View file @
c8cc3752
Crop Name,N,P,K
Wheat,0.8,0.5,0.9
Tomato,0.8,0.5,0.9
Cotton,0.8,0.5,0.9
Soybean,0.2,0.1,0.3
Potato,0.2,0.1,0.3
Barley,0.2,0.1,0.3
Wheat,4.46,0.5,5.04
Tomato,4.46,0.5,5.04
Cotton,4.46,0.5,5.04
Wheat,4.46,0.5,5.04
Tomato,4.46,0.5,5.04
Cotton,4.46,0.5,5.04
Wheat,4.46,0.5,5.04
Tomato,4.46,0.5,5.04
Cotton,4.46,0.5,5.04
Wheat,4.46,0.5,5.04
Tomato,4.46,0.5,5.04
Cotton,4.46,0.5,5.04
Potato,0.3,0.2,0.5
Soybean,0.3,0.2,0.5
Barley,0.3,0.2,0.5
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Soybean,0,0,0
Barley,0,0,0
Wheat,0,0,0
Wheat,4.52,0.29,5.19
Cotton,4.52,0.29,5.19
Tomato,4.52,0.29,5.19
Wheat,4.57,0.11,5.33
Cotton,4.57,0.11,5.33
Tomato,4.57,0.11,5.33
Tomato,0,0.52,9.48
Wheat,0,0.52,9.48
Cotton,0,0.52,9.48
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Wheat,4.52,0.11,5.38
Cotton,4.52,0.11,5.38
Tomato,4.52,0.11,5.38
Soybean,0.5,0.3,0.2
Barley,0.5,0.3,0.2
Maize,0.5,0.3,0.2
Potato,0.3,0.5,0.2
Barley,0.3,0.5,0.2
Tomato,0.3,0.5,0.2
Potato,0.3,0.5,0.2
Barley,0.3,0.5,0.2
Tomato,0.3,0.5,0.2
Wheat,4.47,0.29,5.24
Cotton,4.47,0.29,5.24
Tomato,4.47,0.29,5.24
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_crop.csv
0 → 100644
View file @
c8cc3752
This diff is collapsed.
Click to expand it.
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_crop_model.joblib
0 → 100644
View file @
c8cc3752
File added
Soil Analyzer and Optimized Crop Finder - IT20233808/soil-component-BE/soil_randomForest.py
0 → 100644
View file @
c8cc3752
from
flask
import
Flask
,
request
,
jsonify
import
joblib
import
pandas
as
pd
from
sklearn.metrics
import
accuracy_score
model
=
joblib
.
load
(
'./soil_crop_model.joblib'
)
eval_data
=
pd
.
read_csv
(
'soil_crop.csv'
)
eval_X
=
eval_data
[[
'nitrogen'
,
'phosphorus'
,
'potassium'
]]
eval_y
=
eval_data
[
'crop'
]
predicted_labels
=
model
.
predict
(
eval_X
)
accuracy
=
accuracy_score
(
eval_y
,
predicted_labels
)
app
=
Flask
(
__name__
)
@
app
.
route
(
'/predict'
,
methods
=
[
'POST'
])
def
predict
():
input_data
=
request
.
get_json
()
nitrogen
=
input_data
[
'N'
]
phosphorus
=
input_data
[
'P'
]
potassium
=
input_data
[
'K'
]
predicted_crop
=
model
.
predict
([[
nitrogen
,
phosphorus
,
potassium
]])
response
=
{
'crop'
:
predicted_crop
[
0
],
'accuracy'
:
accuracy
}
return
jsonify
(
response
)
if
__name__
==
'__main__'
:
app
.
run
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment