Skip to content

Conversation

@BChaitanyaReddy895
Copy link

@BChaitanyaReddy895 BChaitanyaReddy895 commented Jul 23, 2025

Title: Fixes the issue #8 of adding insightful and decision making profitability forecast charts using plotly
Description:
This pull request introduces a new crop economics visualization module to the KrishiMitra Streamlit app, enabling farmers to compare profitability across crops using interactive Plotly bar charts. Additionally, it updates the crop_economics.json file by adding 10 new crops to enhance the dataset for economic analysis. The changes aim to provide farmers with actionable insights into crop profitability, factoring in realistic cost and yield variations.
Changes Made:
New Crop Economics Visualization Module:
Added a new section titled "Crop Economics Analysis" to the Streamlit app, placed after the "Mandi Prices" section.
Implemented functionality to load crop data from crop_economics.json using a load_crop_data function with robust error handling.
Enhanced economic calculations in the calculate_economics function to include:
Input costs: Seed, fertilizer, labor, irrigation, and pest control.
Yield variability (±10%) to simulate real-world fluctuations.
Market price fluctuation (±5%) to account for market volatility.
Profit margin calculation (Profit/Income * 100).
Added interactive visualizations using Plotly:
A single bar chart comparing profits across crops (using plotly.express) .
An optional grouped bar chart (toggled via checkbox) comparing input cost, income, and profit (using plotly.graph_objects) for detailed decision making skills for the selection of crops based on profit might be obtained in the future by performing various complex calculations with accurate results for the benefit of farmers.
Text labels on bars for exact values and a clean white theme for readability.
Displayed additional metrics: highest profit crop and highest profit margin crop.
Added new dependencies: plotly, json, and random to the imports.
Updated crop_economics.json:
Expanded the dataset from 5 crops (wheat, rice, maize, potato, mustard) to 15 crops by adding:
Sugarcane, tomato, soybean, cotton, barley, chana (chickpea), groundnut, bajra (pearl millet), moong dal (green gram), and onion.
Ensured all crops include required fields: seed_cost, fertilizer, labor_cost, irrigation_cost, pest_control_cost, yield, and market_price.
Values are based on typical Indian agricultural data (costs in ₹/hectare, yields in quintals/hectare, market prices in ₹/quintal, except sugarcane yield which is higher).

Code Integration:
Integrated the new module into the existing Streamlit app without modifying other sections (chatbot, fertilizer recommendation, loan/subsidy checker, etc.).
Ensured the module dynamically handles any number of crops in the JSON file.

Purpose:
The crop economics visualization module helps farmers make informed decisions by comparing profitability across 15 crops, accounting for realistic factors like irrigation, pest control, yield variability, and market price fluctuations. The expanded dataset ensures a broader range of crops relevant to Indian farmers, enhancing the app's utility.

Testing Instructions
Setup:
Ensure dependencies are installed: pip install streamlit pandas gtts openai plotly.
Place the updated crop_economics.json in the same directory as the Streamlit script.
Update the background image path in set_bg_local to a valid local image file as of now i have downloaded image from the google and updated the path. You can replace it with the your file path.
Run the App:
Execute: streamlit run farmer.py.

Verify Changes:
Navigate to the "Crop Economics Analysis" section in the app.
Confirm the data table displays all 15 crops with columns: Crop, Input Cost, Income, Profit, Profit Margin (%), Adjusted Yield, Adjusted Price.
Check the "Profit Comparison Across Crops" bar chart shows profits for all 15 crops with correct labels (e.g., ₹ values).
Enable the "Show Grouped Bar Chart" checkbox and verify the grouped bar chart compares input cost, income, and profit for all crops.
Validate the "Additional Metrics" section correctly identifies the highest profit and profit margin crops.
Ensure no errors occur when loading crop_economics.json (test with a missing file to verify error handling).
Confirm existing app features (chatbot, weather alerts, etc.) remain unaffected.

Related Issues
None (this is a new feature request).
Checklist
Code follows project style guidelines.
Tested locally with all 15 crops displayed correctly.
Visualizations render without errors in Streamlit.
JSON file is valid and correctly formatted.
No impact on existing functionality.
Ready for review.

Screenshots:
Screenshot 2025-07-23 144606
Screenshot 2025-07-23 144623
Screenshot 2025-07-23 144644
Screenshot 2025-07-23 144243
Insights: In the visualizations i had implemented enhances the decision making skills in farmers of selecting the crop that yields more profit by considering all the parameters of the input costs and also provided for each visualization might be in table format or via bar charts, one can easily understand the situation and provided with the functionality to each visualization such that they can download the visualizations. This helps the farmers a lot who are of unable gain the insights textually and they can easily understand the profitability of each crop. This feature enhances this application making a robust application.
I hope this solution resolves this issue and could you please mention the level as 2 or 3 for this issue as a part of GSSOC 25. Thank you once again for trusting me and providing me an opportunity for contributing myself to the development of farmers

@BChaitanyaReddy895
Copy link
Author

@Ansikka please review the changes since i made these changes 7 days ago and could you please merge the changes after reviewing since i had worked a lot on resolving this issue and it would be better if you label this issue/pull request as level 3 for GSSOC since i had worked for complete one day for resolving this issue. Thank you

@BChaitanyaReddy895
Copy link
Author

@Ansikka also try to add the GSSOC tag as well with the levels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant