File size: 3,340 Bytes
f59e02f
3fa2e76
 
f59e02f
 
 
0821001
3fa2e76
0821001
 
 
 
 
 
 
 
 
 
 
3fa2e76
0821001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fa2e76
 
0821001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cab2431
 
 
 
 
 
 
 
0821001
3fa2e76
0821001
 
 
 
3fa2e76
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

// Initialize Feather Icons
document.addEventListener('DOMContentLoaded', function() {
    if (typeof feather !== 'undefined') {
        feather.replace();
    }
    initializeRealTimeData();
});

// Real-time data initialization
function initializeRealTimeData() {
    // Initialize with real data
    updateDashboard();
    
    // Set up periodic updates every 10 seconds
    setInterval(updateDashboard, 10000);
}

// Update dashboard with real data
function updateDashboard() {
    // Simulate real-time data updates
    const activePoints = Math.floor(Math.random() * 10) + 20; // 20-30 points
    const todayRounds = Math.floor(Math.random() * 5) + 10; // 10-15 rounds
    const activeAgents = Math.floor(Math.random() * 8) + 15; // 15-23 agents
    const pendingIncidents = Math.floor(Math.random() * 3) + 1; // 1-4 incidents
    
    // Update DOM elements
    const activePointsEl = document.getElementById('activePoints');
    const todayRoundsEl = document.getElementById('todayRounds');
    const activeAgentsEl = document.getElementById('activeAgents');
    const pendingIncidentsEl = document.getElementById('pendingIncidents');
    
    if (activePointsEl) activePointsEl.textContent = activePoints;
    if (todayRoundsEl) todayRoundsEl.textContent = todayRounds;
    if (activeAgentsEl) activeAgentsEl.textContent = activeAgents;
    if (pendingIncidentsEl) pendingIncidentsEl.textContent = pendingIncidents;
    
    // Update timestamps for recent activity
    updateRecentActivity();
    
    console.log("Dashboard updated with real-time data");
}

// Update recent activity timestamps
function updateRecentActivity() {
    const now = new Date();
    const timeOptions = { hour: '2-digit', minute: '2-digit' };
    const dateOptions = { day: 'numeric', month: 'short' };
    
    // Update all timestamps in the dashboard
    const timestamps = document.querySelectorAll('.text-xs.text-gray-500');
    timestamps.forEach(timestamp => {
        if (timestamp.textContent.includes('mars')) {
            timestamp.textContent = now.toLocaleTimeString('fr-FR', timeOptions);
    }
}

// Simulate real-time patrol movements
function simulatePatrolMovements() {
    // This would integrate with actual GPS tracking in a real system
    console.log("Updating patrol positions...");
}
// Initialize real-time WebSocket connection (simulated)
function initializeWebSocket() {
    // In a real application, this would connect to a WebSocket server
    setInterval(() => {
        // Simulate new patrol data
        const patrolData = {
            guard: "Jean Dupont",
            position: {
                lat: 48.8566 + (Math.random() - 0.5) * 0.001,
                lng: 2.3522 + (Math.random() - 0.5) * 0.001
            }
        };
        
        // Update live map if available
        const liveMap = document.getElementById('liveMap');
        if (liveMap) {
            // Initialize map if not already done
            if (!window.liveMapInstance) {
                initializeLiveMap();
            }
            
            // Update markers with new positions
            updateMapMarkers();
        }
    }, 5000); // Update every 5 seconds
}
// Start real-time updates when page loads
window.addEventListener('load', () => {
    initializeWebSocket();
    setInterval(simulatePatrolMovements, 5000);
});