application calculation
This commit is contained in:
@@ -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 = () => {
|
||||
</div>
|
||||
<div className="bg-orange-50 p-2 rounded text-center">
|
||||
<div className="text-xs text-orange-600 font-medium">Coverage</div>
|
||||
<div className="text-sm font-bold text-orange-900">100%</div>
|
||||
<div className="text-sm font-bold text-orange-900">
|
||||
{calculateCoverage(application, log)}%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user