This commit is contained in:
Jake Kasper
2025-08-26 07:09:25 -05:00
parent 054f743e2d
commit 0a47dd742b
3 changed files with 128 additions and 55 deletions

View File

@@ -27,53 +27,52 @@ function calculateLiquidApplication(areaSquareFeet, rateAmount, rateUnit, equipm
Equipment: ${equipment?.categoryName} (width: ${equipment?.sprayWidthFeet || 'N/A'} ft)
Nozzle GPM: ${nozzle?.flowRateGpm || 'N/A'}`);
// Calculate application speed first based on equipment and nozzle
if (equipment && nozzle && nozzle.flowRateGpm && equipment.sprayWidthFeet) {
const sprayWidthFeet = equipment.sprayWidthFeet;
const nozzleGpm = nozzle.flowRateGpm;
// For liquid applications, we need to determine optimal speed based on target carrier rate
// Let's use a reasonable default carrier rate of 20 GPA (gallons per acre)
const targetGallonsPerAcre = 20;
const targetGallonsPerSqft = targetGallonsPerAcre / 43560;
// Formula: Speed (MPH) = GPM / (width_ft × target_rate_gal_per_sqft × 88)
// Where 88 converts MPH to ft/min
applicationSpeedMph = nozzleGpm / (sprayWidthFeet * targetGallonsPerSqft * 88);
// Limit speed to reasonable range (1-8 MPH for lawn applications)
applicationSpeedMph = Math.max(1, Math.min(8, applicationSpeedMph));
} else {
applicationSpeedMph = 3; // Default speed
}
// Use a practical application speed for lawn treatments
applicationSpeedMph = 3; // Standard walking speed for most lawn applications
// Now calculate actual carrier (water) rate using the calculated speed
// Calculate actual carrier (water) rate based on equipment specs and application speed
// Formula: Rate (gal/sqft) = flow (GPM) / (width (ft) × speed (ft/min))
// Where speed (ft/min) = speed (MPH) × 88
let carrierRateGalPerSqft = 0;
let actualGallonsPerAcre = 0;
if (equipment && nozzle && nozzle.flowRateGpm && equipment.sprayWidthFeet) {
const flowGpm = nozzle.flowRateGpm;
const widthFt = equipment.sprayWidthFeet;
const speedFtPerMin = applicationSpeedMph * 88; // Convert MPH to ft/min
// Calculate carrier rate based on actual equipment parameters
carrierRateGalPerSqft = flowGpm / (widthFt * speedFtPerMin);
waterGallons = carrierRateGalPerSqft * areaSquareFeet;
console.log('Carrier rate calculation:', {
// Calculate the resulting GPA for reference
actualGallonsPerAcre = carrierRateGalPerSqft * 43560;
console.log('Equipment-based carrier rate calculation:', {
flowGpm,
widthFt,
speedMph: applicationSpeedMph,
speedFtPerMin,
carrierRateGalPerSqft,
carrierRateGalPerSqft: carrierRateGalPerSqft.toFixed(6),
areaSquareFeet,
totalWaterGallons: waterGallons,
carrierRateGalPer1000Sqft: carrierRateGalPerSqft * 1000
totalWaterGallons: waterGallons.toFixed(2),
resultingGPA: actualGallonsPerAcre.toFixed(1),
carrierRateGalPer1000Sqft: (carrierRateGalPerSqft * 1000).toFixed(3)
});
} else {
// Fallback to area-based calculation if equipment data is missing
// Fallback when equipment/nozzle data is missing
console.log('Using fallback water calculation - missing equipment/nozzle data');
waterGallons = area1000sqft * 0.164; // Use your example: 0.164 gal/1000sqft
// Use a reasonable default rate for lawn applications (25 GPA)
const fallbackGPA = 25;
const fallbackRatePerSqft = fallbackGPA / 43560;
waterGallons = fallbackRatePerSqft * areaSquareFeet;
actualGallonsPerAcre = fallbackGPA;
console.log('Fallback calculation:', {
fallbackGPA,
areaSquareFeet,
totalWaterGallons: waterGallons.toFixed(2)
});
}
// Calculate product amount based on rate unit