File size: 10,627 Bytes
c64d04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Gloire's data filtered from the dataset
const gloireData = [
    { id: 788, fileName: "/batch8-2/Introduction/001013_1.wav", duration: 573.045, hours: 0.15, category: "Introduction" },
    { id: 789, fileName: "/batch8-2/Live/001151_2.wav", duration: 915.325, hours: 0.25, category: "Live" },
    { id: 790, fileName: "/batch8-2/Live/001182_1.wav", duration: 583.006, hours: 0.16, category: "Live" },
    { id: 791, fileName: "/batch8-2/Introduction/000875_2.wav", duration: 751.13, hours: 0.21, category: "Introduction" },
    { id: 793, fileName: "/batch8-2/Introduction/001123_1.wav", duration: 584.418, hours: 0.16, category: "Introduction" },
    { id: 796, fileName: "/batch8-2/Introduction/001116_1.wav", duration: 563.582, hours: 0.15, category: "Introduction" },
    { id: 798, fileName: "/batch8-2/Introduction/001064_1.wav", duration: 571.121, hours: 0.15, category: "Introduction" },
    { id: 799, fileName: "/batch8-2/Travel/001197_3.wav", duration: 637.224, hours: 0.17, category: "Travel" },
    { id: 800, fileName: "/batch8-2/Introduction/000969_1.wav", duration: 598.764, hours: 0.16, category: "Introduction" },
    { id: 802, fileName: "/batch8-2/Introduction/000937_7.wav", duration: 598.852, hours: 0.16, category: "Introduction" },
    { id: 803, fileName: "/batch8-2/Live/001146_2.wav", duration: 820.033, hours: 0.22, category: "Live" },
    { id: 805, fileName: "/batch8-2/Live/001152_1.wav", duration: 567.14, hours: 0.15, category: "Live" },
    { id: 806, fileName: "/batch8-2/Live/001140_1.wav", duration: 563.636, hours: 0.15, category: "Live" },
    { id: 807, fileName: "/batch8-2/Introduction/000945_1.wav", duration: 598.72, hours: 0.16, category: "Introduction" },
    { id: 808, fileName: "/batch8-2/Introduction/000890_2.wav", duration: 570.264, hours: 0.15, category: "Introduction" },
    { id: 809, fileName: "/batch8-2/Introduction/000869_2.wav", duration: 521.006, hours: 0.14, category: "Introduction" },
    { id: 815, fileName: "/batch8-2/Live/001162_1.wav", duration: 561.573, hours: 0.15, category: "Live" },
    { id: 816, fileName: "/batch8-2/Live/001135_1.wav", duration: 499.299, hours: 0.13, category: "Live" },
    { id: 817, fileName: "/batch8-2/Introduction/000941_6.wav", duration: 422.017, hours: 0.11, category: "Introduction" },
    { id: 818, fileName: "/batch8-2/Introduction/000941_4.wav", duration: 482.013, hours: 0.13, category: "Introduction" },
    { id: 819, fileName: "/batch8-2/Introduction/000996_1.wav", duration: 569.876, hours: 0.15, category: "Introduction" },
    { id: 859, fileName: "/batch8-2/Introduction/000888_4.wav", duration: 628.822, hours: 0.17, category: "Introduction" },
    { id: 860, fileName: "/batch8-2/Live/001151_1.wav", duration: 523.671, hours: 0.14, category: "Live" },
    { id: 862, fileName: "/batch8-2/Introduction/000962_2.wav", duration: 973.874, hours: 0.27, category: "Introduction" },
    { id: 865, fileName: "/batch8-2/Introduction/000937_4.wav", duration: 598.684, hours: 0.16, category: "Introduction" },
    { id: 866, fileName: "/batch8-2/Introduction/000937_8.wav", duration: 692.453, hours: 0.19, category: "Introduction" },
    { id: 870, fileName: "/batch8-2/Introduction/000874_1.wav", duration: 598.757, hours: 0.16, category: "Introduction" },
    { id: 877, fileName: "/batch8-2/Introduction/001110_2.wav", duration: 787.51, hours: 0.21, category: "Introduction" },
    { id: 878, fileName: "/batch8-2/Introduction/000941_2.wav", duration: 598.826, hours: 0.16, category: "Introduction" },
    { id: 880, fileName: "/batch8-2/Live/001174_2.wav", duration: 544.139, hours: 0.15, category: "Live" },
    { id: 881, fileName: "/batch8-2/Live/001174_3.wav", duration: 977.914, hours: 0.27, category: "Live" },
    { id: 882, fileName: "/batch8-2/Introduction/000873_2.wav", duration: 833.855, hours: 0.23, category: "Introduction" },
    { id: 883, fileName: "/batch8-2/Travel/001196_1.wav", duration: 287.963, hours: 0.08, category: "Travel" },
    { id: 886, fileName: "/batch8-2/Introduction/001025_3.wav", duration: 652.289, hours: 0.18, category: "Introduction" },
    { id: 887, fileName: "/batch8-2/Introduction/000890_1.wav", duration: 582.613, hours: 0.16, category: "Introduction" },
    { id: 888, fileName: "/batch8-2/Travel/001221_1.wav", duration: 273.394, hours: 0.08, category: "Travel" },
    { id: 890, fileName: "/batch8-2/Live/001135_2.wav", duration: 804.498, hours: 0.22, category: "Live" },
    { id: 892, fileName: "/batch8-2/Introduction/001110_1.wav", duration: 583.554, hours: 0.16, category: "Introduction" },
    { id: 894, fileName: "/batch8-2/Introduction/001079_2.wav", duration: 886.687, hours: 0.24, category: "Introduction" },
    { id: 907, fileName: "/batch8-2/Introduction/000937_3.wav", duration: 527.853, hours: 0.14, category: "Introduction" },
    { id: 925, fileName: "/batch8-2/Travel/001195_1.wav", duration: 407.751, hours: 0.11, category: "Travel" },
    { id: 926, fileName: "/batch8-2/Introduction/000931_2.wav", duration: 647.034, hours: 0.17, category: "Introduction" },
    { id: 933, fileName: "/batch8-2/Introduction/001040_1.wav", duration: 572.237, hours: 0.15, category: "Introduction" },
    { id: 936, fileName: "/batch8-2/Introduction/000945_5.wav", duration: 510.083, hours: 0.14, category: "Introduction" },
    { id: 947, fileName: "/batch8-2/Introduction/001025_1.wav", duration: 590.477, hours: 0.16, category: "Introduction" },
    { id: 948, fileName: "/batch8-2/Introduction/001045_1.wav", duration: 582.894, hours: 0.16, category: "Introduction" },
    { id: 949, fileName: "/batch8-2/Introduction/001011_1.wav", duration: 587.805, hours: 0.16, category: "Introduction" },
    { id: 950, fileName: "/batch8-2/Travel/001211_1.wav", duration: 211.448, hours: 0.06, category: "Travel" },
    { id: 954, fileName: "/batch8-2/Travel/001223_1.wav", duration: 286.21, hours: 0.08, category: "Travel" },
    { id: 955, fileName: "/batch8-2/Live/001174_1.wav", duration: 572.809, hours: 0.15, category: "Live" },
    { id: 957, fileName: "/batch8-2/Introduction/000888_3.wav", duration: 598.78, hours: 0.16, category: "Introduction" },
    { id: 931, fileName: "/batch8-2/Travel/001220_1.wav", duration: 243.976, hours: 0.07, category: "Travel" },
    { id: 935, fileName: "/batch8-2/Travel/001218_2.wav", duration: 144.965, hours: 0.04, category: "Travel" }
];

// DOM elements
const dataTable = document.getElementById('dataTable');
const totalHoursElement = document.getElementById('totalHours');
const totalFilesElement = document.getElementById('totalFiles');
const avgDurationElement = document.getElementById('avgDuration');
const longestFileElement = document.getElementById('longestFile');
const searchInput = document.getElementById('searchInput');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('prevBtn');
const startItemElement = document.getElementById('startItem');
const endItemElement = document.getElementById('endItem');
const totalItemsElement = document.getElementById('totalItems');

// Pagination variables
let currentPage = 1;
const itemsPerPage = 10;
let filteredData = [...gloireData];

// Initialize the page
function init() {
    calculateStats();
    renderTable();
    setupEventListeners();
}

// Calculate statistics
function calculateStats() {
    const totalHours = gloireData.reduce((sum, item) => sum + item.hours, 0);
    const totalDuration = gloireData.reduce((sum, item) => sum + item.duration, 0);
    const avgDuration = totalDuration / gloireData.length / 60; // Convert to minutes
    const longestFile = Math.max(...gloireData.map(item => item.hours));
    
    totalHoursElement.textContent = totalHours.toFixed(2);
    totalFilesElement.textContent = gloireData.length;
    avgDurationElement.textContent = (avgDuration).toFixed(2);
    longestFileElement.textContent = longestFile.toFixed(2);
}

// Render table with pagination
function renderTable() {
    dataTable.innerHTML = '';
    
    const startIndex = (currentPage - 1) * itemsPerPage;
    const endIndex = Math.min(startIndex + itemsPerPage, filteredData.length);
    
    for (let i = startIndex; i < endIndex; i++) {
        const item = filteredData[i];
        const row = document.createElement('tr');
        
        row.innerHTML = `
            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${item.id}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.fileName}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.duration.toFixed(3)}</td>
            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${item.hours.toFixed(2)}</td>
            <td class="px-6 py-4 whitespace-nowrap">
                <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full 
                    ${getCategoryColor(item.category)}">
                    ${item.category}
                </span>
            </td>
        `;
        
        dataTable.appendChild(row);
    }
    
    // Update pagination info
    startItemElement.textContent = startIndex + 1;
    endItemElement.textContent = endIndex;
    totalItemsElement.textContent = filteredData.length;
    
    // Update button states
    prevBtn.disabled = currentPage === 1;
    nextBtn.disabled = endIndex >= filteredData.length;
}

// Get color class based on category
function getCategoryColor(category) {
    switch(category) {
        case 'Introduction': return 'bg-blue-100 text-blue-800';
        case 'Live': return 'bg-green-100 text-green-800';
        case 'Travel': return 'bg-purple-100 text-purple-800';
        default: return 'bg-gray-100 text-gray-800';
    }
}

// Setup event listeners
function setupEventListeners() {
    // Search functionality
    searchInput.addEventListener('input', (e) => {
        const searchTerm = e.target.value.toLowerCase();
        filteredData = gloireData.filter(item => 
            item.fileName.toLowerCase().includes(searchTerm) || 
            item.category.toLowerCase().includes(searchTerm)
        );
        currentPage = 1;
        renderTable();
    });
    
    // Pagination buttons
    prevBtn.addEventListener('click', () => {
        if (currentPage > 1) {
            currentPage--;
            renderTable();
        }
    });
    
    nextBtn.addEventListener('click', () => {
        const totalPages = Math.ceil(filteredData.length / itemsPerPage);
        if (currentPage < totalPages) {
            currentPage++;
            renderTable();
        }
    });
}

// Initialize the app
document.addEventListener('DOMContentLoaded', init);