File size: 12,159 Bytes
75eac86 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analytics - Agrosynth OS</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<style>
.chart-container {
height: 300px;
}
</style>
</head>
<body class="bg-gray-50 font-sans antialiased">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<div class="bg-white shadow-md w-64 flex flex-col">
<div class="flex items-center justify-center h-16 px-4 border-b">
<div class="flex items-center">
<i data-feather="layers" class="text-green-600 h-6 w-6"></i>
<span class="ml-2 text-lg font-bold text-gray-900">Agrosynth OS</span>
</div>
</div>
<nav class="flex-1 overflow-y-auto py-4">
<div class="px-4 space-y-1">
<a href="/dashboard" class="flex items-center px-2 py-2 text-sm font-medium rounded-md text-gray-600 hover:bg-gray-50 hover:text-gray-900">
<i data-feather="home" class="text-gray-500 h-5 w-5"></i>
<span class="ml-3">Dashboard</span>
</a>
<a href="/field-maps" class="flex items-center px-2 py-2 text-sm font-medium rounded-md text-gray-600 hover:bg-gray-50 hover:text-gray-900">
<i data-feather="map" class="text-gray-500 h-5 w-5"></i>
<span class="ml-3">Field Maps</span>
</a>
<a href="/analytics" class="flex items-center px-2 py-2 text-sm font-medium rounded-md bg-green-50 text-green-700">
<i data-feather="activity" class="text-green-600 h-5 w-5"></i>
<span class="ml-3">Analytics</span>
</a>
</div>
</nav>
</div>
<!-- Main content -->
<div class="flex-1 overflow-auto">
<header class="bg-white shadow-sm">
<div class="flex justify-between items-center px-4 py-4 sm:px-6">
<h1 class="text-xl font-semibold text-gray-900">Analytics</h1>
</div>
</header>
<main class="p-4 sm:p-6">
<div id="analytics-container">
<div class="rounded-xl border p-6 text-sm text-gray-500">Loading analytics...</div>
</div>
</main>
</div>
</div>
<script>
feather.replace();
// Fetch analytics data with error handling
(async () => {
try {
const r = await fetch('/api/proxy/api/v1/farms/analytics');
const text = await r.text();
const data = JSON.parse(text);
const container = document.getElementById('analytics-container');
container.innerHTML = `
<h1 class="text-2xl font-semibold mb-4">Analytics</h1>
<div class="grid md:grid-cols-2 gap-6">
<div class="border rounded-xl p-4">
<div class="font-semibold mb-2">Yield Trend (t/ha)</div>
<div class="chart-container">
<canvas id="yieldChart"></canvas>
</div>
</div>
<div class="border rounded-xl p-4">
<div class="font-semibold mb-2">Soil Moisture (%)</div>
<div class="chart-container">
<canvas id="moistureChart"></canvas>
</div>
</div>
</div>
`;
// Yield Chart
const yieldCtx = document.getElementById('yieldChart').getContext('2d');
new Chart(yieldCtx, {
type: 'line',
data: {
labels: data.yield.labels,
datasets: [{
label: 'Yield (t/ha)',
data: data.yield.values,
borderColor: '#22c55e',
backgroundColor: 'rgba(34, 197, 94, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: (context) => `${context.dataset.label}: ${context.parsed.y} t/ha`
}
}
},
scales: {
y: {
beginAtZero: false,
min: Math.min(...data.yield.values) - 0.5,
max: Math.max(...data.yield.values) + 0.5
}
}
}
});
// Moisture Chart
const moistureCtx = document.getElementById('moistureChart').getContext('2d');
new Chart(moistureCtx, {
type: 'line',
data: {
labels: data.moisture.labels,
datasets: [{
label: 'Soil Moisture (%)',
data: data.moisture.values,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: (context) => `${context.dataset.label}: ${context.parsed.y}%`
}
}
},
scales: {
y: {
beginAtZero: false,
min: Math.min(...data.moisture.values) - 5,
max: Math.max(...data.moisture.values) + 5
}
}
}
});
})
// Render charts with the data
const container = document.getElementById('analytics-container');
container.innerHTML = `
<h1 class="text-2xl font-semibold mb-4">Analytics</h1>
<div class="grid md:grid-cols-2 gap-6">
<div class="border rounded-xl p-4">
<div class="font-semibold mb-2">Yield Trend (t/ha)</div>
<div class="chart-container">
<canvas id="yieldChart"></canvas>
</div>
</div>
<div class="border rounded-xl p-4">
<div class="font-semibold mb-2">Soil Moisture (%)</div>
<div class="chart-container">
<canvas id="moistureChart"></canvas>
</div>
</div>
</div>
`;
// Yield Chart
const yieldCtx = document.getElementById('yieldChart').getContext('2d');
new Chart(yieldCtx, {
type: 'line',
data: {
labels: data.yield.labels,
datasets: [{
label: 'Yield (t/ha)',
data: data.yield.values,
borderColor: '#22c55e',
backgroundColor: 'rgba(34, 197, 94, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: (context) => `${context.dataset.label}: ${context.parsed.y} t/ha`
}
}
},
scales: {
y: {
beginAtZero: false,
min: Math.min(...data.yield.values) - 0.5,
max: Math.max(...data.yield.values) + 0.5
}
}
}
});
// Moisture Chart
const moistureCtx = document.getElementById('moistureChart').getContext('2d');
new Chart(moistureCtx, {
type: 'line',
data: {
labels: data.moisture.labels,
datasets: [{
label: 'Soil Moisture (%)',
data: data.moisture.values,
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderWidth: 2,
tension: 0.4,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false },
tooltip: {
callbacks: {
label: (context) => `${context.dataset.label}: ${context.parsed.y}%`
}
}
},
scales: {
y: {
beginAtZero: false,
min: Math.min(...data.moisture.values) - 5,
max: Math.max(...data.moisture.values) + 5
}
}
}
});
} catch (e) {
const container = document.getElementById('analytics-container');
container.innerHTML = `
<div class="rounded-xl border p-6">
<h1 class="text-2xl font-semibold mb-4">Analytics</h1>
<div class="text-red-600">
Failed to load analytics data: ${e}
</div>
<button onclick="window.location.reload()"
class="mt-4 px-4 py-2 bg-primary-600 text-white rounded hover:bg-primary-700">
Retry
</button>
</div>
`;
}
})();
</script>
</body>
</html> |