-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (155 loc) · 7.35 KB
/
script.js
File metadata and controls
175 lines (155 loc) · 7.35 KB
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
// Translations (Expandable to 10+ languages)
const translations = {
en: {
homeTitle: "Welcome to Smart Tourist Safety Monitoring System",
homeDesc: "A secure platform using AI, Blockchain, and Geo-Fencing for tourist safety in high-risk areas like Northeast India.",
touristTitle: "Digital Tourist ID Generation",
dashTitle: "Tourist Dashboard",
adminTitle: "Tourism & Police Dashboard",
// Add more as needed
},
hi: {
homeTitle: "स्मार्ट पर्यटक सुरक्षा निगरानी प्रणाली में आपका स्वागत है",
homeDesc: "उत्तर पूर्व भारत जैसे उच्च जोखिम वाले क्षेत्रों में पर्यटक सुरक्षा के लिए एआई, ब्लॉकचेन और जियो-फेंसिंग का उपयोग करने वाला एक सुरक्षित प्लेटफॉर्म।",
touristTitle: "डिजिटल पर्यटक आईडी जनरेशन",
dashTitle: "पर्यटक डैशबोर्ड",
adminTitle: "पर्यटन और पुलिस डैशबोर्ड",
}
};
// Current Language
let currentLang = 'en';
// Show/Hide Sections
function showSection(sectionId) {
document.querySelectorAll('section').forEach(sec => sec.classList.add('hidden'));
document.getElementById(sectionId).classList.remove('hidden');
updateTranslations();
}
// Language Selector
document.getElementById('languageSelector').addEventListener('change', (e) => {
currentLang = e.target.value;
updateTranslations();
});
function updateTranslations() {
const t = translations[currentLang];
document.getElementById('homeTitle').textContent = t.homeTitle;
document.getElementById('homeDesc').textContent = t.homeDesc;
document.getElementById('touristTitle').textContent = t.touristTitle;
document.getElementById('dashTitle').textContent = t.dashTitle;
document.getElementById('adminTitle').textContent = t.adminTitle;
// Update other elements dynamically if needed
}
// Digital ID Generation (Mock Blockchain: Hash + QR)
document.getElementById('idForm').addEventListener('submit', (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const data = {
name: document.getElementById('name').value,
kyc: document.getElementById('kyc').value,
arrival: document.getElementById('arrival').value,
departure: document.getElementById('departure').value,
itinerary: document.getElementById('itinerary').value,
emergency: document.getElementById('emergencyContact').value
};
// Mock Encryption (CryptoJS)
const encryptedData = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret-key').toString();
const digitalId = CryptoJS.SHA256(JSON.stringify(data)).toString().substring(0, 16); // Mock Hash ID
document.getElementById('digitalId').textContent = digitalId;
document.getElementById('validity').textContent = `${data.arrival} to ${data.departure}`;
document.getElementById('idOutput').classList.remove('hidden');
// Generate QR
const qrCanvas = document.getElementById('qrCode');
QRCode.toCanvas(qrCanvas, digitalId, { width: 200 });
// Store in localStorage (Mock DB)
localStorage.setItem('touristData', encryptedData);
calculateSafetyScore(data.itinerary);
startAnomalyDetection();
});
// Safety Score (Mock AI: Based on itinerary risk)
function calculateSafetyScore(itinerary) {
let score = 85; // Base
if (itinerary.toLowerCase().includes('forest') || itinerary.toLowerCase().includes('cave')) score -= 20;
if (itinerary.toLowerCase().includes('northeast')) score -= 10;
document.getElementById('safetyScore').textContent = `${score}/100`;
}
// Geo-location & Alerts
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((pos) => {
document.getElementById('location').textContent = `${pos.coords.latitude}, ${pos.coords.longitude}`;
checkGeoFencing(pos.coords.latitude, pos.coords.longitude);
});
} else {
document.getElementById('location').textContent = 'Geolocation not supported';
}
}
function checkGeoFencing(lat, lng) {
// Mock High-Risk Zones (e.g., Northeast forests)
const highRisk = { lat: 26.5, lng: 94.0 }; // Kaziranga approx
const distance = Math.sqrt((lat - highRisk.lat)**2 + (lng - highRisk.lng)**2);
if (distance < 0.5) {
document.getElementById('geoAlert').innerHTML = '<p style="color:red;">Alert: Entering High-Risk Zone!</p>';
}
}
// Panic Button
function panicAlert() {
getLocation(); // Share location
const alertMsg = 'Panic Alert Triggered! Location Shared to Police & Contacts.';
alert(alertMsg);
console.log('Alert Dispatched:', new Date().toISOString()); // Mock Dispatch
addAdminAlert(alertMsg);
}
// Anomaly Detection (Mock AI: Timer-based)
let anomalyTimer;
function startAnomalyDetection() {
anomalyTimer = setInterval(() => {
// Mock: Check inactivity (e.g., no location update in 5min)
if (Math.random() > 0.8) { // Random anomaly
document.getElementById('anomalyAlert').innerHTML = '<p style="color:orange;">Anomaly Detected: Deviation from Route!</p>';
addAdminAlert('Anomaly: Tourist deviated from itinerary.');
}
}, 10000); // Every 10s for demo
}
// Admin Login (Mock)
document.getElementById('adminLogin').addEventListener('submit', (e) => {
e.preventDefault();
if (document.querySelector('#adminLogin input').value === 'admin123') {
document.getElementById('adminLogin').classList.add('hidden');
document.getElementById('adminContent').classList.remove('hidden');
initDashboard();
} else {
alert('Invalid Password');
}
});
// Admin Dashboard
function initDashboard() {
// Heat Map (Mock Chart.js)
const heatCtx = document.getElementById('heatMap').getContext('2d');
new Chart(heatCtx, {
type: 'bar',
data: { labels: ['Guwahati', 'Kaziranga', 'High-Risk Zone'], datasets: [{ label: 'Tourist Density', data: [50, 30, 10] }] },
options: { title: { display: true, text: 'High-Risk Heat Map' } }
});
// Cluster Chart
const clusterCtx = document.getElementById('clusterChart').getContext('2d');
new Chart(clusterCtx, {
type: 'doughnut',
data: { labels: ['Safe Clusters', 'At-Risk'], datasets: [{ data: [70, 30] }] },
options: { title: { display: true, text: 'Tourist Clusters' } }
});
// IoT Toggle
document.getElementById('iotToggle').addEventListener('change', (e) => {
document.getElementById('iotStatus').textContent = e.target.checked ? 'Active: Monitoring Health/Location' : 'Inactive';
});
}
let alertCounter = 0;
function addAdminAlert(msg) {
const li = document.createElement('li');
li.textContent = `${++alertCounter}. ${msg} - ${new Date().toString()}`;
document.getElementById('alertList').appendChild(li);
}
function generateEFIR() {
alert('E-FIR Generated: Automated Report for Missing Tourist (Mock).');
addAdminAlert('E-FIR: Missing Person Case Logged.');
}
// Load Tourist Data on Dashboard Show
document.getElementById('tourist').addEventListener('transition')