generated from sdhutchins/base-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_html_table.py
More file actions
371 lines (333 loc) · 11.3 KB
/
create_html_table.py
File metadata and controls
371 lines (333 loc) · 11.3 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
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
#!/usr/bin/env python3
"""
Generate HTML table from faculty-student data for GitHub Pages hosting.
Creates a responsive, searchable table with faculty mentoring relationships.
"""
import json
from pathlib import Path
from typing import List, Dict
def create_html_table(faculty_data: List[Dict]) -> str:
"""
Create HTML table with faculty-student mentoring data.
Args:
faculty_data: List of faculty objects with students
Returns:
Complete HTML document as string
"""
html_template = f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UAB Faculty Mentoring Relationships</title>
<style>
body {{
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}}
.container {
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 {
margin: 0;
font-size: 2.5em;
font-weight: 300;
}
.header p {
margin: 10px 0 0 0;
opacity: 0.9;
font-size: 1.1em;
}
.controls {
padding: 20px 30px;
background: #f8f9fa;
border-bottom: 1px solid #dee2e6;
}
.search-box {
width: 100%;
max-width: 400px;
padding: 12px 16px;
border: 2px solid #ddd;
border-radius: 6px;
font-size: 16px;
outline: none;
transition: border-color 0.3s;
}
.search-box:focus {
border-color: #1e3c72;
}
.stats {
margin-top: 15px;
font-size: 14px;
color: #666;
}
.table-container {
overflow-x: auto;
max-height: 70vh;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
th {
background: #f8f9fa;
padding: 15px 12px;
text-align: left;
font-weight: 600;
color: #495057;
border-bottom: 2px solid #dee2e6;
position: sticky;
top: 0;
z-index: 10;
}
td {
padding: 12px;
border-bottom: 1px solid #dee2e6;
vertical-align: top;
}
tr:hover {
background-color: #f8f9fa;
}
.faculty-name {
font-weight: 600;
color: #1e3c72;
}
.research-tags {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.tag {
background: #e3f2fd;
color: #1976d2;
padding: 2px 8px;
border-radius: 12px;
font-size: 11px;
white-space: nowrap;
}
.student-list {
margin: 0;
padding: 0;
list-style: none;
}
.student-item {
margin-bottom: 8px;
padding: 8px;
background: #f8f9fa;
border-radius: 4px;
border-left: 3px solid #28a745;
}
.student-name {
font-weight: 500;
color: #333;
}
.student-role {
font-size: 12px;
color: #666;
margin-top: 2px;
}
.student-status {
font-size: 11px;
color: #999;
margin-top: 2px;
}
.status-current {
color: #28a745;
}
.status-completed {
color: #6c757d;
}
.status-unknown {
color: #ffc107;
}
.no-results {
text-align: center;
padding: 40px;
color: #666;
font-style: italic;
}
@media (max-width: 768px) {
.header h1 {
font-size: 2em;
}
th, td {
padding: 8px 6px;
font-size: 13px;
}
.research-tags {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>UAB Faculty Mentoring Relationships</h1>
<p>Faculty members and their graduate student mentoring relationships</p>
</div>
<div class="controls">
<input type="text" id="searchInput" class="search-box" placeholder="Search faculty names, research areas, or student names...">
<div class="stats">
<span id="totalFaculty">Total Faculty: {total_faculty}</span> |
<span id="totalStudents">Total Students: {total_students}</span> |
<span id="showingResults">Showing: {total_faculty} faculty</span>
</div>
</div>
<div class="table-container">
<table id="facultyTable">
<thead>
<tr>
<th>Faculty Name</th>
<th>Research Areas</th>
<th>Students</th>
</tr>
</thead>
<tbody>
{table_rows}
</tbody>
</table>
</div>
</div>
<script>
const facultyData = {faculty_data_json};
function updateTable(filteredData) {
const tbody = document.querySelector('#facultyTable tbody');
const showingResults = document.getElementById('showingResults');
if (filteredData.length === 0) {
tbody.innerHTML = '<tr><td colspan="3" class="no-results">No faculty found matching your search criteria.</td></tr>';
showingResults.textContent = 'Showing: 0 faculty';
return;
}
tbody.innerHTML = filteredData.map(faculty => `
<tr>
<td class="faculty-name">${faculty.userName}</td>
<td>
<div class="research-tags">
${faculty.researchTags.map(tag => `<span class="tag">${tag}</span>`).join('')}
</div>
</td>
<td>
<ul class="student-list">
${faculty.students.map(student => `
<li class="student-item">
<div class="student-name">${student.name}</div>
<div class="student-role">${student.role}</div>
<div class="student-status ${getStatusClass(student.status)}">${student.status}</div>
</li>
`).join('')}
</ul>
</td>
</tr>
`).join('');
showingResults.textContent = `Showing: ${filteredData.length} faculty`;
}
function getStatusClass(status) {
if (status.includes('Current')) return 'status-current';
if (status.includes('graduated') || status.includes('No longer')) return 'status-completed';
return 'status-unknown';
}
function filterData(searchTerm) {
if (!searchTerm) return facultyData;
const term = searchTerm.toLowerCase();
return facultyData.filter(faculty => {
// Search faculty name
if (faculty.userName.toLowerCase().includes(term)) return true;
// Search research tags
if (faculty.researchTags.some(tag => tag.toLowerCase().includes(term))) return true;
// Search student names
if (faculty.students.some(student => student.name.toLowerCase().includes(term))) return true;
return false;
});
}
// Search functionality
document.getElementById('searchInput').addEventListener('input', function(e) {
const searchTerm = e.target.value;
const filteredData = filterData(searchTerm);
updateTable(filteredData);
});
// Initialize table
updateTable(facultyData);
</script>
</body>
</html>
"""
# Generate table rows
table_rows = []
for faculty in faculty_data:
# Create research tags HTML
tags_html = ''.join([f'<span class="tag">{tag}</span>' for tag in faculty['researchTags']])
# Create students HTML
students_html = ''
for student in faculty['students']:
status_class = 'status-unknown'
if 'Current' in student['status']:
status_class = 'status-current'
elif 'graduated' in student['status'] or 'No longer' in student['status']:
status_class = 'status-completed'
students_html += f'''
<li class="student-item">
<div class="student-name">{student['name']}</div>
<div class="student-role">{student['role']}</div>
<div class="student-status {status_class}">{student['status']}</div>
</li>
'''
table_rows.append(f'''
<tr>
<td class="faculty-name">{faculty['userName']}</td>
<td>
<div class="research-tags">
{tags_html}
</div>
</td>
<td>
<ul class="student-list">
{students_html}
</ul>
</td>
</tr>
''')
# Calculate totals
total_faculty = len(faculty_data)
total_students = sum(len(f['students']) for f in faculty_data)
# Create the HTML
html_content = html_template.format(
total_faculty=total_faculty,
total_students=total_students,
table_rows=''.join(table_rows),
faculty_data_json=json.dumps(faculty_data)
)
return html_content
def main():
"""Generate HTML table from faculty-student data."""
print("Loading faculty-student data...")
# Load the processed data
with open("data/processed/faculty_students.json", "r") as f:
faculty_data = json.load(f)
print(f"Loaded {len(faculty_data)} faculty records")
# Generate HTML
print("Generating HTML table...")
html_content = create_html_table(faculty_data)
# Save HTML file
output_file = Path("data/processed/faculty_mentoring_table.html")
with open(output_file, "w") as f:
f.write(html_content)
print(f"HTML table saved to: {output_file}")
print("You can now host this file on GitHub Pages!")
if __name__ == "__main__":
main()