Spaces:
Sleeping
Sleeping
File size: 20,069 Bytes
7418d85 5c86dd9 |
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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Crop Swapping Strategy Optimizer</title>
<!-- Tailwind CSS CDN -->
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet" />
<!-- Add Font Awesome for better icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
<!-- Add Animation library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<!-- Google Fonts for better Malayalam support -->
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Malayalam:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Custom CSS for Enhanced UI -->
<style>
/* Custom font support for Malayalam and other languages */
body {
font-family: 'Inter', 'Noto Sans Malayalam', sans-serif;
background: linear-gradient(120deg, #e0f2f1, #f0fff4, #e8f5e9);
background-size: 400% 400%;
animation: gradientBG 15s ease infinite;
line-height: 1.6;
}
@keyframes gradientBG {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
/* Card hover effects - Fixed z-index issues */
.card-hover {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
position: relative;
z-index: 1;
}
.card-hover:hover {
transform: translateY(-3px);
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
z-index: 2;
}
/* Button animations - Fixed ripple effect */
.btn-animated {
position: relative;
overflow: hidden;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
border: none;
outline: none;
}
.btn-animated:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
background: rgba(255, 255, 255, 0.3);
border-radius: 50%;
transform: translate(-50%, -50%);
transition: width 0.6s, height 0.6s;
}
.btn-animated:active:after {
width: 300px;
height: 300px;
}
/* Input focus animations - Fixed focus states */
.input-focus {
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
border: 2px solid #e2e8f0;
background-color: #ffffff;
}
.input-focus:focus {
border-color: #4CAF50;
box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
background-color: #fefefe;
outline: none;
}
.input-focus:hover {
border-color: #cbd5e0;
}
/* Table improvements - Fixed responsive issues */
.table-responsive {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.table-row {
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.table-row:hover {
background-color: #f0fff4;
transform: translateX(2px);
}
/* Fixed output styling */
.output-container {
max-width: 100%;
overflow-x: auto;
background: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 0;
}
.plain-output {
font-size: 1rem;
line-height: 1.6;
color: #333;
padding: 1.5rem;
word-wrap: break-word;
overflow-wrap: break-word;
}
/* Fixed scrollbar */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f7fafc;
border-radius: 4px;
}
::-webkit-scrollbar-thumb {
background: linear-gradient(45deg, #4CAF50, #66BB6A);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: linear-gradient(45deg, #388E3C, #4CAF50);
}
/* Remove button improvements */
.remove-btn {
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
padding: 8px;
border-radius: 4px;
opacity: 0.7;
background-color: transparent;
}
.remove-btn:hover {
opacity: 1;
background-color: #fee2e2;
color: #dc2626;
transform: scale(1.05);
}
/* Page title animation */
.title-animate {
animation: slideInDown 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slideInDown {
from {
opacity: 0;
transform: translate3d(0, -30px, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
/* Error message styling */
.error-message {
background-color: #fee2e2;
border: 1px solid #fca5a5;
color: #dc2626;
padding: 1rem;
border-radius: 8px;
margin: 1rem 0;
}
/* Loading spinner */
.loading {
display: none;
text-align: center;
padding: 2rem;
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #4CAF50;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 0 auto 1rem;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Mobile responsiveness improvements */
@media (max-width: 768px) {
.container-mobile {
padding: 1rem;
}
.grid-mobile {
grid-template-columns: 1fr;
gap: 1rem;
}
.text-mobile {
font-size: 1.5rem;
}
.table-mobile {
font-size: 0.875rem;
}
}
/* Form validation styles */
.input-error {
border-color: #ef4444 !important;
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
}
.error-text {
color: #ef4444;
font-size: 0.875rem;
margin-top: 0.25rem;
}
</style>
</head>
<body class="min-h-screen flex flex-col items-center justify-center p-6">
<div class="w-full max-w-6xl animate__animated animate__fadeIn container-mobile">
<h1 class="text-4xl md:text-5xl font-bold text-center text-green-700 mb-8 title-animate text-mobile">
<i class="fas fa-seedling mr-2"></i>Crop Swapping Strategy Optimizer
</h1>
<form id="cropForm" action="/" method="POST" class="bg-white shadow-lg rounded-lg px-6 md:px-8 pt-6 pb-8 mb-6 card-hover">
<!-- Farm Information -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6 grid-mobile">
<div>
<label class="block text-green-700 text-sm font-bold mb-2" for="location">
<i class="fas fa-map-marker-alt mr-1"></i> Location
</label>
<input class="shadow appearance-none border rounded w-full py-3 px-4 text-green-700 leading-tight focus:outline-none focus:shadow-outline input-focus"
id="location" name="location" type="text" placeholder="Enter location" required />
<div class="error-text" id="location-error"></div>
</div>
<div>
<label class="block text-green-700 text-sm font-bold mb-2" for="season">
<i class="fas fa-cloud-sun mr-1"></i> Season
</label>
<select id="season" name="season" class="shadow appearance-none border rounded w-full py-3 px-4 text-green-700 leading-tight focus:outline-none focus:shadow-outline input-focus" required>
<option value="" disabled selected>Select Season</option>
<option value="Rabi">Rabi</option>
<option value="Kharif">Kharif</option>
<option value="Zaid">Zaid</option>
</select>
<div class="error-text" id="season-error"></div>
</div>
<div>
<label class="block text-green-700 text-sm font-bold mb-2" for="total_area">
<i class="fas fa-ruler-combined mr-1"></i> Total Farm Area (acres)
</label>
<input class="shadow appearance-none border rounded w-full py-3 px-4 text-green-700 leading-tight focus:outline-none focus:shadow-outline input-focus"
id="total_area" name="total_area" type="number" step="0.1" min="0.1" placeholder="Enter total farm area" required />
<div class="error-text" id="total_area-error"></div>
</div>
<div>
<label class="block text-green-700 text-sm font-bold mb-2" for="language">
<i class="fas fa-language mr-1"></i> Language
</label>
<select id="language" name="language" class="shadow appearance-none border rounded w-full py-3 px-4 text-green-700 leading-tight focus:outline-none focus:shadow-outline input-focus">
<option value="English">English</option>
<option value="Malayalam">Malayalam</option>
<option value="Marathi">Marathi</option>
<option value="Hindi">Hindi</option>
<option value="Urdu">Urdu</option>
<option value="Bengali">Bengali</option>
<option value="Odia">Odia</option>
<option value="Telugu">Telugu</option>
<option value="Tamil">Tamil</option>
</select>
</div>
</div>
<!-- Dynamic Crop Details Table -->
<h2 class="text-2xl font-semibold text-green-600 mt-8 mb-4 text-center animate__animated animate__fadeIn">
<i class="fas fa-leaf mr-2"></i>Crop Details
</h2>
<div class="table-responsive mb-6 rounded-lg shadow">
<table class="min-w-full divide-y divide-green-200 table-mobile" id="cropTable">
<thead class="bg-green-100">
<tr>
<th class="px-4 md:px-6 py-3 text-left text-xs font-medium text-green-700 uppercase tracking-wider">Crop Name</th>
<th class="px-4 md:px-6 py-3 text-left text-xs font-medium text-green-700 uppercase tracking-wider">Area (acres)</th>
<th class="px-4 md:px-6 py-3 text-center text-xs font-medium text-green-700 uppercase tracking-wider">Action</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-green-200" id="cropTableBody">
<!-- Initial Crop Row -->
<tr class="table-row animate__animated animate__fadeIn">
<td class="px-4 md:px-6 py-4 whitespace-nowrap">
<input name="crop_name" type="text" placeholder="e.g., Tomato" required
class="shadow appearance-none border rounded w-full py-2 px-3 text-green-700 input-focus crop-name-input" />
</td>
<td class="px-4 md:px-6 py-4 whitespace-nowrap">
<input name="crop_area" type="number" step="0.1" min="0.1" placeholder="e.g., 2.5" required
class="shadow appearance-none border rounded w-full py-2 px-3 text-green-700 input-focus crop-area-input" />
</td>
<td class="px-4 md:px-6 py-4 whitespace-nowrap text-center">
<button type="button" class="text-red-500 hover:text-red-700 remove-btn" onclick="removeRow(this)">
<i class="fas fa-trash-alt"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="mb-6 flex justify-center">
<button type="button" onclick="addRow()" id="addRowBtn"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded btn-animated">
<i class="fas fa-plus mr-2"></i>Add Crop
</button>
</div>
<div class="flex items-center justify-center">
<button class="bg-green-500 hover:bg-green-700 text-white font-bold py-3 px-6 rounded-lg focus:outline-none focus:shadow-outline btn-animated" type="submit" id="submitBtn">
<i class="fas fa-magic mr-2"></i>Optimize Strategy
</button>
</div>
</form>
<!-- Loading spinner -->
<div class="loading" id="loadingSpinner">
<div class="spinner"></div>
<p class="text-green-700 font-medium">Generating your crop strategy...</p>
</div>
<!-- Display error if any -->
{% if error %}
<div class="error-message animate__animated animate__shakeX">
<i class="fas fa-exclamation-triangle mr-2"></i>{{ error }}
</div>
{% endif %}
<!-- Render the optimized output if available -->
{% if result %}
<div class="bg-white shadow-lg rounded-lg px-6 md:px-8 pt-6 pb-8 animate__animated animate__fadeInUp card-hover output-container">
<h2 class="text-2xl font-bold text-center text-green-700 mb-4">
<i class="fas fa-chart-line mr-2"></i>Optimized Crop Swapping Strategies
</h2>
<div class="plain-output">
{{ result|safe }}
</div>
</div>
{% endif %}
<footer class="text-center text-green-700 mt-6 opacity-75 animate__animated animate__fadeIn">
<p>© 2025 Crop Swapping Strategy Optimizer</p>
</footer>
</div>
<script>
let rowCount = 1;
// Function to validate form
function validateForm() {
let isValid = true;
const errors = {};
// Clear previous errors
document.querySelectorAll('.error-text').forEach(el => el.textContent = '');
document.querySelectorAll('.input-error').forEach(el => el.classList.remove('input-error'));
// Validate location
const location = document.getElementById('location').value.trim();
if (!location) {
errors.location = 'Location is required';
isValid = false;
}
// Validate season
const season = document.getElementById('season').value;
if (!season) {
errors.season = 'Season is required';
isValid = false;
}
// Validate total area
const totalArea = parseFloat(document.getElementById('total_area').value);
if (!totalArea || totalArea <= 0) {
errors.total_area = 'Total area must be greater than 0';
isValid = false;
}
// Validate crop details
const cropNames = document.querySelectorAll('.crop-name-input');
const cropAreas = document.querySelectorAll('.crop-area-input');
let totalCropArea = 0;
let hasCrops = false;
for (let i = 0; i < cropNames.length; i++) {
const name = cropNames[i].value.trim();
const area = parseFloat(cropAreas[i].value);
if (name && area) {
hasCrops = true;
totalCropArea += area;
}
}
if (!hasCrops) {
alert('Please add at least one crop with name and area');
isValid = false;
}
if (hasCrops && totalArea && totalCropArea > totalArea) {
errors.total_area = `Total crop area (${totalCropArea}) cannot exceed farm area (${totalArea})`;
isValid = false;
}
// Display errors
Object.keys(errors).forEach(field => {
const errorElement = document.getElementById(field + '-error');
const inputElement = document.getElementById(field);
if (errorElement) {
errorElement.textContent = errors[field];
}
if (inputElement) {
inputElement.classList.add('input-error');
}
});
return isValid;
}
// Function to add a new crop row with animation
function addRow() {
rowCount++;
const tableBody = document.getElementById("cropTableBody");
const newRow = document.createElement("tr");
newRow.className = "table-row animate__animated animate__fadeIn";
newRow.innerHTML = `
<td class="px-4 md:px-6 py-4 whitespace-nowrap">
<input name="crop_name" type="text" placeholder="e.g., Rice" required
class="shadow appearance-none border rounded w-full py-2 px-3 text-green-700 input-focus crop-name-input" />
</td>
<td class="px-4 md:px-6 py-4 whitespace-nowrap">
<input name="crop_area" type="number" step="0.1" min="0.1" placeholder="e.g., 1.5" required
class="shadow appearance-none border rounded w-full py-2 px-3 text-green-700 input-focus crop-area-input" />
</td>
<td class="px-4 md:px-6 py-4 whitespace-nowrap text-center">
<button type="button" class="text-red-500 hover:text-red-700 remove-btn" onclick="removeRow(this)">
<i class="fas fa-trash-alt"></i>
</button>
</td>
`;
tableBody.appendChild(newRow);
}
// Function to remove a crop row with animation
function removeRow(button) {
const tableBody = document.getElementById("cropTableBody");
const rows = tableBody.querySelectorAll('tr');
// Prevent removing the last row
if (rows.length <= 1) {
alert('At least one crop row is required');
return;
}
const row = button.closest("tr");
row.classList.add("animate__animated", "animate__fadeOut");
// Wait for animation to complete before removing the row
setTimeout(() => {
row.remove();
rowCount--;
}, 500);
}
// Add form submission handling
document.getElementById("cropForm").addEventListener("submit", function(e) {
e.preventDefault();
if (!validateForm()) {
return false;
}
// Show loading spinner
document.getElementById('loadingSpinner').style.display = 'block';
document.getElementById('submitBtn').disabled = true;
document.getElementById('submitBtn').innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i>Processing...';
// Submit form
this.submit();
});
// Real-time validation for total area vs crop areas
function validateAreas() {
const totalArea = parseFloat(document.getElementById('total_area').value) || 0;
const cropAreas = document.querySelectorAll('.crop-area-input');
let totalCropArea = 0;
cropAreas.forEach(input => {
const area = parseFloat(input.value) || 0;
totalCropArea += area;
});
const errorElement = document.getElementById('total_area-error');
const totalAreaInput = document.getElementById('total_area');
if (totalArea > 0 && totalCropArea > totalArea) {
errorElement.textContent = `Crop areas total (${totalCropArea.toFixed(1)}) exceeds farm area (${totalArea})`;
totalAreaInput.classList.add('input-error');
} else {
errorElement.textContent = '';
totalAreaInput.classList.remove('input-error');
}
}
// Add event listeners for real-time validation
document.getElementById('total_area').addEventListener('input', validateAreas);
document.addEventListener('input', function(e) {
if (e.target.classList.contains('crop-area-input')) {
validateAreas();
}
});
// Animate input fields on focus
document.querySelectorAll("input, select").forEach(element => {
element.addEventListener("focus", function() {
this.classList.add("animate__animated", "animate__pulse");
setTimeout(() => {
this.classList.remove("animate__animated", "animate__pulse");
}, 1000);
});
});
// Add keyboard shortcuts
document.addEventListener('keydown', function(e) {
// Alt + A to add row
if (e.altKey && e.key === 'a') {
e.preventDefault();
addRow();
}
// Ctrl + Enter to submit form
if (e.ctrlKey && e.key === 'Enter') {
e.preventDefault();
document.getElementById('cropForm').dispatchEvent(new Event('submit'));
}
});
// Initialize tooltips and accessibility features
document.addEventListener('DOMContentLoaded', function() {
// Add ARIA labels
document.querySelectorAll('input').forEach(input => {
const label = input.closest('div').querySelector('label');
if (label) {
input.setAttribute('aria-label', label.textContent.trim());
}
});
// Focus first input
document.getElementById('location').focus();
});
</script>
</body>
</html> |