-
Notifications
You must be signed in to change notification settings - Fork 20
/
scripts.js
381 lines (347 loc) · 15.7 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
document.addEventListener("DOMContentLoaded", function() {
var categoryDropdown = document.getElementById("category");
var cropDropdown = document.getElementById("crop");
var enterButton = document.getElementById("enterButton");
var startDate = document.getElementById("calculateButton");
window.addEventListener('scroll', function() {
var navbar = document.getElementById('nav');
var scrollThreshold = 100; // Change this value to set the scroll threshold
if (window.scrollY >= scrollThreshold) {
navbar.classList.add('nav-black');
} else {
navbar.classList.remove('nav-black');
}
});
var selectedCrop = ("Wheat","Rice","Sweet Corn","Barley");
categoryDropdown.addEventListener("change", function() {
cropDropdown.innerHTML = ""; // Clear previous options
var selectedCategory = this.value;
if (selectedCategory === "kharif") {
addCropOption("Rice");
addCropOption("Sweet Corn");
addCropOption("Millet");
addCropOption("Sorghum");
addCropOption("Pearl Millet");
addCropOption("Sugarcane");
addCropOption("Cotton");
addCropOption("Groundnut");
addCropOption("Soybeans");
addCropOption("Turmeric");
addCropOption("Maize");
addCropOption("Sunflower");
addCropOption("Paddy");
} else if (selectedCategory === "rabi") {
addCropOption("Wheat");
addCropOption("Barley");
addCropOption("Mustard");
addCropOption("Chickpeas");
addCropOption("Lentils");
addCropOption("Peas");
addCropOption("Rapeseed");
addCropOption("Fennel");
}
});
enterButton.addEventListener("click", function() {
var selectedCategory = categoryDropdown.value;
var selectedCrop = cropDropdown.value;
var resumeItemElement = document.querySelector(".resume-item");
function displaySteps(stepsFunction) {
resumeItemElement.innerHTML = stepsFunction();
}
if (selectedCategory === "rabi") {
switch (selectedCrop) {
case "Wheat":
displaySteps(getRabiWheatSteps);
break;
case "Barley":
displaySteps(getRabiBarleySteps);
break;
case "Mustard":
displaySteps(getRabiMustardSteps);
break;
case "Chickpeas":
displaySteps(getRabiChickpeasSteps);
break;
case "Lentils":
displaySteps(getRabiLentilsSteps);
break;
case "Rapeseed":
displaySteps(getRabiRapeseedSteps);
break;
case "Fennel":
displaySteps(getRabiFennelSteps);
break;
default:
displaySteps(function() {
return "No steps available for this crop.";
});
}
} else if (selectedCategory === "kharif") {
switch (selectedCrop) {
case "Rice":
displaySteps(getKharifRiceSteps);
break;
case "Sweet Corn":
displaySteps(getKharifCornSteps);
break;
case "Millet":
displaySteps(getKharifMilletSteps);
break;
case "Sorghum":
displaySteps(getKharifSorghumSteps);
break;
case "Pearl Millet":
displaySteps(getKharifPearlMilletSteps);
break;
case "Sugarcane":
displaySteps(getKharifSugarcaneSteps);
break;
case "Cotton":
displaySteps(getKharifCottonSteps);
break;
case "Groundnut":
displaySteps(getKharifGroundnutSteps);
break;
case "Soybeans":
displaySteps(getKharifSoybeansSteps);
break;
case "Turmeric":
displaySteps(getKharifTurmericSteps);
break;
case "Maize":
displaySteps(getKharifMaizeSteps);
break;
case "Sunflower":
displaySteps(getKharifSunflowerSteps);
break;
case "Paddy":
displaySteps(getKharifPaddySteps);
break;
default:
displaySteps(function() {
return "No steps available for this crop.";
});
}
}
});
enterButton.addEventListener("click", function() {
var selectedCategory = categoryDropdown.value;
var selectedCrop = cropDropdown.value;
var startDate = new Date(document.getElementById("startDate").value);
var endDate;
var selectedDate = new Date(document.getElementById("startDate").value);
var startMonth, endMonth;
var selectedMonth = selectedDate.getMonth();
var landPreparationDate = new Date(startDate);
landPreparationDate.setDate(landPreparationDate.getDate() + 46); // Adding 46 days
var sowingDate = new Date(landPreparationDate);
sowingDate.setDate(sowingDate.getDate() + 46); // Adding 46 days
var harvestDate = new Date(sowingDate);
harvestDate.setDate(harvestDate.getDate() + 46); // Adding 46 days
if (selectedCategory === "kharif" && selectedCrop === "Rice") {
startMonth = 2; // October
endMonth = 3; // November
endDate = new Date(startDate.getFullYear(), 8, 31); // September
} else if (selectedCategory === "kharif" && selectedCrop === "Sweet Corn") {
startMonth = 3; // November
endMonth = 4; // December
endDate = new Date(startDate.getFullYear(), 10, 31);
} else if (selectedCategory === "rabi" && selectedCrop === "Wheat") {
startMonth = 9;
endMonth = 10;
endDate = new Date(startDate.getFullYear(), 2, 31);
} else if (selectedCategory === "rabi" && selectedCrop === "Barley") {
startMonth = 9;
endMonth = 10;
endDate = new Date(startDate.getFullYear(), 3, 31);
}
var timeDiff = endDate.getTime() - startDate.getTime();
var daysRemaining = Math.ceil(timeDiff / (1000 * 3600 * 24));
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var currentDate = new Date();
var daysTillLandPreparation = Math.round(Math.abs((landPreparationDate - currentDate) / oneDay));
var daysTillSowing = Math.round(Math.abs((sowingDate - currentDate) / oneDay));
// document.getElementById('landPreparationDate').textContent = landPreparationDate.toLocaleDateString();
// document.getElementById('sowingDate').textContent = sowingDate.toLocaleDateString();
if (selectedMonth >= startMonth && selectedMonth <= endMonth) {
document.getElementById('result').innerHTML = "Days until land preparation:<br> " + daysTillLandPreparation +
"<br> Sowing Date:<br> " + daysTillSowing + "<br> Days remaining till Harvesting:<br> " + daysRemaining;
} else {
document.getElementById('result').textContent = "The selected date is NOT in the Sown period.";
}
});
function addCropOption(cropName) {
var option = document.createElement("option");
option.text = cropName;
cropDropdown.add(option);
}
function getRabiWheatSteps() {
return `
<h4>Rabi - Wheat</h4>
<h5>Step 1: Land Preparation</h5>
<p><em>Prepare the land well in advance to ensure optimal growth conditions for Rabi wheat. Follow these sub-steps:</em></p>
<ul>
<li>
Clear the land of any existing crops, weeds, and debris.
</li>
<li>
Plow the field to break up the soil and remove any clods.
</li>
<h5>Step 2: Seed selection and sowing</h5>
<p><em>Select high-quality seeds that are specifically bred for Rabi wheat cultivation. Here's what you should do: </em></p>
<ul>
<li>
Choose certified seeds from reliable sources to ensure good germination and disease resistance.
</li>
<li>
Ensure proper seed depth by sowing the seeds at a depth of about 2 to 3 cm into the soil.
</li>
</ul>
<h5>Step 3: Grain Maturation and Harvest</h5>
<ul>
<li>
The time from heading to maturity can vary, but it generally takes around 3 to 4 weeks.
</li>
<li>
The wheat crop is ready for harvest when the grains have reached the desired maturity and moisture content.
</li>
</ul>
`;
}
function getRabiBarleySteps() {
return `
<h4>Rabi - Barley</h4>
<h5>Step 1: Land Preparation</h5>
<p><em><B>Prepare the land well in advance to ensure optimal growth conditions for Rabi Barley. Follow these sub-steps:</b></em></p>
<ul>
<li>
Clear the land of any existing crops, weeds, and debris.
</li>
<li>
Plow the field to break up the soil and remove any clods.
</li>
<h5>Step 2: Seed selection and sowing</h5>
<p><em><b>Select high-quality seeds that are specifically bred for Rabi wheat cultivation. Here's what you should do:</b> </em></p>
<ul>
<li>
Choose certified seeds from reliable sources to ensure good germination and disease resistance.
</li>
<li>
Ensure proper seed depth by sowing the seeds at a depth of about 2 to 3 cm into the soil.
</li>
</ul>
<h5>Step 3: Grain Maturation and Harvest</h5>
<p><em><b>The time duration for barley growth and the specific time of the year to grow barley can vary depending on various factors</b></em></p>
<ul>
<li>
The time from heading to maturity can vary, but it generally takes around 3 to 4 weeks.
</li>
<li>
The wheat crop is ready for harvest when the grains have reached the desired maturity and moisture content.
</li>
</ul>
`;
}
function getKharifRiceSteps() {
return `
<h4>Kharif - Rice</h4>
<h5>Step 1: Land Preparation</h5>
<p><em><b>Prepare the land well in advance to ensure optimal growth conditions for Kharif rice. Follow these sub-steps:</b></em></p>
<ul>
<li>
Clear the land of any existing crops, weeds, and debris.
</li>
<li>
Plow the field to break up the soil and remove any clods.
</li>
<h5>Step 2: Seed selection and sowing</h5>
<p><em><b>Select high-quality seeds that are specifically bred for Rabi wheat cultivation. Here's what you should do:</b> </em></p>
<ul>
<li>
Choose certified seeds from reliable sources to ensure good germination and disease resistance.
</li>
<li>
Ensure proper seed depth by sowing the seeds at a depth of about 2 to 3 cm into the soil.
</li>
</ul>
<h5>Step 3: Grain Maturation and Harvest</h5>
<p><em><b>Rice is typically categorized into two main types: "upland" or "dryland" rice and "paddy" or "wetland" rice:</b></em></p>
<ul>
<li>
The time from heading to maturity can vary, but it generally takes around 3 to 4 weeks.
</li>
<li>
The wheat crop is ready for harvest when the grains have reached the desired maturity and moisture content.
</li>
</ul>
`;
}
function getKharifCornSteps() {
return `
<h4>Kharif - Sweet Corn</h4>
<h5>Step 1: Land Preparation</h5>
<p><em<b>Prepare the land well in advance to ensure optimal growth conditions for Kharif Sweet Corn. Follow these sub-steps: </b></em></p>
<ul>
<li>
Clear the land of any existing crops, weeds, and debris.
</li>
<li>
Plow the field to break up the soil and remove any clods.
</li>
<h5>Step 2: Seed selection and sowing</h5>
<p><em><b>Select high-quality seeds that are specifically bred for Rabi wheat cultivation. Here's what you should do: </b></em></p>
<ul>
<li>
Choose certified seeds from reliable sources to ensure good germination and disease resistance.
</li>
<li>
Ensure proper seed depth by sowing the seeds at a depth of about 2 to 3 cm into the soil.
</li>
</ul>
<h5>Step 3: Grain Maturation and Harvest</h5>
<p><em><b>Sweet corn is a warm-season crop that thrives in areas with long, sunny days and moderate temperatures:</b></em></p>
<ul>
<li>
The time from heading to maturity can vary, but it generally takes around 3 to 4 weeks.
</li>
<li>
The wheat crop is ready for harvest when the grains have reached the desired maturity and moisture content.
</li>
</ul>
`;
}
function displayMessage(message) {
var messageBox = document.createElement("div");
messageBox.classList.add("message");
messageBox.textContent = message;
var container = document.querySelector(".container");
container.appendChild(messageBox);
setTimeout(function() {
container.removeChild(messageBox);
}, 10000);
}
});
// Replace 'API_KEY' with OpenWeatherMap API key
const apiKey = 'API_KEY';
const weatherWrapper = document.getElementById('weather_wrapper');
function fetchWeather(location) {
const url = `https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => {
const temperature = Math.round(data.main.temp - 273.15); // Convert temperature to Celsius
const rain = data.rain ? data.rain['1h'] : 0; // Rain in the last hour (if available)
const windSpeed = data.wind.speed;
// Update HTML with fetched data
weatherWrapper.querySelector('.temp').textContent = temperature + '°C';
weatherWrapper.querySelector('.location').textContent = data.name;
weatherWrapper.querySelector('.conditions').innerHTML = ''; // You can use appropriate weather icons here
weatherWrapper.querySelector('.rain').textContent = `Rain: ${rain} mm`;
weatherWrapper.querySelector('.wind').textContent = `Wind: ${windSpeed} km/h`;
})
.catch(error => {
console.log('Error fetching weather:', error);
});
}
// call fetchWeather with the user's location
fetchWeather('Himalayas'); // Replace 'Himalayas' with the user's location or use geolocation to get it