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
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Yahoo Webscope Anomaly Detection Dashboard</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.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;
        }
        .chart-container {
            position: relative;
            height: 300px;
            width: 100%;
        }
        .anomaly-marker {
            position: absolute;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background-color: #ef4444;
            transform: translate(-50%, -50%);
            z-index: 10;
        }
        .tooltip {
            position: absolute;
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            pointer-events: none;
            z-index: 100;
            opacity: 0;
            transition: opacity 0.3s;
        }
    </style>
</head>
<body class="bg-gray-100 font-sans">
    <div class="flex h-screen overflow-hidden">
        <!-- Sidebar -->
        <div class="sidebar bg-indigo-800 text-white w-64 flex-shrink-0">
            <div class="p-4 border-b border-indigo-700">
                <h1 class="text-xl font-bold flex items-center">
                    <i class="fas fa-chart-line mr-2"></i>
                    AnomalyScope
                </h1>
            </div>
            <nav class="p-4">
                <div class="mb-6">
                    <h2 class="text-sm uppercase text-indigo-300 font-semibold mb-2">Datasets</h2>
                    <ul>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded bg-indigo-700">
                                <i class="fas fa-server mr-3"></i>
                                A1 Benchmark
                            </a>
                        </li>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-server mr-3"></i>
                                A2 Benchmark
                            </a>
                        </li>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-server mr-3"></i>
                                A3 Benchmark
                            </a>
                        </li>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-server mr-3"></i>
                                A4 Benchmark
                            </a>
                        </li>
                    </ul>
                </div>
                <div>
                    <h2 class="text-sm uppercase text-indigo-300 font-semibold mb-2">Analysis Tools</h2>
                    <ul>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-search mr-3"></i>
                                Anomaly Detection
                            </a>
                        </li>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-chart-bar mr-3"></i>
                                Time Series Analysis
                            </a>
                        </li>
                        <li class="mb-2">
                            <a href="#" class="flex items-center p-2 rounded hover:bg-indigo-700">
                                <i class="fas fa-cogs mr-3"></i>
                                Model Settings
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>
        </div>

        <!-- Main Content -->
        <div class="flex-1 overflow-auto">
            <!-- Header -->
            <header class="bg-white shadow-sm p-4 flex justify-between items-center">
                <div>
                    <h2 class="text-xl font-semibold text-gray-800">Yahoo Webscope Anomaly Detection</h2>
                    <p class="text-sm text-gray-500">Analyzing time series anomalies in real-world data</p>
                </div>
                <div class="flex items-center space-x-4">
                    <div class="relative">
                        <input type="text" placeholder="Search..." class="pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
                    </div>
                    <div class="flex items-center space-x-2">
                        <div class="w-8 h-8 rounded-full bg-indigo-500 flex items-center justify-center text-white">
                            <i class="fas fa-user"></i>
                        </div>
                        <span class="text-sm font-medium">Analyst</span>
                    </div>
                </div>
            </header>

            <!-- Dashboard Content -->
            <main class="p-6">
                <!-- Stats Cards -->
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6">
                    <div class="bg-white rounded-lg shadow p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium text-gray-500">Total Data Points</p>
                                <p class="text-2xl font-bold text-gray-800">67,000</p>
                            </div>
                            <div class="p-3 rounded-full bg-indigo-100 text-indigo-600">
                                <i class="fas fa-database text-xl"></i>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium text-gray-500">Anomalies Detected</p>
                                <p class="text-2xl font-bold text-gray-800">1,450</p>
                            </div>
                            <div class="p-3 rounded-full bg-red-100 text-red-600">
                                <i class="fas fa-exclamation-triangle text-xl"></i>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium text-gray-500">Detection Accuracy</p>
                                <p class="text-2xl font-bold text-gray-800">92.3%</p>
                            </div>
                            <div class="p-3 rounded-full bg-green-100 text-green-600">
                                <i class="fas fa-check-circle text-xl"></i>
                            </div>
                        </div>
                    </div>
                    <div class="bg-white rounded-lg shadow p-6">
                        <div class="flex items-center justify-between">
                            <div>
                                <p class="text-sm font-medium text-gray-500">Processing Time</p>
                                <p class="text-2xl font-bold text-gray-800">1.2s</p>
                            </div>
                            <div class="p-3 rounded-full bg-blue-100 text-blue-600">
                                <i class="fas fa-stopwatch text-xl"></i>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Main Chart -->
                <div class="bg-white rounded-lg shadow p-6 mb-6">
                    <div class="flex justify-between items-center mb-4">
                        <h3 class="text-lg font-semibold text-gray-800">Time Series with Anomaly Detection</h3>
                        <div class="flex space-x-2">
                            <select class="border rounded-md px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <option>Last 7 days</option>
                                <option>Last 30 days</option>
                                <option selected>Last 90 days</option>
                                <option>Last year</option>
                            </select>
                            <button class="bg-indigo-600 text-white px-3 py-1 rounded-md text-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <i class="fas fa-download mr-1"></i> Export
                            </button>
                        </div>
                    </div>
                    <div class="chart-container">
                        <canvas id="mainChart"></canvas>
                    </div>
                </div>

                <!-- Anomaly Details and Model Performance -->
                <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
                    <!-- Anomaly Details -->
                    <div class="bg-white rounded-lg shadow p-6 col-span-2">
                        <h3 class="text-lg font-semibold text-gray-800 mb-4">Recent Anomalies</h3>
                        <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">Timestamp</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Value</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Expected</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Deviation</th>
                                        <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Type</th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white divide-y divide-gray-200">
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2023-05-15 14:30</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">142.56</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">98.23</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-red-600 font-medium">+45.1%</td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Spike</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2023-05-12 09:15</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">32.11</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">68.45</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-red-600 font-medium">-53.1%</td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Drop</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2023-05-10 18:45</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">215.78</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">102.34</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-red-600 font-medium">+110.8%</td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Spike</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2023-05-08 11:20</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">45.67</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">72.89</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-red-600 font-medium">-37.3%</td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Drop</span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">2023-05-05 16:10</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">178.92</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">95.67</td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-red-600 font-medium">+87.0%</td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">Spike</span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>

                    <!-- Model Performance -->
                    <div class="bg-white rounded-lg shadow p-6">
                        <h3 class="text-lg font-semibold text-gray-800 mb-4">Model Performance</h3>
                        <div class="space-y-4">
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">Precision</span>
                                    <span class="text-sm font-medium text-gray-700">89.2%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-blue-600 h-2.5 rounded-full" style="width: 89.2%"></div>
                                </div>
                            </div>
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">Recall</span>
                                    <span class="text-sm font-medium text-gray-700">92.3%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-green-600 h-2.5 rounded-full" style="width: 92.3%"></div>
                                </div>
                            </div>
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="text-sm font-medium text-gray-700">F1 Score</span>
                                    <span class="text-sm font-medium text-gray-700">90.7%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2.5">
                                    <div class="bg-purple-600 h-2.5 rounded-full" style="width: 90.7%"></div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <h4 class="text-md font-medium text-gray-700 mb-2">Confusion Matrix</h4>
                            <div class="grid grid-cols-3 gap-1 text-center text-xs">
                                <div class="p-2"></div>
                                <div class="p-2 font-medium">Predicted Anomaly</div>
                                <div class="p-2 font-medium">Predicted Normal</div>
                                <div class="p-2 font-medium">Actual Anomaly</div>
                                <div class="p-2 bg-green-100 text-green-800 rounded">1,234 (TP)</div>
                                <div class="p-2 bg-red-100 text-red-800 rounded">102 (FN)</div>
                                <div class="p-2 font-medium">Actual Normal</div>
                                <div class="p-2 bg-red-100 text-red-800 rounded">114 (FP)</div>
                                <div class="p-2 bg-green-100 text-green-800 rounded">65,550 (TN)</div>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <button class="w-full bg-indigo-600 text-white py-2 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500">
                                <i class="fas fa-cog mr-2"></i> Tune Model Parameters
                            </button>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script>
        // Generate sample data for the chart
        function generateTimeSeriesData() {
            const data = [];
            const anomalies = [];
            let value = 100;
            
            for (let i = 0; i < 90; i++) {
                // Base value with some noise
                value = 100 + Math.sin(i / 5) * 30 + (Math.random() * 10 - 5);
                
                // Add some anomalies
                if (i === 15 || i === 45 || i === 70) {
                    value += 60 + Math.random() * 40;
                    anomalies.push({x: i, y: value});
                } else if (i === 30 || i === 60) {
                    value -= 50 + Math.random() * 30;
                    anomalies.push({x: i, y: value});
                }
                
                data.push(value);
            }
            
            return {data, anomalies};
        }

        // Initialize the main chart
        function initMainChart() {
            const {data, anomalies} = generateTimeSeriesData();
            const ctx = document.getElementById('mainChart').getContext('2d');
            
            const chart = new Chart(ctx, {
                type: 'line',
                data: {
                    labels: Array.from({length: 90}, (_, i) => `Day ${i+1}`),
                    datasets: [
                        {
                            label: 'Time Series Data',
                            data: data,
                            borderColor: 'rgb(79, 70, 229)',
                            backgroundColor: 'rgba(79, 70, 229, 0.1)',
                            borderWidth: 2,
                            fill: true,
                            tension: 0.1
                        },
                        {
                            label: 'Anomalies',
                            data: data.map((val, idx) => {
                                const anomaly = anomalies.find(a => a.x === idx);
                                return anomaly ? anomaly.y : null;
                            }),
                            pointBackgroundColor: 'rgb(239, 68, 68)',
                            pointRadius: 5,
                            pointHoverRadius: 7,
                            showLine: false
                        }
                    ]
                },
                options: {
                    responsive: true,
                    maintainAspectRatio: false,
                    plugins: {
                        tooltip: {
                            mode: 'index',
                            intersect: false,
                        },
                        legend: {
                            position: 'top',
                        }
                    },
                    scales: {
                        y: {
                            beginAtZero: false,
                            grid: {
                                color: 'rgba(0, 0, 0, 0.05)',
                            }
                        },
                        x: {
                            grid: {
                                display: false
                            }
                        }
                    },
                    interaction: {
                        mode: 'nearest',
                        axis: 'x',
                        intersect: false
                    }
                }
            });
            
            // Add custom tooltips for anomalies
            const chartContainer = document.querySelector('.chart-container');
            anomalies.forEach(anomaly => {
                const marker = document.createElement('div');
                marker.className = 'anomaly-marker';
                marker.style.left = `${(anomaly.x / 89) * 100}%`;
                marker.style.top = `${100 - ((anomaly.y - 50) / 200) * 100}%`;
                
                const tooltip = document.createElement('div');
                tooltip.className = 'tooltip';
                tooltip.innerHTML = `
                    <div class="font-bold">Anomaly Detected</div>
                    <div>Value: ${anomaly.y.toFixed(2)}</div>
                    <div>Day ${anomaly.x + 1}</div>
                `;
                
                marker.addEventListener('mouseover', () => {
                    tooltip.style.opacity = '1';
                    tooltip.style.left = `${(anomaly.x / 89) * 100 + 2}%`;
                    tooltip.style.top = `${100 - ((anomaly.y - 50) / 200) * 100 - 10}%`;
                });
                
                marker.addEventListener('mouseout', () => {
                    tooltip.style.opacity = '0';
                });
                
                chartContainer.appendChild(marker);
                chartContainer.appendChild(tooltip);
            });
        }

        // Initialize when DOM is loaded
        document.addEventListener('DOMContentLoaded', function() {
            initMainChart();
            
            // Add click event to sidebar items
            document.querySelectorAll('.sidebar a').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    document.querySelectorAll('.sidebar a').forEach(a => a.classList.remove('bg-indigo-700'));
                    this.classList.add('bg-indigo-700');
                });
            });
        });
    </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=Daniela-C/yahoo-webscope-anomaly-detection-dataset" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>