diff --git a/frontend/src/components/Applications/ApplicationViewModal.js b/frontend/src/components/Applications/ApplicationViewModal.js index 670d9e3..b3e2752 100644 --- a/frontend/src/components/Applications/ApplicationViewModal.js +++ b/frontend/src/components/Applications/ApplicationViewModal.js @@ -9,6 +9,41 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => { const [planDetails, setPlanDetails] = useState(null); const [loading, setLoading] = useState(true); + // Calculate coverage percentage based on GPS tracking and equipment specifications + const calculateCoverage = (application, log) => { + if (!log?.gpsTrack?.points || log.gpsTrack.points.length < 2) { + return 0; // No movement = no coverage + } + + const totalDistance = log.gpsTrack.totalDistance || 0; + const plannedArea = application.totalSectionArea || 0; + + if (totalDistance === 0 || plannedArea === 0) { + return 0; + } + + // Estimate equipment width based on type + let equipmentWidth = 4; // Default 4 feet for unknown equipment + + const equipmentName = application.equipmentName?.toLowerCase() || ''; + if (equipmentName.includes('spreader')) { + equipmentWidth = 12; // Spreaders typically 8-16 feet wide + } else if (equipmentName.includes('sprayer')) { + equipmentWidth = 20; // Sprayers typically 15-30 feet wide + } else if (equipmentName.includes('mower')) { + equipmentWidth = 6; // Mowers typically 4-8 feet wide + } + + // Calculate theoretical coverage area + // Distance (feet) * Width (feet) = Coverage area (sq ft) + const theoreticalCoverageArea = totalDistance * equipmentWidth; + + // Calculate coverage percentage (capped at 100%) + const coveragePercentage = Math.min((theoreticalCoverageArea / plannedArea) * 100, 100); + + return Math.round(coveragePercentage); + }; + useEffect(() => { const fetchApplicationData = async () => { if (!application?.id) return; @@ -176,7 +211,7 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => { Tracking Information -
+
Average Speed
{applicationLog.averageSpeed?.toFixed(1)} mph
@@ -197,6 +232,12 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => { {applicationLog.gpsTrack?.totalDistance?.toFixed(0) || 0} ft
+
+
Coverage
+
+ {calculateCoverage(application, applicationLog)}% +
+
)} diff --git a/frontend/src/pages/History/History.js b/frontend/src/pages/History/History.js index b6ea65d..7cc1d05 100644 --- a/frontend/src/pages/History/History.js +++ b/frontend/src/pages/History/History.js @@ -23,6 +23,41 @@ const History = () => { const [dateFilter, setDateFilter] = useState('all'); // all, today, week, month const [sortBy, setSortBy] = useState('date'); // date, area, duration + // Calculate coverage percentage based on GPS tracking and equipment specifications + const calculateCoverage = (application, log) => { + if (!log?.gpsTrack?.points || log.gpsTrack.points.length < 2) { + return 0; // No movement = no coverage + } + + const totalDistance = log.gpsTrack.totalDistance || 0; + const plannedArea = application.totalSectionArea || 0; + + if (totalDistance === 0 || plannedArea === 0) { + return 0; + } + + // Estimate equipment width based on type + let equipmentWidth = 4; // Default 4 feet for unknown equipment + + const equipmentName = application.equipmentName?.toLowerCase() || ''; + if (equipmentName.includes('spreader')) { + equipmentWidth = 12; // Spreaders typically 8-16 feet wide + } else if (equipmentName.includes('sprayer')) { + equipmentWidth = 20; // Sprayers typically 15-30 feet wide + } else if (equipmentName.includes('mower')) { + equipmentWidth = 6; // Mowers typically 4-8 feet wide + } + + // Calculate theoretical coverage area + // Distance (feet) * Width (feet) = Coverage area (sq ft) + const theoreticalCoverageArea = totalDistance * equipmentWidth; + + // Calculate coverage percentage (capped at 100%) + const coveragePercentage = Math.min((theoreticalCoverageArea / plannedArea) * 100, 100); + + return Math.round(coveragePercentage); + }; + useEffect(() => { fetchHistoryData(); }, []); @@ -267,7 +302,9 @@ const History = () => {
Coverage
-
100%
+
+ {calculateCoverage(application, log)}% +
)}