application calculation
This commit is contained in:
@@ -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 }) => {
|
||||
<ClockIcon className="h-5 w-5 mr-2" />
|
||||
Tracking Information
|
||||
</h3>
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div className="grid grid-cols-2 lg:grid-cols-5 gap-4">
|
||||
<div className="bg-blue-50 p-3 rounded-lg">
|
||||
<div className="text-sm text-blue-600 font-medium">Average Speed</div>
|
||||
<div className="text-xl font-bold text-blue-900">{applicationLog.averageSpeed?.toFixed(1)} mph</div>
|
||||
@@ -197,6 +232,12 @@ const ApplicationViewModal = ({ application, propertyDetails, onClose }) => {
|
||||
{applicationLog.gpsTrack?.totalDistance?.toFixed(0) || 0} ft
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-emerald-50 p-3 rounded-lg">
|
||||
<div className="text-sm text-emerald-600 font-medium">Coverage</div>
|
||||
<div className="text-xl font-bold text-emerald-900">
|
||||
{calculateCoverage(application, applicationLog)}%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -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