MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / buildPlanningSignals

Function buildPlanningSignals

src/components/CropPlanningSection.tsx:1147–1176  ·  view source on GitHub ↗
({ ndviData, soilData, weatherData, suitabilityData, field }: Omit<CropPlanningSectionProps, "mapToken">)

Source from the content-addressed store, hash-verified

1145 if (waterNeeds === "low") return 0.28;
1146 return 0.55;
1147}
1148
1149function buildPlanningSignals({ ndviData, soilData, weatherData, suitabilityData, field }: Omit<CropPlanningSectionProps, "mapToken">): PlanningSignals {
1150 const annualRainfall = suitabilityData?.raw?.annual_rainfall_mm ?? (weatherData?.humidity ? weatherData.humidity * 24 : 1100);
1151 const availableWater = soilData?.water_retention?.available_water_pct ?? 12;
1152 const waterAccess = suitabilityData?.water_access ?? 6;
1153 const ndvi = clamp(ndviData?.mean_ndvi ?? 0.58, 0.18, 0.92);
1154 const healthScore = clamp((ndviData?.vegetation_health_score ?? 70) / 100, 0.35, 0.95);
1155
1156 const waterIndex = clamp(
1157 (availableWater / 25) * 0.45 +
1158 (waterAccess / 10) * 0.35 +
1159 clamp(annualRainfall / 2600, 0, 1) * 0.2,
1160 0.15,
1161 0.95,
1162 );
1163
1164 return {
1165 ndvi,
1166 healthScore,
1167 soilPH: soilData?.metrics?.ph ?? 6.7,
1168 annualRainfall,
1169 temperature: weatherData?.temperature ?? 27,
1170 humidity: weatherData?.humidity ?? 65,
1171 waterIndex,
1172 soilQuality: clamp((suitabilityData?.soil_quality ?? 7) / 10, 0.35, 0.95),
1173 climateQuality: clamp((suitabilityData?.climate ?? 7) / 10, 0.35, 0.95),
1174 topographyQuality: clamp((suitabilityData?.topography ?? 8) / 10, 0.35, 0.95),
1175 locationText: normalizeLocation(field.location),
1176 soilClass: soilData?.classification?.soil_class || soilData?.texture?.usda_class || "loam",
1177 };
1178}
1179

Callers 1

buildLocalCropPlanFunction · 0.85

Calls 2

clampFunction · 0.85
normalizeLocationFunction · 0.85

Tested by

no test coverage detected