File size: 4,335 Bytes
f49d1e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Usage analytics functionality
document.addEventListener('DOMContentLoaded', function() {
    initUsageChart();
});

// Initialize usage chart
function initUsageChart() {
    const ctx = document.getElementById('usage-chart').getContext('2d');
    
    // Generate sample data for last 30 days
    const labels = [];
    const data = [];
    const threats = [];
    
    for (let i = 29; i >= 0; i--) {
        const date = new Date();
        date.setDate(date.getDate() - i);
        labels.push(date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }));
        
        // Generate realistic usage data
        const baseUsage = 80 + Math.random() * 40;
        const weekendFactor = (date.getDay() === 0 || date.getDay() === 6) ? 0.6 : 1;
        const dailyUsage = Math.floor(baseUsage * weekendFactor);
        data.push(dailyUsage);
        threats.push(Math.floor(dailyUsage * 0.4 + Math.random() * 20));
    }

    new Chart(ctx, {
        type: 'line',
        data: {
            labels: labels,
            datasets: [
                {
                    label: 'Documents Processed',
                    data: data,
                    borderColor: '#3b82f6',
                    backgroundColor: 'rgba(59, 130, 246, 0.1)',
                    fill: true,
                    tension: 0.4
                },
                {
                    label: 'Threats Removed',
                    data: threats,
                    borderColor: '#ef4444',
                    backgroundColor: 'rgba(239, 68, 68, 0.1)',
                    fill: true,
                    tension: 0.4
                }
            ]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    position: 'top',
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    grid: {
                        color: 'rgba(0, 0, 0, 0.1)'
                    }
                },
                x: {
                    grid: {
                        color: 'rgba(0, 0, 0, 0.1)'
                    }
                }
            },
            elements: {
                point: {
                    radius: 3,
                    hoverRadius: 6
                }
            }
        }
    });
}

// Export usage data
function exportUsageData() {
    const usageData = {
        period: 'Last 30 days',
        documentsProcessed: 2847,
        threatsRemoved: 1423,
        averageProcessingTime: 2.3,
        dataCleaned: '847 MB',
        threatBreakdown: {
            'Zero-width characters': 687,
            'Embedded JavaScript': 423,
            'LSB steganography': 189,
            'VBA macros': 124
        },
        fileTypeBreakdown: {
            'PDF': 1245,
            'DOCX': 867,
            'Images': 432,
            'PPTX': 203,
            'Other': 100
        }
    };

    const csvContent = [
        'Metric,Value',
        `Documents Processed,${usageData.documentsProcessed}`,
        `Threats Removed,${usageData.threatsRemoved}`,
        `Average Processing Time,${usageData.averageProcessingTime}s`,
        `Data Cleaned,${usageData.dataCleaned}`,
        '',
        'Threat Types,Count',
        ...Object.entries(usageData.threatBreakdown).map(([type, count]) => `${type},${count}`),
        '',
        'File Types,Count',
        ...Object.entries(usageData.fileTypeBreakdown).map(([type, count]) => `${type},${count}`)
    ].join('\n');

    const blob = new Blob([csvContent], { type: 'text/csv' });
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = `wash-usage-${new Date().toISOString().split('T')[0]}.csv`;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    URL.revokeObjectURL(url);

    Wash.showNotification('Usage data exported successfully', 'success');
}

// Format number with commas
function formatNumber(num) {
    return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

// Calculate percentage change
function calculatePercentageChange(current, previous) {
    if (previous === 0) return current > 0 ? 100 : 0;
    return ((current - previous) / previous * 100).toFixed(1);
}