Spaces:
Running
Running
Download index.html from Preetham77Awaji/cowtest: direct link, hf CLI and curl.
- Browser
- Download file 80.7 kB
-
https://huggingface.co/spaces/Preetham77Awaji/cowtest/resolve/main/index.html
- Command line
-
hf download hf://spaces/Preetham77Awaji/cowtest/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Preetham77Awaji/cowtest/resolve/main/index.html
80.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cattle Health Monitoring Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.sidebar {
transition: all 0.3s ease;
}
.sidebar.collapsed {
width: 70px;
}
.sidebar.collapsed .nav-text {
display: none;
}
.sidebar.collapsed .logo-text {
display: none;
}
.sidebar.collapsed .nav-item {
justify-content: center;
}
.health-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
display: inline-block;
margin-right: 6px;
}
.health-normal {
background-color: #10B981;
}
.health-warning {
background-color: #F59E0B;
}
.health-critical {
background-color: #EF4444;
}
.parameter-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}
.cattle-card:hover {
transform: translateY(-3px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.alert-critical {
border-left: 4px solid #EF4444;
}
.alert-warning {
border-left: 4px solid #F59E0B;
}
.alert-info {
border-left: 4px solid #3B82F6;
}
.chart-container {
position: relative;
height: 300px;
}
.ai-processing {
background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(236,253,245,1) 100%);
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.sidebar .nav-text {
display: none;
}
.sidebar .logo-text {
display: none;
}
.sidebar .nav-item {
justify-content: center;
}
}
</style>
</head>
<body class="bg-gray-50">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<div class="sidebar bg-green-800 text-white flex flex-col w-64">
<div class="p-4 flex items-center">
<i class="fas fa-cow text-2xl mr-3"></i>
<span class="logo-text text-xl font-bold">CattleHealth Pro</span>
</div>
<div class="flex-grow overflow-y-auto">
<nav class="p-4">
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-tachometer-alt mr-3"></i>
<span class="nav-text">Dashboard</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-cow mr-3"></i>
<span class="nav-text">Cattle Registry</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-heartbeat mr-3"></i>
<span class="nav-text">Health Monitoring</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-chart-line mr-3"></i>
<span class="nav-text">Analytics</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-bell mr-3"></i>
<span class="nav-text">Alerts</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-brain mr-3"></i>
<span class="nav-text">AI Insights</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-clipboard-list mr-3"></i>
<span class="nav-text">Reports</span>
</div>
<div class="nav-item flex items-center p-3 rounded-lg hover:bg-green-700 mb-2">
<i class="fas fa-cog mr-3"></i>
<span class="nav-text">Settings</span>
</div>
</nav>
</div>
<div class="p-4 border-t border-green-700">
<div class="flex items-center">
<img src="https://randomuser.me/api/portraits/women/44.jpg" alt="User" class="w-8 h-8 rounded-full mr-2">
<div>
<div class="nav-text text-sm font-medium">Sarah Johnson</div>
<div class="nav-text text-xs text-green-200">Farm Manager</div>
</div>
</div>
</div>
</div>
<!-- Main Content -->
<div class="flex-1 overflow-auto">
<!-- Header -->
<header class="bg-white shadow-sm p-4 flex justify-between items-center">
<div class="flex items-center">
<button class="mr-4 text-gray-500" id="sidebarToggle">
<i class="fas fa-bars"></i>
</button>
<h1 class="text-xl font-semibold text-gray-800">Cattle Health Dashboard</h1>
</div>
<div class="flex items-center space-x-4">
<div class="relative">
<button class="text-gray-500 hover:text-gray-700" id="notificationBtn">
<i class="fas fa-bell"></i>
<span class="absolute top-0 right-0 h-2 w-2 rounded-full bg-red-500"></span>
</button>
</div>
<div class="relative">
<input type="text" placeholder="Search..." class="pl-8 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-200">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
</div>
</header>
<!-- Dashboard Content -->
<main class="p-6">
<!-- Stats Overview -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6" id="statsOverview">
<!-- Stats will be loaded via API -->
</div>
<!-- Health Parameters Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-6">
<!-- Temperature Card -->
<div class="parameter-card bg-white rounded-lg shadow p-6 transition duration-300">
<div class="flex justify-between items-start mb-4">
<div>
<h3 class="font-semibold text-gray-800">Body Temperature</h3>
<p class="text-sm text-gray-500">Average: <span id="avgTemp">38.5°C</span></p>
</div>
<div class="health-indicator health-normal" id="tempIndicator"></div>
</div>
<div class="chart-container">
<canvas id="temperatureChart"></canvas>
</div>
<div class="mt-4 flex justify-between text-sm">
<span class="text-gray-500">Min: <span id="minTemp">37.8°C</span></span>
<span class="text-gray-500">Max: <span id="maxTemp">39.1°C</span></span>
</div>
</div>
<!-- Heart Rate Card -->
<div class="parameter-card bg-white rounded-lg shadow p-6 transition duration-300">
<div class="flex justify-between items-start mb-4">
<div>
<h3 class="font-semibold text-gray-800">Heart Rate</h3>
<p class="text-sm text-gray-500">Average: <span id="avgHeartRate">68 BPM</span></p>
</div>
<div class="health-indicator health-warning" id="hrIndicator"></div>
</div>
<div class="chart-container">
<canvas id="heartRateChart"></canvas>
</div>
<div class="mt-4 flex justify-between text-sm">
<span class="text-gray-500">Min: <span id="minHeartRate">62 BPM</span></span>
<span class="text-gray-500">Max: <span id="maxHeartRate">75 BPM</span></span>
</div>
</div>
<!-- Milk Production Card -->
<div class="parameter-card bg-white rounded-lg shadow p-6 transition duration-300">
<div class="flex justify-between items-start mb-4">
<div>
<h3 class="font-semibold text-gray-800">Milk Production</h3>
<p class="text-sm text-gray-500">Average: <span id="avgMilk">22.4 L/day</span></p>
</div>
<div class="health-indicator health-critical" id="milkIndicator"></div>
</div>
<div class="chart-container">
<canvas id="milkChart"></canvas>
</div>
<div class="mt-4 flex justify-between text-sm">
<span class="text-gray-500">Min: <span id="minMilk">18.2 L/day</span></span>
<span class="text-gray-500">Max: <span id="maxMilk">25.7 L/day</span></span>
</div>
</div>
</div>
<!-- AI Insights Section -->
<div class="bg-white rounded-lg shadow p-6 mb-6 ai-processing">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold text-gray-800 text-lg">AI Health Insights</h3>
<div class="flex items-center">
<span class="text-xs bg-green-100 text-green-800 px-2 py-1 rounded-full mr-2">TensorFlow</span>
<span class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full">PyTorch</span>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-white rounded-lg border p-4">
<div class="flex items-center mb-3">
<div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-eye text-purple-600"></i>
</div>
<h4 class="font-medium">Eye Temperature Analysis</h4>
</div>
<div class="flex justify-between items-center">
<div>
<p class="text-sm text-gray-600">Detecting early signs of illness</p>
<p class="text-xs text-gray-500 mt-1">Computer Vision Model</p>
</div>
<button class="text-purple-600 hover:text-purple-800 text-sm font-medium" id="runEyeAnalysis">Run Analysis</button>
</div>
</div>
<div class="bg-white rounded-lg border p-4">
<div class="flex items-center mb-3">
<div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-wave-square text-blue-600"></i>
</div>
<h4 class="font-medium">Anomaly Detection</h4>
</div>
<div class="flex justify-between items-center">
<div>
<p class="text-sm text-gray-600">Identifying abnormal patterns</p>
<p class="text-xs text-gray-500 mt-1">Scikit-learn Model</p>
</div>
<button class="text-blue-600 hover:text-blue-800 text-sm font-medium" id="runAnomalyDetection">Check Now</button>
</div>
</div>
<div class="bg-white rounded-lg border p-4">
<div class="flex items-center mb-3">
<div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-chart-line text-green-600"></i>
</div>
<h4 class="font-medium">Production Forecast</h4>
</div>
<div class="flex justify-between items-center">
<div>
<p class="text-sm text-gray-600">Predicting milk yield trends</p>
<p class="text-xs text-gray-500 mt-1">Prophet Time Series</p>
</div>
<button class="text-green-600 hover:text-green-800 text-sm font-medium" id="runProductionForecast">Generate Forecast</button>
</div>
</div>
</div>
<div id="aiResults" class="mt-6 hidden">
<!-- AI results will be displayed here -->
</div>
</div>
<!-- Alerts and Cattle List -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-6">
<!-- Alerts Section -->
<div class="lg:col-span-1">
<div class="bg-white rounded-lg shadow">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-semibold text-gray-800">Recent Alerts</h3>
<span class="text-xs bg-gray-100 text-gray-800 px-2 py-1 rounded-full">Real-time</span>
</div>
<div class="divide-y" id="alertsContainer">
<!-- Alerts will be loaded via API -->
</div>
<div class="p-4 text-center">
<button class="text-green-600 text-sm font-medium">View All Alerts</button>
</div>
</div>
</div>
<!-- Cattle List -->
<div class="lg:col-span-2">
<div class="bg-white rounded-lg shadow">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-semibold text-gray-800">Cattle Requiring Attention</h3>
<div class="flex space-x-2">
<button class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-xs">Sort by Priority</button>
<button class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs" id="addNewCow">Add New</button>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Breed</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Issue</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Action</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200" id="cattleTableBody">
<!-- Cattle data will be loaded via API -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Mastitis Detection Section -->
<div class="bg-white rounded-lg shadow p-6 mb-6">
<div class="flex justify-between items-center mb-6">
<h3 class="font-semibold text-gray-800 text-lg">Mastitis Detection System</h3>
<div class="flex space-x-2">
<button class="px-3 py-1 bg-green-100 text-green-700 rounded-full text-xs">View All</button>
<button class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-xs">Settings</button>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-green-50 rounded-lg p-4">
<div class="flex items-center mb-2">
<div class="w-8 h-8 bg-green-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-check text-green-600"></i>
</div>
<h4 class="font-medium">Healthy Quarters</h4>
</div>
<p class="text-2xl font-bold text-green-700">84%</p>
<p class="text-sm text-gray-600 mt-1">of udder quarters show no signs of mastitis</p>
</div>
<div class="bg-yellow-50 rounded-lg p-4">
<div class="flex items-center mb-2">
<div class="w-8 h-8 bg-yellow-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-exclamation text-yellow-600"></i>
</div>
<h4 class="font-medium">Early Signs</h4>
</div>
<p class="text-2xl font-bold text-yellow-700">12%</p>
<p class="text-sm text-gray-600 mt-1">of udder quarters show early mastitis signs</p>
</div>
<div class="bg-red-50 rounded-lg p-4">
<div class="flex items-center mb-2">
<div class="w-8 h-8 bg-red-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-times text-red-600"></i>
</div>
<h4 class="font-medium">Clinical Mastitis</h4>
</div>
<p class="text-2xl font-bold text-red-700">4%</p>
<p class="text-sm text-gray-600 mt-1">of udder quarters show clinical mastitis</p>
</div>
</div>
<div class="mt-6">
<div class="chart-container">
<canvas id="mastitisChart"></canvas>
</div>
</div>
</div>
</main>
</div>
</div>
<!-- Modal for adding new cattle -->
<div id="addCattleModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="p-6">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold text-gray-800">Add New Cattle</h3>
<button id="closeModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="cattleForm">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-medium mb-2" for="cattleId">ID</label>
<input type="text" id="cattleId" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-200" required>
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-medium mb-2" for="cattleName">Name</label>
<input type="text" id="cattleName" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-200" required>
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-medium mb-2" for="cattleBreed">Breed</label>
<select id="cattleBreed" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-200" required>
<option value="Holstein">Holstein</option>
<option value="Jersey">Jersey</option>
<option value="Angus">Angus</option>
<option value="Hereford">Hereford</option>
<option value="Other">Other</option>
</select>
</div>
<div class="mb-4">
<label class="block text-gray-700 text-sm font-medium mb-2" for="cattleImage">Image</label>
<input type="file" id="cattleImage" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-200">
</div>
<div class="flex justify-end space-x-3">
<button type="button" id="cancelAdd" class="px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200">Cancel</button>
<button type="submit" class="px-4 py-2 text-white bg-green-600 rounded-lg hover:bg-green-700">Save</button>
</div>
</form>
</div>
</div>
</div>
<script>
// Mock API endpoints
const API_ENDPOINTS = {
stats: '/api/dashboard/stats',
cattle: '/api/cattle',
alerts: '/api/alerts',
metrics: '/api/metrics',
predict: '/api/ai/predict'
};
// JWT token for authentication
const AUTH_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IlNhcmFoIEpvaG5zb24iLCJyb2xlIjoiZmFybV9tYW5hZ2VyIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
// Socket.IO connection for real-time updates
const socket = io('https://api.cattlehealthpro.com', {
auth: {
token: AUTH_TOKEN
}
});
// Initialize charts
let temperatureChart, heartRateChart, milkChart, mastitisChart;
// DOM elements
const sidebarToggle = document.getElementById('sidebarToggle');
const sidebar = document.querySelector('.sidebar');
const addNewCowBtn = document.getElementById('addNewCow');
const addCattleModal = document.getElementById('addCattleModal');
const closeModal = document.getElementById('closeModal');
const cancelAdd = document.getElementById('cancelAdd');
const cattleForm = document.getElementById('cattleForm');
const cattleTableBody = document.getElementById('cattleTableBody');
const alertsContainer = document.getElementById('alertsContainer');
const statsOverview = document.getElementById('statsOverview');
const aiResults = document.getElementById('aiResults');
const runEyeAnalysis = document.getElementById('runEyeAnalysis');
const runAnomalyDetection = document.getElementById('runAnomalyDetection');
const runProductionForecast = document.getElementById('runProductionForecast');
// Toggle sidebar
sidebarToggle.addEventListener('click', () => {
sidebar.classList.toggle('collapsed');
});
// Show add cattle modal
addNewCowBtn.addEventListener('click', () => {
addCattleModal.classList.remove('hidden');
});
// Hide add cattle modal
closeModal.addEventListener('click', () => {
addCattleModal.classList.add('hidden');
});
cancelAdd.addEventListener('click', () => {
addCattleModal.classList.add('hidden');
});
// Form submission for adding new cattle
cattleForm.addEventListener('submit', async (e) => {
e.preventDefault();
// Mock API call to add new cattle
try {
// In a real app, this would be an actual API call
// const response = await axios.post(API_ENDPOINTS.cattle, {
// id: document.getElementById('cattleId').value,
// name: document.getElementById('cattleName').value,
// breed: document.getElementById('cattleBreed').value,
// image: document.getElementById('cattleImage').files[0]
// }, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`,
// 'Content-Type': 'multipart/form-data'
// }
// });
// For demo purposes, we'll just log to console
console.log('Adding new cattle:', {
id: document.getElementById('cattleId').value,
name: document.getElementById('cattleName').value,
breed: document.getElementById('cattleBreed').value
});
// Show success message
alert('Cattle added successfully!');
// Close modal and reset form
addCattleModal.classList.add('hidden');
cattleForm.reset();
// Refresh cattle list
fetchCattleData();
} catch (error) {
console.error('Error adding cattle:', error);
alert('Failed to add cattle. Please try again.');
}
});
// Fetch initial data
document.addEventListener('DOMContentLoaded', () => {
initCharts();
fetchDashboardStats();
fetchCattleData();
fetchAlerts();
setupSocketListeners();
});
// Initialize charts with empty data
function initCharts() {
// Temperature Chart
const tempCtx = document.getElementById('temperatureChart').getContext('2d');
temperatureChart = new Chart(tempCtx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Temperature (°C)',
data: [],
borderColor: '#10B981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}]
},
options: getChartOptions('Temperature (°C)', 35, 42)
});
// Heart Rate Chart
const hrCtx = document.getElementById('heartRateChart').getContext('2d');
heartRateChart = new Chart(hrCtx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Heart Rate (BPM)',
data: [],
borderColor: '#F59E0B',
backgroundColor: 'rgba(245, 158, 11, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}]
},
options: getChartOptions('Heart Rate (BPM)', 50, 100)
});
// Milk Production Chart
const milkCtx = document.getElementById('milkChart').getContext('2d');
milkChart = new Chart(milkCtx, {
type: 'bar',
data: {
labels: [],
datasets: [{
label: 'Current (L/day)',
data: [],
backgroundColor: '#EF4444',
borderColor: '#EF4444',
borderWidth: 0
}, {
label: 'Average (L/day)',
data: [],
backgroundColor: '#3B82F6',
borderColor: '#3B82F6',
borderWidth: 0,
type: 'line',
pointRadius: 0
}]
},
options: getChartOptions('Milk Production (L/day)', 0, 30)
});
// Mastitis Chart
const mastitisCtx = document.getElementById('mastitisChart').getContext('2d');
mastitisChart = new Chart(mastitisCtx, {
type: 'line',
data: {
labels: [],
datasets: [{
label: 'Healthy Quarters',
data: [],
borderColor: '#10B981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}, {
label: 'Early Signs',
data: [],
borderColor: '#F59E0B',
backgroundColor: 'rgba(245, 158, 11, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}, {
label: 'Clinical Mastitis',
data: [],
borderColor: '#EF4444',
backgroundColor: 'rgba(239, 68, 68, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom'
}
},
scales: {
y: {
beginAtZero: false,
min: 0,
max: 100,
grid: {
display: false
},
ticks: {
callback: function(value) {
return value + '%';
}
}
},
x: {
grid: {
display: false
}
}
}
}
});
}
// Common chart options
function getChartOptions(title, min, max) {
return {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
y: {
beginAtZero: false,
min: min,
max: max,
grid: {
display: false
}
},
x: {
grid: {
display: false
}
}
}
};
}
// Fetch dashboard stats
async function fetchDashboardStats() {
try {
// Mock API response
const response = {
data: {
totalCattle: 142,
healthyCattle: 128,
warningAlerts: 9,
criticalAlerts: 5,
temperatureStats: {
avg: 38.5,
min: 37.8,
max: 39.1,
trend: 'up',
data: [38.2, 38.4, 38.7, 38.9, 38.6, 38.3, 38.1, 38.0],
labels: ['6am', '9am', '12pm', '3pm', '6pm', '9pm', '12am', '3am']
},
heartRateStats: {
avg: 68,
min: 62,
max: 75,
trend: 'up',
data: [65, 68, 70, 72, 71, 69, 67],
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
milkStats: {
avg: 22.4,
min: 18.2,
max: 25.7,
trend: 'down',
data: [15.2, 19.8, 21.4, 18.6, 24.3, 22.7],
labels: ['Cow #142', 'Cow #87', 'Cow #112', 'Cow #56', 'Cow #23', 'Cow #78']
},
mastitisStats: {
healthy: [82, 83, 85, 84, 83, 84, 84],
early: [13, 12, 10, 11, 12, 11, 12],
clinical: [5, 5, 5, 5, 5, 5, 4],
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
}
}
};
// In a real app, you would use:
// const response = await axios.get(API_ENDPOINTS.stats, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Update stats cards
statsOverview.innerHTML = `
<div class="bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500">Total Cattle</p>
<h3 class="text-2xl font-bold mt-1">${response.data.totalCattle}</h3>
</div>
<div class="bg-green-100 p-3 rounded-full">
<i class="fas fa-cow text-green-600"></i>
</div>
</div>
<div class="mt-4 flex items-center text-sm ${response.data.totalCattle > 130 ? 'text-green-600' : 'text-red-600'}">
<i class="fas ${response.data.totalCattle > 130 ? 'fa-arrow-up' : 'fa-arrow-down'} mr-1"></i>
<span>${response.data.totalCattle > 130 ? '12% from last month' : '5% from last month'}</span>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500">Healthy Cattle</p>
<h3 class="text-2xl font-bold mt-1">${response.data.healthyCattle}</h3>
</div>
<div class="bg-blue-100 p-3 rounded-full">
<i class="fas fa-heartbeat text-blue-600"></i>
</div>
</div>
<div class="mt-4 flex items-center text-sm ${response.data.healthyCattle > 120 ? 'text-blue-600' : 'text-red-600'}">
<i class="fas ${response.data.healthyCattle > 120 ? 'fa-arrow-up' : 'fa-arrow-down'} mr-1"></i>
<span>${response.data.healthyCattle > 120 ? '5% from last week' : '3% from last week'}</span>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500">Warning Alerts</p>
<h3 class="text-2xl font-bold mt-1">${response.data.warningAlerts}</h3>
</div>
<div class="bg-yellow-100 p-3 rounded-full">
<i class="fas fa-exclamation-triangle text-yellow-600"></i>
</div>
</div>
<div class="mt-4 flex items-center text-sm ${response.data.warningAlerts < 10 ? 'text-yellow-600' : 'text-red-600'}">
<i class="fas ${response.data.warningAlerts < 10 ? 'fa-arrow-down' : 'fa-arrow-up'} mr-1"></i>
<span>${response.data.warningAlerts < 10 ? '3% from yesterday' : '5% from yesterday'}</span>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex justify-between items-start">
<div>
<p class="text-gray-500">Critical Alerts</p>
<h3 class="text-2xl font-bold mt-1">${response.data.criticalAlerts}</h3>
</div>
<div class="bg-red-100 p-3 rounded-full">
<i class="fas fa-times-circle text-red-600"></i>
</div>
</div>
<div class="mt-4 flex items-center text-sm text-red-600">
<i class="fas fa-arrow-up mr-1"></i>
<span>2 new today</span>
</div>
</div>
`;
// Update temperature chart
document.getElementById('avgTemp').textContent = `${response.data.temperatureStats.avg}°C`;
document.getElementById('minTemp').textContent = `${response.data.temperatureStats.min}°C`;
document.getElementById('maxTemp').textContent = `${response.data.temperatureStats.max}°C`;
temperatureChart.data.labels = response.data.temperatureStats.labels;
temperatureChart.data.datasets[0].data = response.data.temperatureStats.data;
temperatureChart.update();
// Update heart rate chart
document.getElementById('avgHeartRate').textContent = `${response.data.heartRateStats.avg} BPM`;
document.getElementById('minHeartRate').textContent = `${response.data.heartRateStats.min} BPM`;
document.getElementById('maxHeartRate').textContent = `${response.data.heartRateStats.max} BPM`;
heartRateChart.data.labels = response.data.heartRateStats.labels;
heartRateChart.data.datasets[0].data = response.data.heartRateStats.data;
heartRateChart.update();
// Update milk chart
document.getElementById('avgMilk').textContent = `${response.data.milkStats.avg} L/day`;
document.getElementById('minMilk').textContent = `${response.data.milkStats.min} L/day`;
document.getElementById('maxMilk').textContent = `${response.data.milkStats.max} L/day`;
milkChart.data.labels = response.data.milkStats.labels;
milkChart.data.datasets[0].data = response.data.milkStats.data;
milkChart.data.datasets[1].data = Array(response.data.milkStats.data.length).fill(response.data.milkStats.avg);
milkChart.update();
// Update mastitis chart
mastitisChart.data.labels = response.data.mastitisStats.labels;
mastitisChart.data.datasets[0].data = response.data.mastitisStats.healthy;
mastitisChart.data.datasets[1].data = response.data.mastitisStats.early;
mastitisChart.data.datasets[2].data = response.data.mastitisStats.clinical;
mastitisChart.update();
} catch (error) {
console.error('Error fetching dashboard stats:', error);
}
}
// Fetch cattle data
async function fetchCattleData() {
try {
// Mock API response
const response = {
data: [
{
id: "142",
name: "Daisy",
breed: "Holstein",
status: "critical",
issue: "Mastitis (Severe)",
image: "https://images.unsplash.com/photo-1559163499-413a7d4aeef3?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80"
},
{
id: "87",
name: "Bella",
breed: "Jersey",
status: "warning",
issue: "Fever (39.8°C)",
image: "https://images.unsplash.com/photo-1559163499-413a7d4aeef3?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80"
},
{
id: "112",
name: "Molly",
breed: "Angus",
status: "monitor",
issue: "Lameness (Score 3)",
image: "https://images.unsplash.com/photo-1559163499-413a7d4aeef3?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80"
},
{
id: "56",
name: "Rosie",
breed: "Hereford",
status: "warning",
issue: "Low Milk Production",
image: "https://images.unsplash.com/photo-1559163499-413a7d4aeef3?ixlib=rb-1.2.1&auto=format&fit=crop&w=100&q=80"
}
]
};
// In a real app, you would use:
// const response = await axios.get(API_ENDPOINTS.cattle, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Update cattle table
cattleTableBody.innerHTML = response.data.map(cow => `
<tr class="cattle-card hover:bg-gray-50 transition duration-150">
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10">
<img class="h-10 w-10 rounded-full" src="${cow.image}" alt="">
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">#${cow.id}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900">${cow.name}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm text-gray-500">${cow.breed}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${
cow.status === 'critical' ? 'bg-red-100 text-red-800' :
cow.status === 'warning' ? 'bg-yellow-100 text-yellow-800' :
'bg-blue-100 text-blue-800'
}">
${cow.status.charAt(0).toUpperCase() + cow.status.slice(1)}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
${cow.issue}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button class="text-green-600 hover:text-green-900 mr-3">${
cow.status === 'critical' ? 'Treat' :
cow.status === 'warning' ? 'Assess' :
'Examine'
}</button>
<button class="text-gray-600 hover:text-gray-900">Details</button>
</td>
</tr>
`).join('');
} catch (error) {
console.error('Error fetching cattle data:', error);
}
}
// Fetch alerts
async function fetchAlerts() {
try {
// Mock API response
const response = {
data: [
{
id: "alert1",
type: "critical",
title: "Mastitis Detected",
description: "Cow #142 - Severe inflammation detected in left rear quarter",
timestamp: "10 min ago"
},
{
id: "alert2",
type: "warning",
title: "Elevated Temperature",
description: "Cow #87 - Temperature at 39.8°C (above threshold)",
timestamp: "45 min ago"
},
{
id: "alert3",
type: "info",
title: "Lameness Detected",
description: "Cow #112 - Mobility score 3 (moderate lameness)",
timestamp: "2 hours ago"
}
]
};
// In a real app, you would use:
// const response = await axios.get(API_ENDPOINTS.alerts, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Update alerts container
alertsContainer.innerHTML = response.data.map(alert => `
<div class="p-4 ${alert.type === 'critical' ? 'alert-critical' : alert.type === 'warning' ? 'alert-warning' : 'alert-info'}">
<div class="flex justify-between items-start">
<div>
<div class="flex items-center">
<span class="health-indicator ${alert.type === 'critical' ? 'health-critical' : alert.type === 'warning' ? 'health-warning' : 'health-normal'}"></span>
<h4 class="font-medium">${alert.title}</h4>
</div>
<p class="text-sm text-gray-600 mt-1">${alert.description}</p>
</div>
<span class="text-xs text-gray-500">${alert.timestamp}</span>
</div>
<div class="mt-3 flex space-x-2">
<button class="px-3 py-1 ${
alert.type === 'critical' ? 'bg-red-100 text-red-700' :
alert.type === 'warning' ? 'bg-yellow-100 text-yellow-700' :
'bg-blue-100 text-blue-700'
} rounded-full text-xs">
${alert.type.charAt(0).toUpperCase() + alert.type.slice(1)}
</button>
<button class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-xs">
${alert.type === 'critical' ? 'Treatment' :
alert.type === 'warning' ? 'Monitor' :
'Checkup'}
</button>
</div>
</div>
`).join('');
} catch (error) {
console.error('Error fetching alerts:', error);
}
}
// Setup Socket.IO listeners for real-time updates
function setupSocketListeners() {
// Listen for new alerts
socket.on('new_alert', (alert) => {
const alertElement = document.createElement('div');
alertElement.className = `p-4 ${alert.type === 'critical' ? 'alert-critical' : alert.type === 'warning' ? 'alert-warning' : 'alert-info'}`;
alertElement.innerHTML = `
<div class="flex justify-between items-start">
<div>
<div class="flex items-center">
<span class="health-indicator ${alert.type === 'critical' ? 'health-critical' : alert.type === 'warning' ? 'health-warning' : 'health-normal'}"></span>
<h4 class="font-medium">${alert.title}</h4>
</div>
<p class="text-sm text-gray-600 mt-1">${alert.description}</p>
</div>
<span class="text-xs text-gray-500">Just now</span>
</div>
<div class="mt-3 flex space-x-2">
<button class="px-3 py-1 ${
alert.type === 'critical' ? 'bg-red-100 text-red-700' :
alert.type === 'warning' ? 'bg-yellow-100 text-yellow-700' :
'bg-blue-100 text-blue-700'
} rounded-full text-xs">
${alert.type.charAt(0).toUpperCase() + alert.type.slice(1)}
</button>
<button class="px-3 py-1 bg-gray-100 text-gray-700 rounded-full text-xs">
${alert.type === 'critical' ? 'Treatment' :
alert.type === 'warning' ? 'Monitor' :
'Checkup'}
</button>
</div>
`;
// Add new alert at the top
alertsContainer.insertBefore(alertElement, alertsContainer.firstChild);
// Show notification
showNotification(alert.title, alert.description);
});
// Listen for health metric updates
socket.on('health_metrics', (metrics) => {
// Update temperature chart
if (metrics.temperature) {
temperatureChart.data.labels = metrics.temperature.labels;
temperatureChart.data.datasets[0].data = metrics.temperature.data;
temperatureChart.update();
document.getElementById('avgTemp').textContent = `${metrics.temperature.avg}°C`;
document.getElementById('minTemp').textContent = `${metrics.temperature.min}°C`;
document.getElementById('maxTemp').textContent = `${metrics.temperature.max}°C`;
// Update indicator based on temperature status
const tempIndicator = document.getElementById('tempIndicator');
tempIndicator.className = 'health-indicator ' +
(metrics.temperature.status === 'normal' ? 'health-normal' :
metrics.temperature.status === 'warning' ? 'health-warning' : 'health-critical');
}
// Update heart rate chart
if (metrics.heartRate) {
heartRateChart.data.labels = metrics.heartRate.labels;
heartRateChart.data.datasets[0].data = metrics.heartRate.data;
heartRateChart.update();
document.getElementById('avgHeartRate').textContent = `${metrics.heartRate.avg} BPM`;
document.getElementById('minHeartRate').textContent = `${metrics.heartRate.min} BPM`;
document.getElementById('maxHeartRate').textContent = `${metrics.heartRate.max} BPM`;
// Update indicator based on heart rate status
const hrIndicator = document.getElementById('hrIndicator');
hrIndicator.className = 'health-indicator ' +
(metrics.heartRate.status === 'normal' ? 'health-normal' :
metrics.heartRate.status === 'warning' ? 'health-warning' : 'health-critical');
}
// Update milk production chart
if (metrics.milkProduction) {
milkChart.data.labels = metrics.milkProduction.labels;
milkChart.data.datasets[0].data = metrics.milkProduction.data;
milkChart.data.datasets[1].data = Array(metrics.milkProduction.data.length).fill(metrics.milkProduction.avg);
milkChart.update();
document.getElementById('avgMilk').textContent = `${metrics.milkProduction.avg} L/day`;
document.getElementById('minMilk').textContent = `${metrics.milkProduction.min} L/day`;
document.getElementById('maxMilk').textContent = `${metrics.milkProduction.max} L/day`;
// Update indicator based on milk production status
const milkIndicator = document.getElementById('milkIndicator');
milkIndicator.className = 'health-indicator ' +
(metrics.milkProduction.status === 'normal' ? 'health-normal' :
metrics.milkProduction.status === 'warning' ? 'health-warning' : 'health-critical');
}
});
}
// Show notification
function showNotification(title, message) {
// Check if browser supports notifications
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification");
return;
}
// Check if notification permissions are already granted
if (Notification.permission === "granted") {
// If it's okay let's create a notification
new Notification(title, { body: message });
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
new Notification(title, { body: message });
}
});
}
}
// AI Analysis Functions
runEyeAnalysis.addEventListener('click', async () => {
try {
// Show loading state
runEyeAnalysis.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Processing...';
runEyeAnalysis.disabled = true;
// Mock API call to TensorFlow model
const response = {
data: {
prediction: "Early signs of respiratory infection detected",
confidence: 87,
recommendations: [
"Isolate cow #142 for observation",
"Monitor temperature every 2 hours",
"Consult veterinarian if symptoms worsen"
],
imageAnalysis: {
eyeTemperature: 39.2,
normalRange: "38.0-38.5",
inflammationScore: 0.72
}
}
};
// In a real app, you would use:
// const response = await axios.post(API_ENDPOINTS.predict, {
// model: "eye_temperature",
// image: "base64_encoded_image_or_url"
// }, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Display results
aiResults.innerHTML = `
<div class="bg-white rounded-lg border p-6">
<div class="flex items-center mb-4">
<div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-eye text-purple-600 text-xl"></i>
</div>
<div>
<h4 class="font-medium text-lg">Eye Temperature Analysis Results</h4>
<p class="text-sm text-gray-600">Computer Vision Model (TensorFlow)</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
<div class="bg-gray-50 rounded-lg p-4">
<h5 class="font-medium text-gray-700 mb-2">Prediction</h5>
<p class="text-lg font-semibold text-purple-700">${response.data.prediction}</p>
<div class="mt-2">
<span class="text-xs bg-purple-100 text-purple-800 px-2 py-1 rounded-full">Confidence: ${response.data.confidence}%</span>
</div>
</div>
<div class="bg-gray-50 rounded-lg p-4">
<h5 class="font-medium text-gray-700 mb-2">Key Metrics</h5>
<div class="space-y-2">
<div class="flex justify-between">
<span class="text-gray-600">Eye Temperature:</span>
<span class="font-medium">${response.data.imageAnalysis.eyeTemperature}°C</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Normal Range:</span>
<span class="font-medium">${response.data.imageAnalysis.normalRange}°C</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Inflammation Score:</span>
<span class="font-medium">${response.data.imageAnalysis.inflammationScore}</span>
</div>
</div>
</div>
</div>
<div class="bg-blue-50 rounded-lg p-4">
<h5 class="font-medium text-gray-700 mb-2">Recommendations</h5>
<ul class="list-disc list-inside space-y-1">
${response.data.recommendations.map(rec => `<li class="text-gray-700">${rec}</li>`).join('')}
</ul>
</div>
</div>
`;
aiResults.classList.remove('hidden');
} catch (error) {
console.error('Error running eye analysis:', error);
aiResults.innerHTML = `
<div class="bg-red-50 rounded-lg border border-red-200 p-4">
<div class="flex items-center">
<div class="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-exclamation text-red-600"></i>
</div>
<div>
<h4 class="font-medium">Analysis Failed</h4>
<p class="text-sm text-gray-600">Please try again later</p>
</div>
</div>
</div>
`;
aiResults.classList.remove('hidden');
} finally {
// Reset button
runEyeAnalysis.innerHTML = 'Run Analysis';
runEyeAnalysis.disabled = false;
}
});
runAnomalyDetection.addEventListener('click', async () => {
try {
// Show loading state
runAnomalyDetection.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Processing...';
runAnomalyDetection.disabled = true;
// Mock API call to Scikit-learn model
const response = {
data: {
anomalies: [
{ cowId: "142", parameter: "Temperature", value: 39.8, normalRange: "38.0-39.0" },
{ cowId: "87", parameter: "Heart Rate", value: 78, normalRange: "60-75" },
{ cowId: "56", parameter: "Milk Production", value: 15.2, normalRange: "20-25" }
],
trends: [
"Temperature anomalies increasing in the afternoon",
"Milk production below average for 3 cows"
],
recommendations: [
"Check environmental conditions in barn",
"Review feeding schedule",
"Monitor cows #142, #87, #56 closely"
]
}
};
// In a real app, you would use:
// const response = await axios.post(API_ENDPOINTS.predict, {
// model: "anomaly_detection",
// metrics: "last_7_days_data"
// }, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Display results
aiResults.innerHTML = `
<div class="bg-white rounded-lg border p-6">
<div class="flex items-center mb-4">
<div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-wave-square text-blue-600 text-xl"></i>
</div>
<div>
<h4 class="font-medium text-lg">Anomaly Detection Results</h4>
<p class="text-sm text-gray-600">Scikit-learn Isolation Forest</p>
</div>
</div>
<div class="mb-6">
<h5 class="font-medium text-gray-700 mb-3">Detected Anomalies</h5>
<div class="space-y-3">
${response.data.anomalies.map(anomaly => `
<div class="bg-red-50 rounded-lg p-3 flex justify-between items-center">
<div>
<span class="font-medium">Cow #${anomaly.cowId}</span>
<span class="text-gray-600 mx-2">-</span>
<span>${anomaly.parameter}: ${anomaly.value}</span>
</div>
<div class="text-sm text-gray-600">
Normal: ${anomaly.normalRange}
</div>
</div>
`).join('')}
</div>
</div>
<div class="mb-6">
<h5 class="font-medium text-gray-700 mb-3">Trend Analysis</h5>
<div class="space-y-2">
${response.data.trends.map(trend => `
<div class="flex items-start">
<i class="fas fa-arrow-trend-up text-blue-500 mt-1 mr-2"></i>
<p class="text-gray-700">${trend}</p>
</div>
`).join('')}
</div>
</div>
<div class="bg-blue-50 rounded-lg p-4">
<h5 class="font-medium text-gray-700 mb-2">Recommendations</h5>
<ul class="list-disc list-inside space-y-1">
${response.data.recommendations.map(rec => `<li class="text-gray-700">${rec}</li>`).join('')}
</ul>
</div>
</div>
`;
aiResults.classList.remove('hidden');
} catch (error) {
console.error('Error running anomaly detection:', error);
aiResults.innerHTML = `
<div class="bg-red-50 rounded-lg border border-red-200 p-4">
<div class="flex items-center">
<div class="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-exclamation text-red-600"></i>
</div>
<div>
<h4 class="font-medium">Analysis Failed</h4>
<p class="text-sm text-gray-600">Please try again later</p>
</div>
</div>
</div>
`;
aiResults.classList.remove('hidden');
} finally {
// Reset button
runAnomalyDetection.innerHTML = 'Check Now';
runAnomalyDetection.disabled = false;
}
});
runProductionForecast.addEventListener('click', async () => {
try {
// Show loading state
runProductionForecast.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Processing...';
runProductionForecast.disabled = true;
// Mock API call to Prophet model
const response = {
data: {
forecast: [
{ date: "2023-07-01", value: 22.1 },
{ date: "2023-07-02", value: 21.8 },
{ date: "2023-07-03", value: 21.5 },
{ date: "2023-07-04", value: 21.2 },
{ date: "2023-07-05", value: 20.9 },
{ date: "2023-07-06", value: 20.7 },
{ date: "2023-07-07", value: 20.5 }
],
confidenceInterval: {
upper: [23.2, 23.0, 22.7, 22.4, 22.1, 21.9, 21.7],
lower: [21.0, 20.6, 20.3, 20.0, 19.7, 19.5, 19.3]
},
insights: [
"Expected 5% decrease in production over next week",
"Potential causes: heat stress, feed quality change"
],
recommendations: [
"Increase cooling measures in barn",
"Review feed composition",
"Monitor cows for signs of heat stress"
]
}
};
// In a real app, you would use:
// const response = await axios.post(API_ENDPOINTS.predict, {
// model: "production_forecast",
// timePeriod: "next_7_days"
// }, {
// headers: {
// 'Authorization': `Bearer ${AUTH_TOKEN}`
// }
// });
// Display results
aiResults.innerHTML = `
<div class="bg-white rounded-lg border p-6">
<div class="flex items-center mb-4">
<div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-chart-line text-green-600 text-xl"></i>
</div>
<div>
<h4 class="font-medium text-lg">Production Forecast</h4>
<p class="text-sm text-gray-600">Facebook Prophet Time Series</p>
</div>
</div>
<div class="mb-6">
<div class="chart-container" style="height: 250px;">
<canvas id="forecastChart"></canvas>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
<div>
<h5 class="font-medium text-gray-700 mb-3">Key Insights</h5>
<div class="space-y-2">
${response.data.insights.map(insight => `
<div class="flex items-start">
<i class="fas fa-lightbulb text-yellow-500 mt-1 mr-2"></i>
<p class="text-gray-700">${insight}</p>
</div>
`).join('')}
</div>
</div>
<div>
<h5 class="font-medium text-gray-700 mb-3">Forecast Summary</h5>
<div class="space-y-2">
<div class="flex justify-between">
<span class="text-gray-600">Current Production:</span>
<span class="font-medium">22.4 L/day</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Projected in 7 days:</span>
<span class="font-medium">20.5 L/day</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Expected Change:</span>
<span class="font-medium text-red-600">-8.5%</span>
</div>
</div>
</div>
</div>
<div class="bg-blue-50 rounded-lg p-4">
<h5 class="font-medium text-gray-700 mb-2">Recommendations</h5>
<ul class="list-disc list-inside space-y-1">
${response.data.recommendations.map(rec => `<li class="text-gray-700">${rec}</li>`).join('')}
</ul>
</div>
</div>
`;
// Initialize forecast chart
const forecastCtx = document.getElementById('forecastChart').getContext('2d');
new Chart(forecastCtx, {
type: 'line',
data: {
labels: response.data.forecast.map(item => item.date.split('-')[2] + ' Jul'),
datasets: [{
label: 'Forecast',
data: response.data.forecast.map(item => item.value),
borderColor: '#10B981',
backgroundColor: 'rgba(16, 185, 129, 0.1)',
borderWidth: 2,
tension: 0.3,
fill: true
}, {
label: 'Upper Bound',
data: response.data.confidenceInterval.upper,
borderColor: '#3B82F6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderWidth: 1,
borderDash: [5, 5],
pointRadius: 0
}, {
label: 'Lower Bound',
data: response.data.confidenceInterval.lower,
borderColor: '#3B82F6',
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderWidth: 1,
borderDash: [5, 5],
pointRadius: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom'
}
},
scales: {
y: {
title: {
display: true,
text: 'Milk Production (L/day)'
},
grid: {
display: false
}
},
x: {
grid: {
display: false
}
}
}
}
});
aiResults.classList.remove('hidden');
} catch (error) {
console.error('Error running production forecast:', error);
aiResults.innerHTML = `
<div class="bg-red-50 rounded-lg border border-red-200 p-4">
<div class="flex items-center">
<div class="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center mr-3">
<i class="fas fa-exclamation text-red-600"></i>
</div>
<div>
<h4 class="font-medium">Analysis Failed</h4>
<p class="text-sm text-gray-600">Please try again later</p>
</div>
</div>
</div>
`;
aiResults.classList.remove('hidden');
} finally {
// Reset button
runProductionForecast.innerHTML = 'Generate Forecast';
runProductionForecast.disabled = false;
}
});
// Request notification permission on page load
document.addEventListener('DOMContentLoaded', () => {
if ("Notification" in window) {
Notification.requestPermission();
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Preetham77Awaji/cowtest" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cattle Health Monitoring Dashboard</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.sidebar {
transition: all 0.3s ease;
}
.sidebar.collapsed {
width: 70px;
}
.sidebar.collapsed .nav-text {
display: none;
}
.sidebar.collapsed .logo-text {
display: none;
}
.sidebar.collapsed .nav-item {
justify-content: center;
}
.health-indicator {
width: 12px;
height: 12px;
border-radius: 50%;
display: inline-block;
margin-right: 6px;
}
.health-normal {
background-color: #10B981;
}
.health-warning {
background-color: #F59E0B;
}
.health-critical {
background-color: #EF4444;
}
.parameter-card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}
.cattle-card:hover {
transform: translateY(-3px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
.alert-critical {
border-left: 4px solid #EF4444;
}
.alert-warning {
border-left: 4px solid #F59E0B;
}
.alert-info {
border-left: 4px solid #3B82F6;
}
.chart-container {
position: relative;
height: 300px;
}
.ai-processing {
background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(236,253,245,1) 100%);
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.sidebar .nav-text {
display: none;
}
.sidebar .logo-text {
display: none;
}
.sidebar .nav-item {
justify-content: center;
}
}
</style>
</head>
<body class="bg-gray-50">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<div class="sidebar bg-green-800 text-white flex flex-col w-64">
<div class="p-4 flex items-center">
<i class="fas fa-cow text-2xl mr-3"></i>
<span class="logo-text text-xl font-bold">CattleHealth Pro</span>
</div>
<div class="flex-grow overflow-y-auto">