-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathevaluation_interface.html
More file actions
232 lines (199 loc) · 8.69 KB
/
evaluation_interface.html
File metadata and controls
232 lines (199 loc) · 8.69 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Quality Assessment</title>
<style>
body { font-family: sans-serif; display: flex; flex-direction: column; height: 100vh; margin: 0; }
#controls { padding: 10px; background: #f0f0f0; border-bottom: 1px solid #ccc; text-align: center; }
#main-container { display: flex; flex: 1; overflow: hidden; }
#viewer { flex: 1; border: none; }
#sidebar { width: 400px; padding: 10px; border-left: 1px solid #ccc; overflow-y: auto; background: #fafafa; }
#scenario-text { white-space: pre-wrap; font-family: monospace; font-size: 12px; }
.button { padding: 8px 12px; margin: 0 5px; cursor: pointer; }
.high { background-color: #4CAF50; color: white; border: none; }
.low { background-color: #f44336; color: white; border: none; }
#stats { margin-top: 10px; font-weight: bold; }
</style>
</head>
<body>
<div id="controls">
<span id="progress"></span>
<button class="button" onclick="navigate(-1)">Previous</button>
<button class="button" onclick="navigate(1)">Next</button>
<button class="button" onclick="navigateToNextUnassessed()">Next Unassessed</button>
<button class="button high" onclick="assess('High')">High Quality</button>
<button class="button low" onclick="assess('Low')">Low Quality</button>
<button class="button" onclick="exportToCSV()">Export to CSV</button>
<div id="stats"></div>
</div>
<div id="main-container">
<iframe id="viewer"></iframe>
<div id="sidebar">
<h3>Scenario Description</h3>
<p id="scenario-text">Loading...</p>
</div>
</div>
<script>
// File format: task_{task_id}_{domain}_{timestamp}.json and task_{task_id}_{domain}_interactive_{timestamp}.html
let samples = [];
let currentIndex = 0;
let assessments = {};
async function scanOutputDirectory() {
// Load file list from list_files.json
try {
const response = await fetch('data_generation/list_files.json');
const fileList = await response.json();
return fileList;
} catch (e) {
console.log('Unable to load file list. Please run generate_file_list.py first.');
return [];
}
}
function setupSamples(fileList = []) {
if (fileList.length === 0) {
console.log('File list is empty');
}
const fileMap = {};
// Parse file format: task_{task_id}_{domain}_{timestamp}.json and task_{task_id}_{domain}_interactive_{timestamp}.html
fileList.forEach(file => {
// Match JSON files: task_0960_Transportation_20251101_075543.json
const jsonMatch = file.match(/^(task_\d+)_(.+?)_(\d{8}_\d{6})\.json$/);
// Match HTML files: task_0960_Transportation_interactive_20251101_075543.html
const htmlMatch = file.match(/^(task_\d+)_(.+?)_interactive_(\d{8}_\d{6})\.html$/);
if (jsonMatch) {
const taskId = jsonMatch[1];
const domain = jsonMatch[2];
const timestamp = jsonMatch[3];
const key = `${taskId}_${domain}_${timestamp}`;
if (!fileMap[key]) {
fileMap[key] = { taskId, domain, timestamp };
}
fileMap[key].json = 'data_generation/batch_output/' + file;
} else if (htmlMatch) {
const taskId = htmlMatch[1];
const domain = htmlMatch[2];
const timestamp = htmlMatch[3];
const key = `${taskId}_${domain}_${timestamp}`;
if (!fileMap[key]) {
fileMap[key] = { taskId, domain, timestamp };
}
fileMap[key].html = 'data_generation/batch_output/' + file;
}
});
samples = Object.keys(fileMap)
.filter(key => fileMap[key].json && fileMap[key].html)
.map(key => ({
id: key,
taskId: fileMap[key].taskId,
domain: fileMap[key].domain,
timestamp: fileMap[key].timestamp,
jsonFile: fileMap[key].json,
htmlFile: fileMap[key].html
}))
.sort((a, b) => {
// Sort by taskId
const taskNumA = parseInt(a.taskId.replace('task_', ''));
const taskNumB = parseInt(b.taskId.replace('task_', ''));
if (taskNumA !== taskNumB) return taskNumA - taskNumB;
return a.timestamp.localeCompare(b.timestamp);
});
assessments = JSON.parse(localStorage.getItem('assessments_v3')) || {};
samples.forEach(sample => {
if (!assessments[sample.id]) {
assessments[sample.id] = 'Unassessed';
}
});
if (samples.length > 0) {
loadSample(0);
} else {
document.getElementById('scenario-text').textContent =
'❌ No data files found.\n\n' +
'Please ensure:\n' +
'1. Run generate_file_list.py to generate the file list\n' +
'2. File format is correct:\n' +
' - task_{id}_{domain}_{timestamp}.json\n' +
' - task_{id}_{domain}_interactive_{timestamp}.html\n\n' +
'Example:\n' +
' - task_0960_Transportation_20251101_075543.json\n' +
' - task_0960_Transportation_interactive_20251101_075543.html';
}
}
// Initialize function
async function initialize() {
const fileList = await scanOutputDirectory();
if (fileList.length === 0) {
console.warn('No files detected automatically. Please run generate_file_list.py first.');
}
setupSamples(fileList);
}
async function loadSample(index) {
if (index < 0 || index >= samples.length) return;
currentIndex = index;
const sample = samples[currentIndex];
document.getElementById('viewer').src = sample.htmlFile;
document.getElementById('scenario-text').textContent = 'Loading...';
try {
const response = await fetch(sample.jsonFile);
const data = await response.json();
document.getElementById('scenario-text').textContent = data.agent1_scenario;
} catch (error) {
document.getElementById('scenario-text').textContent = 'Error loading scenario.';
console.error('Error fetching scenario:', error);
}
updateUI();
}
function updateUI() {
const sample = samples[currentIndex];
const displayName = `${sample.taskId} - ${sample.domain}`;
document.getElementById('progress').textContent =
`${displayName} - ${currentIndex + 1} / ${samples.length}`;
updateStats();
}
function updateStats() {
const counts = { High: 0, Low: 0, Unassessed: 0 };
Object.values(assessments).forEach(status => {
counts[status]++;
});
document.getElementById('stats').textContent =
`High: ${counts.High} | Low: ${counts.Low} | Unassessed: ${counts.Unassessed}`;
}
function navigate(direction) {
loadSample(currentIndex + direction);
}
function navigateToNextUnassessed() {
// Find the first unassessed sample starting from the beginning of the list.
const nextIndex = samples.findIndex(sample => assessments[sample.id] === 'Unassessed');
if (nextIndex !== -1) {
loadSample(nextIndex);
} else {
alert("All samples have been assessed!");
}
}
function assess(quality) {
assessments[samples[currentIndex].id] = quality;
localStorage.setItem('assessments_v3', JSON.stringify(assessments));
updateStats();
navigateToNextUnassessed();
}
function exportToCSV() {
let csvContent = "data:text/csv;charset=utf-8,task_id,domain,timestamp,quality_label\n";
samples.forEach(sample => {
csvContent += `${sample.taskId},${sample.domain},${sample.timestamp},${assessments[sample.id]}\n`;
});
const encodedUri = encodeURI(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "quality_labels.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// Initialize on page load
window.onload = async function() {
await initialize();
};
</script>
</body>
</html>