File size: 12,960 Bytes
17892ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<title>Explanation Evaluation</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap" rel="stylesheet">

<style>
/* ──────────── layout & theme ──────────── */
html, body{ margin: 0;
  padding: 0;
  background: #fff; /* Make background white */
  height: 100vh;
  overflow: hidden;
          }
.container{
  height: 100vh; /* Full viewport height */
  background: #fff; /* Container background white */
  padding: 1rem; /* Keep internal padding */
  box-sizing: border-box;
  width: 100%; /* compensate width after scaling */
  margin: 0; /* Remove margin */
  border-radius: 0; /* Remove rounded corners */
  box-shadow: none; /* Remove shadow */
  display: flex;
  flex-direction: column;}
header{text-align:center;border-bottom:1px solid #dee2e6}
header h2{margin:0;font-size:1.5rem;color:#343a40; margin-bottom:1rem}
/* progress bar */
#progress-container{margin:.5rem 0;text-align:center;margin-top:5rem}
progress{width:100%;height:20px;border-radius:10px;appearance:none}
progress::-webkit-progress-bar{background:#f1f1f1}
progress::-webkit-progress-value{background:#28a745;border-radius:10px}
#progress-text{margin-top:.5rem;font-size:1.1rem;color:#495057}
/* explanation frame */

/* explanation frame */
.explain-row{
  display:flex;
  gap:16px;                 /* space between iframe and button column */
  align-items:flex-start;
}
  
iframe{
  width: 85%;
  height: 89vh; /* Take most of the height */
  border: 2px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  transform: scale(1, 1); 
  transform-origin:top right;
}
/* controls */
.controls{
  flex:1 1 0;
  display:flex;
  flex-direction:column;
  align-items:center;
  text-align:center;
}

.controls p{font-size:1.2rem;margin: 0.5rem 2rem 0.5rem 0;color:#343a40}
button{padding:.8rem 1.5rem;margin:.5rem;font-size:1rem;border:none;border-radius:4px;
  cursor:pointer;transition:opacity .3s;background:#6c757d;color:#fff}
button:hover{opacity:.9}
/* follow-up (wrong-step) */
#wrong-box{display:none;margin:1rem auto;text-align:center;flex-direction:column;align-items:center}
#wrong-step{width:90px;padding:.45rem;text-align:center;font-size:1rem;margin-top:.4rem}
#confirm-wrong{margin-top:.8rem}
/* footer buttons */
#download-btn{display:block;margin:1rem auto;visibility:hidden}
#download-btn{background:#007bff;display:none} 
#restart-btn{display:block;margin:1rem auto}      /* optional offline CSV */
#restart-btn{background:#dc3545;display:none}
/* results + feedback */
#accuracy{margin-top:2rem;padding:1rem;border:1px solid #ced4da;border-radius:4px;
  background:#f8f9fa;color:#495057;font-size:1.1rem;line-height:1.6;text-align:center}
#accuracy h2{margin:0 0 1rem}
</style>
</head>
<body>
<div class="container">
  <header><h2>Traditional Chain-of-Thought Explanation Experiment</h2></header>

  <!-- <div id="progress-container">
    <progress id="progress-bar" value="0" max="10"></progress>
    <p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
  </div> -->

  <div class="explain-row">
    <iframe id="explanation-frame" src=""></iframe>

    <!-- MAIN CONTROLS (now vertical on the right) -->
    <div class="controls" style="display:none">
      <p id= "instruction"> you <strong>MUST</strong> do the experiment in full screen mode by clicking the button below πŸ‘‡ </p>
      <button id="full_screen" >Enter Full Screen</button>
      <p>Is the final answer correct or incorrect?</p>
      <button id="btn-correct">Correct</button>
      <button id="btn-wrong">Incorrect</button>
       <!-- ══════ FOLLOW-UP WHEN INCORRECT ══════ -->
      <div id="wrong-box">
        <span>You think the final answer is incorrect! In which step do you think the model was wrong? Step (1 – <span id="max-step">1</span>)</span>
        <input id="wrong-step" type="number" min="1" step="1">
        <button id="confirm-wrong">Confirm</button>
      </div>
      <div id="progress-container">
        <progress id="progress-bar" value="0" max="10"></progress>
        <p id="progress-text">Question 0 of 10 (Remaining: 10)</p>
      </div>
    </div>
  </div>
  
  <button id="download-btn">Download Results</button>
  <button id="restart-btn">Submit</button>
  
  <div id="accuracy"></div>
</div>
  

<!-- ──────────── SCRIPT ──────────── -->
<script>
document.addEventListener("DOMContentLoaded", () => {
    const btn = document.getElementById('full_screen');
    const span = document.getElementById('instruction');

    function isFullscreen() {
      return document.fullscreenElement || 
             document.webkitFullscreenElement || 
             document.mozFullScreenElement || 
             document.msFullscreenElement;
    }

    // Show button only if NOT in fullscreen at start
    if (!isFullscreen()) {
         btn.style.visibility = 'visible';
         span.style.visibility = "visible";
    }

    btn.addEventListener('click', () => {
        if (!isFullscreen()) {
            document.documentElement.requestFullscreen?.() ||
            document.documentElement.webkitRequestFullscreen?.() ||
            document.documentElement.mozRequestFullScreen?.() ||
            document.documentElement.msRequestFullscreen?.();
        }
    });

    function toggleButton() {
        if (isFullscreen()) {
            btn.style.visibility = 'hidden'; // Hide in fullscreen
            span.style.visibility = "hidden";
        } else {
            btn.style.visibility = 'visible'; // Show when not fullscreen
            span.style.visibility = "visible";
        }
    }
    document.addEventListener('fullscreenchange', toggleButton);
    document.addEventListener('webkitfullscreenchange', toggleButton);
    document.addEventListener('mozfullscreenchange', toggleButton);
    document.addEventListener('MSFullscreenChange', toggleButton);
});
/* utilities */
const shuffle=a=>{for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;}
const nowISO=()=>new Date().toISOString();
/* session vars */
let userName="anonymous"; function setUserName(n){userName=n;}
const sessionId=crypto.randomUUID();
const base ="interactive-llm-xai/evaluation/eval_interfaces/traditional_cot_explanations/";
const files = [
// 1 β€œright” explanation
`${base}traditional_cot_right_NA_41.html`,
`${base}traditional_cot_wrong_CA_46.html`,
`${base}traditional_cot_wrong_CO_34.html`,
`${base}traditional_cot_wrong_CS_32.html`,
`${base}traditional_cot_wrong_CV_36.html`,
`${base}traditional_cot_wrong_FC_26.html`,
`${base}traditional_cot_wrong_HA_26.html`,
`${base}traditional_cot_wrong_MS_43.html`,
`${base}traditional_cot_wrong_OP_31.html`,
`${base}traditional_cot_wrong_UC_34.html`
];


const total=files.length;
/* state */
let idx=0,startTime="",firstClick="";
let clickCounts={play:0,stop:0,next:0,prev:0};
const samples=[];
let currentMaxStep=1;
/* DOM */
const frame=document.getElementById('explanation-frame');
const controls=document.querySelector('.controls');
const downloadBtn=document.getElementById('download-btn');
const restartBtn=document.getElementById('restart-btn');
const wrongBox=document.getElementById('wrong-box');
const wrongInput=document.getElementById('wrong-step');
const maxStepSpan=document.getElementById('max-step');
const accDiv=document.getElementById('accuracy');
/* progress */
function updateProgress(){
  document.getElementById('progress-bar').value=idx;
  document.getElementById('progress-text').textContent=
    idx<total?`Question ${idx+1} of ${total} (Remaining: ${total-idx})`
             :'All questions reviewed.';
}
/* telemetry from explanation page */
window.addEventListener('message',ev=>{
  if(!ev.data||ev.data.type!=='xai-click')return;
  clickCounts[ev.data.key]=(clickCounts[ev.data.key]||0)+1;
  if(!firstClick)firstClick=nowISO();
});
/* navigation */
function loadNext(){
  if(idx>=total){renderResults();return;}
  updateProgress();
  frame.src=files[idx];
  controls.style.display='block';downloadBtn.style.display='block';
  wrongBox.style.display='none';wrongInput.value='';
  startTime=Date.now();firstClick=null;clickCounts={play:0,stop:0,next:0,prev:0};
}
frame.addEventListener('load',()=>{
  const hide=frame.src.includes('instructions.html');
  controls.style.display=hide?'none':'block';
  downloadBtn.style.display=hide?'none':'black';
  restartBtn.style.display='none';
  if(!hide){
    currentMaxStep=10;
    wrongInput.min=1;wrongInput.max=currentMaxStep;maxStepSpan.textContent=currentMaxStep;
  }
});


/* answer flow */
document.getElementById('btn-correct').onclick=()=>saveAnswer('correct',0);
document.getElementById('btn-wrong').onclick=()=>{
  wrongBox.style.display='flex';wrongInput.value='';wrongInput.focus();
};
document.getElementById('confirm-wrong').onclick=()=>{
  const n=parseInt(wrongInput.value,10);
  if(Number.isNaN(n)||n<1||n>currentMaxStep){
    alert(`Enter a valid step number (1 – ${currentMaxStep})`);wrongInput.focus();return;
  }
  saveAnswer('incorrect',n);wrongBox.style.display='none';
};
function saveAnswer(ans,userInputWrongStep){
  const elapsed=(Date.now()-startTime)/1000;
  const ActualWrongStep = parseInt(frame.contentDocument.querySelector('.wrong-step')?.textContent.trim() ?? '', 10);
  samples.push({
    file:files[idx],
    id:files[idx].match(/([^/_]+_[^/_]+_\d+)\.html$/)[1],
    label:files[idx].includes('right')?'correct':'wrong',
    humanAnswer:ans,
    actualWrongstep: ActualWrongStep,
    userInputWrongStep,
    elapsedSeconds:+elapsed.toFixed(3),
    clickCounts,
    // firstActionAt:firstClick,
    // answeredAt:nowISO()
  });
  idx++;loadNext();
}
/* results + feedback */
function renderResults(){
  /* metrics */
  const correctItems=samples.filter(s=>s.label==='correct');
  const incorrectItems=samples.filter(s=>s.label==='wrong');
  const correctHits=samples.filter(s=>s.label==='correct'&&s.humanAnswer==='correct').length;
  const incorrectHits=samples.filter(s=>s.label==='wrong'&&s.humanAnswer==='incorrect').length;
  const overallCorrect=correctHits+incorrectHits;
  const overallAcc=((overallCorrect/total)*100).toFixed(2);
  const correctAcc  =correctItems.length?((correctHits  /correctItems.length )*100).toFixed(2):'0.00';
  const incorrectAcc=incorrectItems.length?((incorrectHits/incorrectItems.length)*100).toFixed(2):'0.00';
  const avgTC=(correctItems  .reduce((a,s)=>a+s.elapsedSeconds,0)/(correctItems.length ||1)).toFixed(2);
  const avgTI=(incorrectItems.reduce((a,s)=>a+s.elapsedSeconds,0)/(incorrectItems.length||1)).toFixed(2);
  /* hide UI parts */
  controls.style.display='none';downloadBtn.style.display='none';
  document.getElementById('progress-container').style.display='none';
  frame.style.display='none';
  /* results + feedback UI */
  accDiv.innerHTML=`
    <h2>Results</h2>
    <p><strong>Overall Accuracy:</strong> ${overallCorrect}/${total} (${overallAcc}%)</p>
    <p><strong>Correct-Item Accuracy:</strong>   ${correctAcc}%</p>
    <p><strong>Incorrect-Item Accuracy:</strong> ${incorrectAcc}%</p>
    <p><strong>Avg Time (Correct):</strong>   ${avgTC} s</p>
    <p><strong>Avg Time (Incorrect):</strong> ${avgTI} s</p>
    <textarea id="feedback-box" placeholder="Any comments or suggestions?"></textarea>
  `;
  restartBtn.style.display='block';
  /* send + restart */
  restartBtn.onclick=()=>{
    const subjective_feedback=document.getElementById('feedback-box').value.trim();
    fetch('/save-stats', {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify({
        sessionId,
        userName,
        overallAccuracy: +overallAcc,
        correctItemAccuracy: correctAcc,
        incorrectItemAccuracy: incorrectAcc,
        avgTimeCorrect: avgTC,
        avgTimeIncorrect: avgTI,
        samples,
        subjective_feedback
    })
}).then(response => {
    if (response.ok) {
        window.location.href = 'interactive-llm-xai/evaluation/eval_interfaces/thank_you_cot.html';
    } else {
        alert('Failed to save stats. Please try again.');
    }
});
  };
}
/* offline CSV (optional) */
downloadBtn.onclick=()=>{
  const hdr=['file','label','humanAnswer','wrongStep','time','play','stop','next','prev'];
  const rows=[hdr,...samples.map(s=>[
    s.file,s.label,s.humanAnswer,s.wrongStep??'',s.elapsedSeconds,
    s.clickCounts.play,s.clickCounts.stop,s.clickCounts.next,s.clickCounts.prev
  ])];
  const csv=new Blob([rows.map(r=>r.join(',')).join('\n')],{type:'text/csv'});
  const url=URL.createObjectURL(csv);
  const a=document.createElement('a');a.href=url;a.download='results.csv';a.click();
  URL.revokeObjectURL(url);
};
/* kick-off */
updateProgress();
frame.src="interactive-llm-xai/evaluation/eval_interfaces/instructions.html";
</script>
</body>
</html>