(chosenProfiles: CropProfile[], signals: PlanningSignals)
| 1233 | |
| 1234 | return `${profile.name} fits this ${priority} because the ${signals.soilClass.toLowerCase()} profile and pH ${roundTo(signals.soilPH)} align well with its rooting needs. Current NDVI is ${ndviLabel}, rainfall is ~${Math.round(signals.annualRainfall)}mm/year, and the field shows ${moistureLabel} water availability for ${profile.waterNeeds}-water cropping.`; |
| 1235 | } |
| 1236 | |
| 1237 | function chooseRotationPlan(chosenProfiles: CropProfile[], signals: PlanningSignals): RotationStep[] { |
| 1238 | const names = new Set(chosenProfiles.map((profile) => profile.name)); |
| 1239 | const detectedRegions = detectRegion(signals.locationText); |
| 1240 | const isTropical = detectedRegions.includes("tropical"); |
| 1241 | const isMediterranean = detectedRegions.includes("mediterranean"); |
| 1242 | const isTemplateOrCont = detectedRegions.includes("temperate") || detectedRegions.includes("continental"); |
| 1243 | |
| 1244 | const currentMonth = new Date().getMonth(); |
| 1245 | |
| 1246 | if (isTropical) { |
| 1247 | const isKharif = currentMonth >= 5 && currentMonth <= 9; |
| 1248 | const isRabi = currentMonth >= 10 || currentMonth <= 2; |
| 1249 | const kharif = signals.annualRainfall > 1400 ? (names.has("Rice") ? "Rice" : names.has("Turmeric") ? "Turmeric" : "Maize") : names.has("Millet") ? "Millet" : "Groundnut"; |
| 1250 | const rabi = signals.temperature < 22 ? (names.has("Wheat") ? "Wheat" : "Chickpea") : names.has("Chickpea") ? "Chickpea" : "Mustard"; |
| 1251 | const zaid = names.has("Mung Bean") ? "Mung Bean" : names.has("Tomato") ? "Tomato" : "Groundnut"; |
| 1252 | return [ |
| 1253 | { season: `Kharif${isKharif ? " (Current)" : ""}`, months: "Jun-Oct", crops: [kharif, names.has("Black Pepper") ? "Black Pepper" : "Cover crop", "Mung Bean"] }, |
| 1254 | { season: `Rabi${isRabi ? " (Current)" : ""}`, months: "Nov-Mar", crops: [rabi, names.has("Mustard") ? "Mustard" : "Lentil"] }, |
| 1255 | { season: `Zaid${!isKharif && !isRabi ? " (Current)" : ""}`, months: "Mar-Jun", crops: [zaid, "Mung Bean"] }, |
| 1256 | ]; |
| 1257 | } |
| 1258 | |
| 1259 | if (isMediterranean) { |
| 1260 | const isWinter = currentMonth >= 10 || currentMonth <= 2; |
| 1261 | const isSpring = currentMonth >= 3 && currentMonth <= 5; |
| 1262 | const isSummer = currentMonth >= 6 && currentMonth <= 9; |
| 1263 | const winter = names.has("Wheat") ? "Wheat" : names.has("Barley") ? "Barley" : "Fava Bean"; |
| 1264 | const spring = names.has("Chickpea") ? "Chickpea" : names.has("Lentil") ? "Lentil" : "Onion"; |
| 1265 | const summer = names.has("Tomato") ? "Tomato" : names.has("Sunflower") ? "Sunflower" : names.has("Maize") ? "Maize" : "Grape"; |
| 1266 | return [ |
| 1267 | { season: `Winter${isWinter ? " (Current)" : ""}`, months: "Nov-Feb", crops: [winter, names.has("Fava Bean") ? "Fava Bean" : "Barley", "Garlic"] }, |
| 1268 | { season: `Spring${isSpring ? " (Current)" : ""}`, months: "Mar-May", crops: [spring, names.has("Artichoke") ? "Artichoke" : "Onion"] }, |
| 1269 | { season: `Summer${isSummer ? " (Current)" : ""}`, months: "Jun-Oct", crops: [summer, names.has("Grape") ? "Grape" : "Alfalfa"] }, |
| 1270 | ]; |
| 1271 | } |
| 1272 | |
| 1273 | // Temperate / Continental / default |
| 1274 | const isSpring = currentMonth >= 2 && currentMonth <= 4; |
| 1275 | const isSummer = currentMonth >= 5 && currentMonth <= 8; |
| 1276 | const isAutumn = currentMonth >= 9 && currentMonth <= 11; |
| 1277 | const spring = names.has("Wheat") ? "Wheat" : names.has("Barley") ? "Barley" : names.has("Oats") ? "Oats" : "Canola"; |
| 1278 | const summer = names.has("Maize") ? "Maize" : names.has("Sunflower") ? "Sunflower" : names.has("Potato") ? "Potato" : "Sugar Beet"; |
| 1279 | const autumn = names.has("Rye") ? "Rye" : names.has("Clover") ? "Clover" : "Field Pea"; |
| 1280 | return [ |
| 1281 | { season: `Spring${isSpring ? " (Current)" : ""}`, months: "Mar-May", crops: [spring, names.has("Field Pea") ? "Field Pea" : "Clover", "Oats"] }, |
| 1282 | { season: `Summer${isSummer ? " (Current)" : ""}`, months: "Jun-Sep", crops: [summer, names.has("Potato") ? "Potato" : "Alfalfa"] }, |
| 1283 | { season: `Autumn/Winter${isAutumn ? " (Current)" : ""}`, months: "Oct-Feb", crops: [autumn, "Cover crop"] }, |
| 1284 | ]; |
| 1285 | } |
| 1286 |
no test coverage detected