Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +266 -266
templates/index.html
CHANGED
@@ -1,266 +1,266 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<title>Pest GeoSpatial Analytics</title>
|
6 |
-
<style>
|
7 |
-
/* Import a Google Font for a modern look */
|
8 |
-
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
9 |
-
|
10 |
-
/* Keyframe for fade-in effect */
|
11 |
-
@keyframes fadeIn {
|
12 |
-
from { opacity: 0; transform: translateY(20px); }
|
13 |
-
to { opacity: 1; transform: translateY(0); }
|
14 |
-
}
|
15 |
-
|
16 |
-
/* Global Styles */
|
17 |
-
body {
|
18 |
-
margin: 0;
|
19 |
-
padding: 0;
|
20 |
-
font-family: 'Roboto', sans-serif;
|
21 |
-
background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
|
22 |
-
display: flex;
|
23 |
-
justify-content: center;
|
24 |
-
align-items: center;
|
25 |
-
min-height: 100vh;
|
26 |
-
}
|
27 |
-
|
28 |
-
/* Container Styles */
|
29 |
-
.container {
|
30 |
-
width: 95%;
|
31 |
-
max-width: 800px;
|
32 |
-
background: #fff;
|
33 |
-
padding: 40px;
|
34 |
-
margin: 20px;
|
35 |
-
border-radius: 12px;
|
36 |
-
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
|
37 |
-
animation: fadeIn 1s ease-out;
|
38 |
-
}
|
39 |
-
|
40 |
-
/* Heading Styles */
|
41 |
-
h1 {
|
42 |
-
color: #2e7d32;
|
43 |
-
text-align: center;
|
44 |
-
margin-bottom: 30px;
|
45 |
-
font-size: 2.8em;
|
46 |
-
}
|
47 |
-
|
48 |
-
/* Form Styles */
|
49 |
-
form {
|
50 |
-
display: flex;
|
51 |
-
flex-direction: column;
|
52 |
-
gap: 20px;
|
53 |
-
}
|
54 |
-
|
55 |
-
label {
|
56 |
-
font-weight: 500;
|
57 |
-
margin-bottom: 8px;
|
58 |
-
color: #333;
|
59 |
-
}
|
60 |
-
|
61 |
-
select, button {
|
62 |
-
width: 100%;
|
63 |
-
padding: 14px 18px;
|
64 |
-
border: 1px solid #ccc;
|
65 |
-
border-radius: 8px;
|
66 |
-
font-size: 1em;
|
67 |
-
transition: all 0.3s ease;
|
68 |
-
}
|
69 |
-
|
70 |
-
select:focus, button:focus {
|
71 |
-
outline: none;
|
72 |
-
border-color: #2e7d32;
|
73 |
-
box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
|
74 |
-
}
|
75 |
-
|
76 |
-
button {
|
77 |
-
background-color: #2e7d32;
|
78 |
-
color: #fff;
|
79 |
-
font-weight: 700;
|
80 |
-
cursor: pointer;
|
81 |
-
margin-top: 10px;
|
82 |
-
}
|
83 |
-
|
84 |
-
button:hover {
|
85 |
-
background-color: #276a2e;
|
86 |
-
transform: scale(1.02);
|
87 |
-
}
|
88 |
-
|
89 |
-
.note {
|
90 |
-
font-style: italic;
|
91 |
-
color: #555;
|
92 |
-
margin-top: 10px;
|
93 |
-
text-align: center;
|
94 |
-
}
|
95 |
-
|
96 |
-
/* Map Section Styles */
|
97 |
-
.map {
|
98 |
-
margin-top: 40px;
|
99 |
-
text-align: center;
|
100 |
-
}
|
101 |
-
|
102 |
-
.map h2 {
|
103 |
-
color: #2e7d32;
|
104 |
-
margin-bottom: 20px;
|
105 |
-
font-size: 2em;
|
106 |
-
}
|
107 |
-
|
108 |
-
.map img {
|
109 |
-
max-width: 100%;
|
110 |
-
border: 3px solid #2e7d32;
|
111 |
-
border-radius: 8px;
|
112 |
-
transition: opacity 0.5s ease;
|
113 |
-
}
|
114 |
-
|
115 |
-
.error {
|
116 |
-
color: red;
|
117 |
-
font-weight: 700;
|
118 |
-
margin-top: 20px;
|
119 |
-
font-size: 1.2em;
|
120 |
-
}
|
121 |
-
</style>
|
122 |
-
</head>
|
123 |
-
<body>
|
124 |
-
<div class="container">
|
125 |
-
<h1>Pest GeoSpatial Analytics</h1>
|
126 |
-
|
127 |
-
<form method="GET" action="/">
|
128 |
-
<!-- Crop selection -->
|
129 |
-
<label for="crop">Crop:</label>
|
130 |
-
<select id="crop" name="crop" onchange="updatePestDropdown()">
|
131 |
-
<option value="">--Select Crop--</option>
|
132 |
-
{% for c in crops %}
|
133 |
-
<option value="{{ c }}" {% if selected_crop == c %}selected{% endif %}>{{ c }}</option>
|
134 |
-
{% endfor %}
|
135 |
-
</select>
|
136 |
-
|
137 |
-
<!-- Pest selection (populated dynamically) -->
|
138 |
-
<label for="pest">Pest:</label>
|
139 |
-
<select id="pest" name="pest">
|
140 |
-
<option value="">--Select Pest--</option>
|
141 |
-
<!-- Options will be set by JavaScript based on selected crop -->
|
142 |
-
</select>
|
143 |
-
|
144 |
-
<!-- Year selection -->
|
145 |
-
<label for="year">Year:</label>
|
146 |
-
<select id="year" name="year" onchange="fetchWeeks()">
|
147 |
-
<option value="">--Select Year--</option>
|
148 |
-
{% for y in years %}
|
149 |
-
<option value="{{ y }}" {% if selected_year == y %}selected{% endif %}>{{ y }}</option>
|
150 |
-
{% endfor %}
|
151 |
-
</select>
|
152 |
-
|
153 |
-
<!-- Week selection (populated dynamically) -->
|
154 |
-
<label for="week">Week:</label>
|
155 |
-
<select id="week" name="week">
|
156 |
-
<option value="">--Select Week--</option>
|
157 |
-
{% if selected_week %}
|
158 |
-
<option value="{{ selected_week }}" selected>{{ selected_week }}</option>
|
159 |
-
{% endif %}
|
160 |
-
</select>
|
161 |
-
|
162 |
-
<!-- Parameter selection -->
|
163 |
-
<label for="param">Parameter:</label>
|
164 |
-
<select id="param" name="param">
|
165 |
-
<option value="">--Select Parameter--</option>
|
166 |
-
{% for code, label in params.items() %}
|
167 |
-
<option value="{{ code }}" {% if selected_param == code %}selected{% endif %}>{{ label }}</option>
|
168 |
-
{% endfor %}
|
169 |
-
</select>
|
170 |
-
|
171 |
-
<button type="submit">Load Map</button>
|
172 |
-
<p class="note">Select a Crop, Pest, Year, Week, and Parameter to load the corresponding map.</p>
|
173 |
-
</form>
|
174 |
-
|
175 |
-
{% if image_url %}
|
176 |
-
<div class="map" id="mapContainer">
|
177 |
-
<h2>Fetched Results</h2>
|
178 |
-
<img src="{{ image_url }}" alt="Map for {{ selected_param }} parameter" onerror="handleImageError(this)">
|
179 |
-
<div id="dataNotAvailable" class="error" style="display:none;">Data Not Available. Cannot plot map.</div>
|
180 |
-
</div>
|
181 |
-
{% endif %}
|
182 |
-
</div>
|
183 |
-
|
184 |
-
<script>
|
185 |
-
// Crop-to-Pest mapping provided from the server
|
186 |
-
const cropToPests = {{ crop_to_pests | tojson }};
|
187 |
-
|
188 |
-
// Update the pest dropdown based on the selected crop
|
189 |
-
function updatePestDropdown() {
|
190 |
-
const cropSelect = document.getElementById("crop");
|
191 |
-
const pestSelect = document.getElementById("pest");
|
192 |
-
const selectedCrop = cropSelect.value;
|
193 |
-
|
194 |
-
// Clear existing options
|
195 |
-
pestSelect.innerHTML = "";
|
196 |
-
const defaultOption = document.createElement("option");
|
197 |
-
defaultOption.value = "";
|
198 |
-
defaultOption.textContent = "--Select Pest--";
|
199 |
-
pestSelect.appendChild(defaultOption);
|
200 |
-
|
201 |
-
if (selectedCrop && cropToPests[selectedCrop]) {
|
202 |
-
const pests = cropToPests[selectedCrop];
|
203 |
-
pests.forEach(function(p) {
|
204 |
-
const option = document.createElement("option");
|
205 |
-
option.value = p;
|
206 |
-
option.textContent = p;
|
207 |
-
// Preserve previous selection if any
|
208 |
-
if (p === "{{ selected_pest }}") {
|
209 |
-
option.selected = true;
|
210 |
-
}
|
211 |
-
pestSelect.appendChild(option);
|
212 |
-
});
|
213 |
-
}
|
214 |
-
// Fetch week options if Year is selected
|
215 |
-
if (document.getElementById("year").value) {
|
216 |
-
fetchWeeks();
|
217 |
-
}
|
218 |
-
}
|
219 |
-
|
220 |
-
// Fetch week options dynamically from the /fetch_weeks endpoint
|
221 |
-
function fetchWeeks() {
|
222 |
-
const crop = document.getElementById("crop").value;
|
223 |
-
const pest = document.getElementById("pest").value;
|
224 |
-
const year = document.getElementById("year").value;
|
225 |
-
if (!crop || !pest || !year) return;
|
226 |
-
|
227 |
-
fetch(`/fetch_weeks?crop=${crop}&pest=${pest}&year=${year}`)
|
228 |
-
.then(response => response.json())
|
229 |
-
.then(data => {
|
230 |
-
const weekSelect = document.getElementById("week");
|
231 |
-
weekSelect.innerHTML = "";
|
232 |
-
const defaultOption = document.createElement("option");
|
233 |
-
defaultOption.value = "";
|
234 |
-
defaultOption.textContent = "--Select Week--";
|
235 |
-
weekSelect.appendChild(defaultOption);
|
236 |
-
|
237 |
-
data.weeks.forEach(function(week) {
|
238 |
-
const option = document.createElement("option");
|
239 |
-
option.value = week;
|
240 |
-
option.textContent = week;
|
241 |
-
if (week === "{{ selected_week }}") {
|
242 |
-
option.selected = true;
|
243 |
-
}
|
244 |
-
weekSelect.appendChild(option);
|
245 |
-
});
|
246 |
-
})
|
247 |
-
.catch(err => console.error("Error fetching weeks:", err));
|
248 |
-
}
|
249 |
-
|
250 |
-
// Error handler for image load failure
|
251 |
-
function handleImageError(img) {
|
252 |
-
img.style.display = "none";
|
253 |
-
document.getElementById("dataNotAvailable").style.display = "block";
|
254 |
-
}
|
255 |
-
|
256 |
-
// Initialize pest dropdown and fetch weeks on page load
|
257 |
-
window.onload = function() {
|
258 |
-
updatePestDropdown();
|
259 |
-
if ("{{ selected_year }}" && "{{ selected_crop }}" && "{{ selected_pest }}") {
|
260 |
-
fetchWeeks();
|
261 |
-
}
|
262 |
-
};
|
263 |
-
</script>
|
264 |
-
|
265 |
-
</body>
|
266 |
-
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>Pest GeoSpatial Analytics</title>
|
6 |
+
<style>
|
7 |
+
/* Import a Google Font for a modern look */
|
8 |
+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
9 |
+
|
10 |
+
/* Keyframe for fade-in effect */
|
11 |
+
@keyframes fadeIn {
|
12 |
+
from { opacity: 0; transform: translateY(20px); }
|
13 |
+
to { opacity: 1; transform: translateY(0); }
|
14 |
+
}
|
15 |
+
|
16 |
+
/* Global Styles */
|
17 |
+
body {
|
18 |
+
margin: 0;
|
19 |
+
padding: 0;
|
20 |
+
font-family: 'Roboto', sans-serif;
|
21 |
+
background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
|
22 |
+
display: flex;
|
23 |
+
justify-content: center;
|
24 |
+
align-items: center;
|
25 |
+
min-height: 100vh;
|
26 |
+
}
|
27 |
+
|
28 |
+
/* Container Styles */
|
29 |
+
.container {
|
30 |
+
width: 95%;
|
31 |
+
max-width: 800px;
|
32 |
+
background: #fff;
|
33 |
+
padding: 40px;
|
34 |
+
margin: 20px;
|
35 |
+
border-radius: 12px;
|
36 |
+
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
|
37 |
+
animation: fadeIn 1s ease-out;
|
38 |
+
}
|
39 |
+
|
40 |
+
/* Heading Styles */
|
41 |
+
h1 {
|
42 |
+
color: #2e7d32;
|
43 |
+
text-align: center;
|
44 |
+
margin-bottom: 30px;
|
45 |
+
font-size: 2.8em;
|
46 |
+
}
|
47 |
+
|
48 |
+
/* Form Styles */
|
49 |
+
form {
|
50 |
+
display: flex;
|
51 |
+
flex-direction: column;
|
52 |
+
gap: 20px;
|
53 |
+
}
|
54 |
+
|
55 |
+
label {
|
56 |
+
font-weight: 500;
|
57 |
+
margin-bottom: 8px;
|
58 |
+
color: #333;
|
59 |
+
}
|
60 |
+
|
61 |
+
select, button {
|
62 |
+
width: 100%;
|
63 |
+
padding: 14px 18px;
|
64 |
+
border: 1px solid #ccc;
|
65 |
+
border-radius: 8px;
|
66 |
+
font-size: 1em;
|
67 |
+
transition: all 0.3s ease;
|
68 |
+
}
|
69 |
+
|
70 |
+
select:focus, button:focus {
|
71 |
+
outline: none;
|
72 |
+
border-color: #2e7d32;
|
73 |
+
box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
|
74 |
+
}
|
75 |
+
|
76 |
+
button {
|
77 |
+
background-color: #2e7d32;
|
78 |
+
color: #fff;
|
79 |
+
font-weight: 700;
|
80 |
+
cursor: pointer;
|
81 |
+
margin-top: 10px;
|
82 |
+
}
|
83 |
+
|
84 |
+
button:hover {
|
85 |
+
background-color: #276a2e;
|
86 |
+
transform: scale(1.02);
|
87 |
+
}
|
88 |
+
|
89 |
+
.note {
|
90 |
+
font-style: italic;
|
91 |
+
color: #555;
|
92 |
+
margin-top: 10px;
|
93 |
+
text-align: center;
|
94 |
+
}
|
95 |
+
|
96 |
+
/* Map Section Styles */
|
97 |
+
.map {
|
98 |
+
margin-top: 40px;
|
99 |
+
text-align: center;
|
100 |
+
}
|
101 |
+
|
102 |
+
.map h2 {
|
103 |
+
color: #2e7d32;
|
104 |
+
margin-bottom: 20px;
|
105 |
+
font-size: 2em;
|
106 |
+
}
|
107 |
+
|
108 |
+
.map img {
|
109 |
+
max-width: 100%;
|
110 |
+
border: 3px solid #2e7d32;
|
111 |
+
border-radius: 8px;
|
112 |
+
transition: opacity 0.5s ease;
|
113 |
+
}
|
114 |
+
|
115 |
+
.error {
|
116 |
+
color: red;
|
117 |
+
font-weight: 700;
|
118 |
+
margin-top: 20px;
|
119 |
+
font-size: 1.2em;
|
120 |
+
}
|
121 |
+
</style>
|
122 |
+
</head>
|
123 |
+
<body>
|
124 |
+
<div class="container">
|
125 |
+
<h1>Pest GeoSpatial Analytics</h1>
|
126 |
+
|
127 |
+
<form method="GET" action="/">
|
128 |
+
<!-- Crop selection -->
|
129 |
+
<label for="crop">Crop:</label>
|
130 |
+
<select id="crop" name="crop" onchange="updatePestDropdown()">
|
131 |
+
<option value="">--Select Crop--</option>
|
132 |
+
{% for c in crops %}
|
133 |
+
<option value="{{ c }}" {% if selected_crop == c %}selected{% endif %}>{{ c }}</option>
|
134 |
+
{% endfor %}
|
135 |
+
</select>
|
136 |
+
|
137 |
+
<!-- Pest selection (populated dynamically) -->
|
138 |
+
<label for="pest">Pest:</label>
|
139 |
+
<select id="pest" name="pest">
|
140 |
+
<option value="">--Select Pest--</option>
|
141 |
+
<!-- Options will be set by JavaScript based on selected crop -->
|
142 |
+
</select>
|
143 |
+
|
144 |
+
<!-- Year selection -->
|
145 |
+
<label for="year">Year:</label>
|
146 |
+
<select id="year" name="year" onchange="fetchWeeks()">
|
147 |
+
<option value="">--Select Year--</option>
|
148 |
+
{% for y in years %}
|
149 |
+
<option value="{{ y }}" {% if selected_year == y %}selected{% endif %}>{{ y }}</option>
|
150 |
+
{% endfor %}
|
151 |
+
</select>
|
152 |
+
|
153 |
+
<!-- Week selection (populated dynamically) -->
|
154 |
+
<label for="week">Week:</label>
|
155 |
+
<select id="week" name="week">
|
156 |
+
<option value="">--Select Week--</option>
|
157 |
+
{% if selected_week %}
|
158 |
+
<option value="{{ selected_week }}" selected>{{ selected_week }}</option>
|
159 |
+
{% endif %}
|
160 |
+
</select>
|
161 |
+
|
162 |
+
<!-- Parameter selection -->
|
163 |
+
<label for="param">Parameter:</label>
|
164 |
+
<select id="param" name="param">
|
165 |
+
<option value="">--Select Parameter--</option>
|
166 |
+
{% for code, label in params.items() %}
|
167 |
+
<option value="{{ code }}" {% if selected_param == code %}selected{% endif %}>{{ label }}</option>
|
168 |
+
{% endfor %}
|
169 |
+
</select>
|
170 |
+
|
171 |
+
<button type="submit">Load Map</button>
|
172 |
+
<p class="note">Select a Crop, Pest, Year, Week, and Parameter to load the corresponding map.</p>
|
173 |
+
</form>
|
174 |
+
|
175 |
+
{% if image_url %}
|
176 |
+
<div class="map" id="mapContainer">
|
177 |
+
<h2>Fetched Results</h2>
|
178 |
+
<img src="{{ image_url }}" alt="Map for {{ selected_param }} parameter" onerror="handleImageError(this)">
|
179 |
+
<div id="dataNotAvailable" class="error" style="display:none;">Data Not Available. Cannot plot map.</div>
|
180 |
+
</div>
|
181 |
+
{% endif %}
|
182 |
+
</div>
|
183 |
+
|
184 |
+
<script>
|
185 |
+
// Crop-to-Pest mapping provided from the server
|
186 |
+
const cropToPests = {{ crop_to_pests | tojson }};
|
187 |
+
|
188 |
+
// Update the pest dropdown based on the selected crop
|
189 |
+
function updatePestDropdown() {
|
190 |
+
const cropSelect = document.getElementById("crop");
|
191 |
+
const pestSelect = document.getElementById("pest");
|
192 |
+
const selectedCrop = cropSelect.value;
|
193 |
+
|
194 |
+
// Clear existing options
|
195 |
+
pestSelect.innerHTML = "";
|
196 |
+
const defaultOption = document.createElement("option");
|
197 |
+
defaultOption.value = "";
|
198 |
+
defaultOption.textContent = "--Select Pest--";
|
199 |
+
pestSelect.appendChild(defaultOption);
|
200 |
+
|
201 |
+
if (selectedCrop && cropToPests[selectedCrop]) {
|
202 |
+
const pests = cropToPests[selectedCrop];
|
203 |
+
pests.forEach(function(p) {
|
204 |
+
const option = document.createElement("option");
|
205 |
+
option.value = p;
|
206 |
+
option.textContent = p;
|
207 |
+
// Preserve previous selection if any
|
208 |
+
if (p === "{{ selected_pest }}") {
|
209 |
+
option.selected = true;
|
210 |
+
}
|
211 |
+
pestSelect.appendChild(option);
|
212 |
+
});
|
213 |
+
}
|
214 |
+
// Fetch week options if Year is selected
|
215 |
+
if (document.getElementById("year").value) {
|
216 |
+
fetchWeeks();
|
217 |
+
}
|
218 |
+
}
|
219 |
+
|
220 |
+
// Fetch week options dynamically from the /fetch_weeks endpoint
|
221 |
+
function fetchWeeks() {
|
222 |
+
const crop = document.getElementById("crop").value;
|
223 |
+
const pest = document.getElementById("pest").value;
|
224 |
+
const year = document.getElementById("year").value;
|
225 |
+
if (!crop || !pest || !year) return;
|
226 |
+
|
227 |
+
fetch(`/fetch_weeks?crop=${crop}&pest=${pest}&year=${year}`)
|
228 |
+
.then(response => response.json())
|
229 |
+
.then(data => {
|
230 |
+
const weekSelect = document.getElementById("week");
|
231 |
+
weekSelect.innerHTML = "";
|
232 |
+
const defaultOption = document.createElement("option");
|
233 |
+
defaultOption.value = "";
|
234 |
+
defaultOption.textContent = "--Select Week--";
|
235 |
+
weekSelect.appendChild(defaultOption);
|
236 |
+
|
237 |
+
data.weeks.forEach(function(week) {
|
238 |
+
const option = document.createElement("option");
|
239 |
+
option.value = week;
|
240 |
+
option.textContent = week;
|
241 |
+
if (week === "{{ selected_week }}") {
|
242 |
+
option.selected = true;
|
243 |
+
}
|
244 |
+
weekSelect.appendChild(option);
|
245 |
+
});
|
246 |
+
})
|
247 |
+
.catch(err => console.error("Error fetching weeks:", err));
|
248 |
+
}
|
249 |
+
|
250 |
+
// Error handler for image load failure
|
251 |
+
function handleImageError(img) {
|
252 |
+
img.style.display = "none";
|
253 |
+
document.getElementById("dataNotAvailable").style.display = "block";
|
254 |
+
}
|
255 |
+
|
256 |
+
// Initialize pest dropdown and fetch weeks on page load
|
257 |
+
window.onload = function() {
|
258 |
+
updatePestDropdown();
|
259 |
+
if ("{{ selected_year }}" && "{{ selected_crop }}" && "{{ selected_pest }}") {
|
260 |
+
fetchWeeks();
|
261 |
+
}
|
262 |
+
};
|
263 |
+
</script>
|
264 |
+
|
265 |
+
</body>
|
266 |
+
</html>
|