How rahuldkjain/crop_prediction works
Project type and purpose
• This is a full-stack web application built with Python and Flask.
File structure
• Entry point: app.py (Flask server routes, HTTP handlers).
• Business-logic / Model code: crops.py (loads CSV datasets in static/*.csv, trains or loads Decision-Tree regression models, produces predictions).
• Static assets:
• static/*.csv (time-series data per crop, rainfall, WPI)
• CSS/JS: MaterializeCSS + Chart.js included via templates.
• Templates:
• templates/index.html (home page, form input for crop selection/time window)
• templates/commodity.html (detailed crop pages)
• templates/export (probably CSV/JSON export endpoints).
• Dependencies: requirements.txt (Flask, scikit-learn, pandas, numpy).
Extract insights from the README
• Highlights Decision-Tree Regression with ~93–95% accuracy.
• Frontend uses MaterializeCSS (layout/components) and Chart.js (data visualization).
• Data source: data.gov.in (rainfall, WPI, crop pricing).
• Usage flow: user selects crop → server loads data/model → returns forecast → client renders table/chart.
Main components & interactions
a. Frontend (Browser)
• UI pages built with MaterializeCSS templates & Chart.js charts.
• Sends HTTP GET/POST to Flask endpoints.
b. Web Server (Flask app.py)
• Routing layer: receives requests (e.g., “/predict?crop=Maize”), calls controller functions.
• Renders templates with data or returns JSON for Chart.js.
c. Prediction Engine (crops.py)
• Data Loader: reads required CSV(s) from static/.
• Model Trainer/Loader: trains Decision-Tree Regressor or loads pre-trained model in memory.
• Prediction Logic: computes next-12-month forecasts, top gainers/losers.
d. Data Storage
• Flat files (.csv in static/).
• (Optional) In-memory caches or pickled models.
e. External Libraries
• scikit-learn (modeling), pandas/numpy (data manipulation), Chart.js (frontend charts), MaterializeCSS (UI).
Architectural patterns & design principles
• MVC-like separation:
• Model = crops.py data+prediction logic
• View = Jinja2 HTML templates + embedded JS
• Controller = Flask routes in app.py
• Single-process, synchronous request handling (simple Flask server).
• Static assets served directly by Flask’s static folder.
• Data-driven design: each crop CSV provides a consistent schema.