YchKhan commited on
Commit
117009d
·
verified ·
1 Parent(s): c0ba4d5

Update static/js/script.js

Browse files
Files changed (1) hide show
  1. static/js/script.js +106 -1
static/js/script.js CHANGED
@@ -945,6 +945,14 @@ function showRefinedProblems(result) {
945
  tabs.innerHTML = '';
946
  content.innerHTML = '';
947
 
 
 
 
 
 
 
 
 
948
  // Add tabs and content for each refined problem
949
  let isFirst = true;
950
  for (const key in result) {
@@ -955,7 +963,20 @@ function showRefinedProblems(result) {
955
  const tab = document.createElement('div');
956
  tab.className = `refined-problem-tab ${isFirst ? 'active' : ''}`;
957
  tab.dataset.target = key;
958
- tab.textContent = `Option ${key.split('_')[1]}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
959
  tab.onclick = function() {
960
  document.querySelectorAll('.refined-problem-tab').forEach(t => t.classList.remove('active'));
961
  document.querySelectorAll('.refined-problem').forEach(p => p.classList.remove('active'));
@@ -977,6 +998,18 @@ function showRefinedProblems(result) {
977
  description.className = 'refined-problem-description';
978
  description.textContent = problem.description;
979
 
 
 
 
 
 
 
 
 
 
 
 
 
980
  const applyButton = document.createElement('button');
981
  applyButton.className = 'apply-problem-btn';
982
  applyButton.textContent = 'Apply This Problem';
@@ -986,6 +1019,7 @@ function showRefinedProblems(result) {
986
 
987
  problemDiv.appendChild(title);
988
  problemDiv.appendChild(description);
 
989
  problemDiv.appendChild(applyButton);
990
 
991
  content.appendChild(problemDiv);
@@ -999,6 +1033,77 @@ function showRefinedProblems(result) {
999
 
1000
  // Scroll to the container
1001
  refinedContainer.scrollIntoView({ behavior: 'smooth' });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  }
1003
 
1004
  // Apply the selected refined problem
 
945
  tabs.innerHTML = '';
946
  content.innerHTML = '';
947
 
948
+ // Collect problem descriptions for evaluation
949
+ const problemDescriptions = [];
950
+ for (const key in result) {
951
+ if (result.hasOwnProperty(key)) {
952
+ problemDescriptions.push(result[key].description);
953
+ }
954
+ }
955
+
956
  // Add tabs and content for each refined problem
957
  let isFirst = true;
958
  for (const key in result) {
 
963
  const tab = document.createElement('div');
964
  tab.className = `refined-problem-tab ${isFirst ? 'active' : ''}`;
965
  tab.dataset.target = key;
966
+ tab.dataset.problemIndex = problemDescriptions.indexOf(problem.description);
967
+
968
+ // Create tab content with placeholder for score
969
+ const tabTextSpan = document.createElement('span');
970
+ tabTextSpan.textContent = `Option ${key.split('_')[1]}`;
971
+
972
+ // Create score element that will be updated later
973
+ const tabScoreSpan = document.createElement('span');
974
+ tabScoreSpan.className = 'tab-score-indicator';
975
+ tabScoreSpan.innerHTML = `<div class="tab-loading-spinner"></div>`;
976
+
977
+ tab.appendChild(tabTextSpan);
978
+ tab.appendChild(tabScoreSpan);
979
+
980
  tab.onclick = function() {
981
  document.querySelectorAll('.refined-problem-tab').forEach(t => t.classList.remove('active'));
982
  document.querySelectorAll('.refined-problem').forEach(p => p.classList.remove('active'));
 
998
  description.className = 'refined-problem-description';
999
  description.textContent = problem.description;
1000
 
1001
+ // Create score display with loading spinner initially
1002
+ const scoreContainer = document.createElement('div');
1003
+ scoreContainer.className = 'problem-score-container';
1004
+ scoreContainer.innerHTML = `
1005
+ <div class="problem-score-loading">
1006
+ <div class="loading-spinner-small"></div>
1007
+ <span>Evaluating quality...</span>
1008
+ </div>
1009
+ <div class="problem-score" style="display: none;"></div>
1010
+ `;
1011
+ scoreContainer.dataset.problemIndex = problemDescriptions.indexOf(problem.description);
1012
+
1013
  const applyButton = document.createElement('button');
1014
  applyButton.className = 'apply-problem-btn';
1015
  applyButton.textContent = 'Apply This Problem';
 
1019
 
1020
  problemDiv.appendChild(title);
1021
  problemDiv.appendChild(description);
1022
+ problemDiv.appendChild(scoreContainer);
1023
  problemDiv.appendChild(applyButton);
1024
 
1025
  content.appendChild(problemDiv);
 
1033
 
1034
  // Scroll to the container
1035
  refinedContainer.scrollIntoView({ behavior: 'smooth' });
1036
+
1037
+ // If we have problem descriptions, evaluate them
1038
+ if (problemDescriptions.length > 0) {
1039
+ // Call the API to evaluate problem descriptions
1040
+ fetch('/evaluate-problem-descriptions', {
1041
+ method: 'POST',
1042
+ headers: {
1043
+ 'Content-Type': 'application/json',
1044
+ },
1045
+ body: JSON.stringify({
1046
+ 'problem_descriptions': problemDescriptions
1047
+ })
1048
+ })
1049
+ .then(response => response.json())
1050
+ .then(data => {
1051
+ console.log('Problem evaluation results:', data);
1052
+
1053
+ // Update the UI with evaluation scores
1054
+ if (Array.isArray(data)) {
1055
+ data.forEach((evaluation, index) => {
1056
+ const scoreContainers = document.querySelectorAll(`.problem-score-container[data-problem-index="${index}"]`);
1057
+ scoreContainers.forEach(container => {
1058
+ const loadingEl = container.querySelector('.problem-score-loading');
1059
+ const scoreEl = container.querySelector('.problem-score');
1060
+
1061
+ if (loadingEl && scoreEl && evaluation.score !== undefined) {
1062
+ // Hide loading spinner
1063
+ loadingEl.style.display = 'none';
1064
+
1065
+ // Format the score as a percentage
1066
+ const scoreValue = (evaluation.score * 100).toFixed(1);
1067
+
1068
+ // Determine color based on score
1069
+ let scoreColor = '#ff4d4d'; // Red for low scores
1070
+ if (evaluation.score >= 0.7) {
1071
+ scoreColor = '#4caf50'; // Green for high scores
1072
+ } else if (evaluation.score >= 0.5) {
1073
+ scoreColor = '#ff9800'; // Orange for medium scores
1074
+ }
1075
+
1076
+ // Show score with appropriate styling
1077
+ scoreEl.innerHTML = `<span style="font-weight: bold;">Specificity Score: <span style="color: ${scoreColor};">${scoreValue}%</span></span>`;
1078
+ scoreEl.style.display = 'block';
1079
+
1080
+ // Also update the score in the tab
1081
+ const tabWithSameIndex = document.querySelector(`.refined-problem-tab[data-problem-index="${index}"]`);
1082
+ if (tabWithSameIndex) {
1083
+ const tabScoreSpan = tabWithSameIndex.querySelector('.tab-score-indicator');
1084
+ if (tabScoreSpan) {
1085
+ tabScoreSpan.innerHTML = `<span style="color: ${scoreColor}; margin-left: 6px; font-size: 0.85em;">${scoreValue}%</span>`;
1086
+ }
1087
+ }
1088
+ }
1089
+ });
1090
+ });
1091
+ } else if (data.error) {
1092
+ console.error('Error evaluating problems:', data.error);
1093
+ // Update UI to show error state
1094
+ document.querySelectorAll('.problem-score-loading').forEach(el => {
1095
+ el.innerHTML = '<span style="color: #ff4d4d;">Evaluation failed</span>';
1096
+ });
1097
+ }
1098
+ })
1099
+ .catch(error => {
1100
+ console.error('Error:', error);
1101
+ // Update UI to show error state
1102
+ document.querySelectorAll('.problem-score-loading').forEach(el => {
1103
+ el.innerHTML = '<span style="color: #ff4d4d;">Evaluation failed</span>';
1104
+ });
1105
+ });
1106
+ }
1107
  }
1108
 
1109
  // Apply the selected refined problem