get-data.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. {% load static %}
  2. <!DOCTYPE html>
  3. <html lang="en"> <!--begin::Head-->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>Content Scorecard</title><!--begin::Primary Meta Tags-->
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <meta name="title" content="CQT | GET DATA">
  9. <!--end::Primary Meta Tags--><!--begin::Fonts-->
  10. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/source-sans-3@5.0.12/index.css"
  11. integrity="sha256-tXJfXfp6Ewt1ilPzLDtQnJV4hclT9XuaZUKyUvmyr+Q=" crossorigin="anonymous">
  12. <!--end::Fonts--><!--begin::Third Party Plugin(OverlayScrollbars)-->
  13. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/styles/overlayscrollbars.min.css"
  14. integrity="sha256-dSokZseQNT08wYEWiz5iLI8QPlKxG+TswNRD8k35cpg=" crossorigin="anonymous">
  15. <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Third Party Plugin(Bootstrap Icons)-->
  16. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.min.css"
  17. integrity="sha256-Qsx5lrStHZyR9REqhUF8iQt73X06c8LGIUPzpOhwRrI=" crossorigin="anonymous">
  18. <!--end::Third Party Plugin(Bootstrap Icons)--><!--begin::Required Plugin(AdminLTE)-->
  19. <link rel="stylesheet" href="{% static './css/adminlte.css' %}"><!--end::Required Plugin(AdminLTE)--><!-- apexcharts -->
  20. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.css"
  21. integrity="sha256-4MX+61mt9NVvvuPjUWdUdyfZfxSB1/Rf9WtqRHgG5S0=" crossorigin="anonymous">
  22. <!-- <link rel="stylesheet" href="{% static 'dist/WOW-master/css/libs/animate.css' %}"> -->
  23. <link rel="stylesheet" href="{% static 'css/custom.css' %}">
  24. <style>
  25. #full-page-loader {
  26. position: fixed;
  27. top: 0;
  28. left: 0;
  29. width: 100%;
  30. height: 100%;
  31. background-color: rgba(0, 0, 0, 0.6); /* semi-transparent black */
  32. z-index: 9999;
  33. display: flex;
  34. justify-content: center;
  35. align-items: center;
  36. }
  37. .loader-overlay .spinner-border {
  38. width: 3rem;
  39. height: 3rem;
  40. }
  41. </style>
  42. <style>
  43. .card {
  44. border: 1px solid #e0e0e0;
  45. border-radius: 8px;
  46. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  47. overflow: hidden;
  48. background-color: #fff;
  49. transition: box-shadow 0.3s ease;
  50. }
  51. .card:hover {
  52. box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  53. }
  54. /*
  55. .card-img-top {
  56. width: 100%;
  57. height: 200px;
  58. object-fit: cover;
  59. border-bottom: 1px solid #e0e0e0;
  60. } */
  61. .card-block {
  62. display: block;
  63. width: 100%;
  64. }
  65. .card-title, .card-text {
  66. display: block;
  67. width: 100%;
  68. /* margin: 0; */
  69. padding: 10px;
  70. margin: 10px;
  71. }
  72. .card-title {
  73. font-size: 1.2rem;
  74. margin-bottom: 0.5rem;
  75. font-weight: 600;
  76. color: #333;
  77. }
  78. .card-text {
  79. font-size: 0.95rem;
  80. color: #555;
  81. line-height: 1.5;
  82. }
  83. .card-footer {
  84. padding: 10px 16px;
  85. font-size: 0.85rem;
  86. background-color: #f8f9fa;
  87. border-top: 1px solid #e0e0e0;
  88. color: #666;
  89. }
  90. .card-header {
  91. background-color: #f1f1f1;
  92. padding: 10px 16px;
  93. font-weight: 600;
  94. font-size: 0.95rem;
  95. color: #333;
  96. border-bottom: 1px solid #ddd;
  97. }
  98. .table.projects {
  99. margin: 0;
  100. }
  101. .table td, .table th {
  102. padding: 8px;
  103. font-size: 0.9rem;
  104. vertical-align: middle;
  105. }
  106. .attribute-label {
  107. font-weight: 600;
  108. color: #333;
  109. margin-right: 4px;
  110. }
  111. .card-body input.dial {
  112. margin-bottom: 10px;
  113. }
  114. .after_score {
  115. animation: fadeIn 0.3s ease-in-out;
  116. }
  117. .row.mb-4 {
  118. margin-bottom: 2rem !important;
  119. }
  120. .table-striped tbody tr:nth-of-type(odd) {
  121. background-color: #fafafa;
  122. }
  123. @keyframes fadeIn {
  124. from { opacity: 0; }
  125. to { opacity: 1; }
  126. }
  127. @media (max-width: 768px) {
  128. .col-md-4 {
  129. flex: 0 0 100%;
  130. max-width: 100%;
  131. margin-bottom: 1rem;
  132. }
  133. .card-img-top {
  134. height: 180px;
  135. }
  136. }
  137. </style>
  138. </head>
  139. <body class="layout-fixed sidebar-expand-lg sidebar-mini app-loaded sidebar-collapse"> <!--begin::App Wrapper-->
  140. <div class="app-wrapper"> <!--begin::Header-->
  141. {% include 'header.html' %}
  142. {% include 'sidebar.html' %}
  143. <main class="app-main"> <!--begin::App Content Header-->
  144. <div class="app-content-header"> <!--begin::Container-->
  145. <div class="container-fluid"> <!--begin::Row-->
  146. <div class="row">
  147. <div class="col-sm-6">
  148. <h3 class="mb-0">📑 Scorecard</h3>
  149. </div>
  150. <div class="col-sm-6">
  151. <ol class="breadcrumb float-sm-end">
  152. <li class="breadcrumb-item"><a href="{% url 'content-scorecard' %}">Home</a></li>
  153. <li class="breadcrumb-item active" aria-current="page">
  154. 📑 Scorecard
  155. </li>
  156. </ol>
  157. </div>
  158. </div> <!--end::Row-->
  159. </div> <!--end::Container-->
  160. </div>
  161. <div class="app-content"> <!--begin::Container-->
  162. <div class="container-fluid"> <!-- Info boxes -->
  163. <!-- Full Page Loader -->
  164. <div id="full-page-loader" style="display: none;">
  165. <div class="loader-overlay">
  166. <div class="spinner-border text-light" role="status">
  167. <!-- <span class="sr-only">Loading...</span> -->
  168. </div>
  169. </div>
  170. </div>
  171. <div id="html"></div>
  172. <div class="row mt-5 ai-fix-issues-button" style="display: none;">
  173. <div class="col-sm-12 text-center">
  174. <button class="btn btn-primary wow lightSpeedIn" data-wow-delay="1s"
  175. onclick="$(this).hide();$('.after_score').removeClass('d-none');">AI
  176. Fix Issues</button>
  177. </div>
  178. </div>
  179. </div> <!--end::Row--> <!--begin::Row-->
  180. <!-- Loader (initially hidden) -->
  181. <!-- <div id="ai-loader" class="spinner-border text-primary mt-3" role="status" style="display: none;">
  182. <span class="sr-only">Loading...</span>
  183. </div> -->
  184. </div> <!--end::Container-->
  185. </main> <!--end::App Main--> <!--begin::Footer-->
  186. {% include 'footer.html' %}
  187. </div> <!--end::App Wrapper--> <!--begin::Script--> <!--begin::Third Party Plugin(OverlayScrollbars)-->
  188. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  189. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  190. <script src="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/browser/overlayscrollbars.browser.es6.min.js"
  191. integrity="sha256-H2VM7BKda+v2Z4+DRy69uknwxjyDRhszjXFhsL4gD3w=" crossorigin="anonymous"></script>
  192. <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Required Plugin(popperjs for Bootstrap 5)-->
  193. <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"
  194. integrity="sha256-whL0tQWoY1Ku1iskqPFvmZ+CHsvmRWx/PIoEvIeWh4I=" crossorigin="anonymous"></script>
  195. <!--end::Required Plugin(popperjs for Bootstrap 5)--><!--begin::Required Plugin(Bootstrap 5)-->
  196. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"
  197. integrity="sha256-YMa+wAM6QkVyz999odX7lPRxkoYAan8suedu4k2Zur8=" crossorigin="anonymous"></script>
  198. <!--end::Required Plugin(Bootstrap 5)--><!--begin::Required Plugin(AdminLTE)-->
  199. <script src="{% static './js/adminlte.js' %}"></script>
  200. <!--end::Required Plugin(AdminLTE)--><!--begin::OverlayScrollbars Configure-->
  201. <script>
  202. const SELECTOR_SIDEBAR_WRAPPER = ".sidebar-wrapper";
  203. const Default = {
  204. scrollbarTheme: "os-theme-light",
  205. scrollbarAutoHide: "leave",
  206. scrollbarClickScroll: true,
  207. };
  208. document.addEventListener("DOMContentLoaded", function () {
  209. const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER);
  210. if (
  211. sidebarWrapper &&
  212. typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== "undefined"
  213. ) {
  214. OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
  215. scrollbars: {
  216. theme: Default.scrollbarTheme,
  217. autoHide: Default.scrollbarAutoHide,
  218. clickScroll: Default.scrollbarClickScroll,
  219. },
  220. });
  221. }
  222. });
  223. </script> <!--end::OverlayScrollbars Configure--> <!-- OPTIONAL SCRIPTS --> <!-- apexcharts -->
  224. <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Knob/1.2.13/jquery.knob.min.js"
  225. integrity="sha512-NhRZzPdzMOMf005Xmd4JonwPftz4Pe99mRVcFeRDcdCtfjv46zPIi/7ZKScbpHD/V0HB1Eb+ZWigMqw94VUVaw=="
  226. crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  227. <!-- <script src="{% static 'dist/WOW-master/dist/wow.js' %}"></script> -->
  228. <script>
  229. const mediaUrl = "./../media/";
  230. console.log("mediaUrl",mediaUrl);
  231. let apiresults_without_filter;
  232. // 2. Function to filter the products based on localStorage 'productType'
  233. function filterProductsByCategory() {
  234. // A. Retrieve the target category from localStorage
  235. // Use a key like 'productType' as requested, or adjust if your localStorage key is different.
  236. const targetCategory = localStorage.getItem('selectedproductType');
  237. // Handle case where localStorage value is missing or empty
  238. if (!targetCategory) {
  239. console.warn("localStorage item 'productType' not found or is empty. Returning all products.");
  240. return productData;
  241. }
  242. // B. Filter the product array
  243. // We assume that the category is available at the top level of each product object.
  244. const filteredData = apiresults_without_filter.filter(product => {
  245. // Ensure both values are compared consistently (case-insensitive trim)
  246. const productCategory = product.category ? product.category.trim().toLowerCase() : '';
  247. const filterValue = targetCategory.trim().toLowerCase();
  248. return productCategory === filterValue;
  249. });
  250. return filteredData;
  251. }
  252. document.addEventListener('DOMContentLoaded', function () {
  253. // const responseDiv = document.getElementById('batchScoreMessage');
  254. // Show loader
  255. $('#full-page-loader').show();
  256. // console.log("localStorage.getItem('analyticsdata')",localStorage.getItem('analyticsdata'));
  257. if (localStorage.getItem('analyticsdata') !== null) {
  258. // console.log('Data key exists in localStorage');
  259. apiresults_stringify = localStorage.getItem('analyticsdata');
  260. apiresults_without_filter = JSON.parse(apiresults_stringify);
  261. apiresults = filterProductsByCategory();
  262. // apiresults = [];
  263. // Define performance buckets
  264. const bucketRanges = {
  265. excellent: [85, 100],
  266. good: [70, 84.99],
  267. fair: [50, 69.99],
  268. poor: [0, 49.99]
  269. };
  270. // Helper function to classify score
  271. function classify(score) {
  272. for (const [bucket, [low, high]] of Object.entries(bucketRanges)) {
  273. if (score >= low && score <= high) return bucket;
  274. }
  275. return 'unknown';
  276. }
  277. // Group products by product type
  278. const grouped = {};
  279. apiresults.forEach(item => {
  280. const valuesUsed = item?.ai_suggestions?.title_construction?.values_used || [];
  281. const productType = item?.category || 'Unknown';
  282. const score = item.final_score || 0;
  283. const breakdown = item.breakdown || {};
  284. const titleQuality = breakdown.title_quality || 0;
  285. const descriptionQuality = breakdown.description_quality || 0;
  286. const imageScore = breakdown.image_score || item.image_score || 0;
  287. if (!grouped[productType]) grouped[productType] = [];
  288. grouped[productType].push({
  289. score,
  290. titleQuality,
  291. descriptionQuality,
  292. imageScore,
  293. bucket: classify(score)
  294. });
  295. });
  296. // Prepare final JSON structure
  297. const output = {
  298. performance_summary: { excellent: 0, good: 0, fair: 0, poor: 0 },
  299. product_metrics: []
  300. };
  301. for (const [ptype, items] of Object.entries(grouped)) {
  302. const total = items.length;
  303. const bucketCounts = { excellent: 0, good: 0, fair: 0, poor: 0 };
  304. let scoreSum = 0, titleSum = 0, descSum = 0, imageSum = 0;
  305. items.forEach(item => {
  306. bucketCounts[item.bucket]++;
  307. scoreSum += item.score;
  308. titleSum += item.titleQuality;
  309. descSum += item.descriptionQuality;
  310. imageSum += item.imageScore;
  311. });
  312. output.performance_summary.excellent += bucketCounts.excellent;
  313. output.performance_summary.good += bucketCounts.good;
  314. output.performance_summary.fair += bucketCounts.fair;
  315. output.performance_summary.poor += bucketCounts.poor;
  316. output.product_metrics.push({
  317. product_type: ptype,
  318. products: total,
  319. avg_score: (scoreSum / total).toFixed(2),
  320. excellent_percent: `${Math.round((bucketCounts.excellent / total) * 100)}%`,
  321. good_percent: `${Math.round((bucketCounts.good / total) * 100)}%`,
  322. fair_percent: `${Math.round((bucketCounts.fair / total) * 100)}%`,
  323. poor_percent: `${Math.round((bucketCounts.poor / total) * 100)}%`,
  324. avg_title_quality: (titleSum / total).toFixed(2),
  325. avg_description_quality: (descSum / total).toFixed(2),
  326. avg_image_quality: (imageSum / total).toFixed(2)
  327. });
  328. }
  329. localStorage.setItem('performanceAnalysis',JSON.stringify(output));
  330. apiresults.forEach(element => {
  331. // console.log(element.final_score);
  332. var initial_score = '';
  333. var after_score = ''
  334. var base_keys = { 'Title': 'title_quality', 'Description': 'description_quality', 'Image': 'image_score', 'Attributes': 'attributes' }
  335. Object.entries(base_keys).forEach(([key, value]) => {
  336. let name = key;
  337. key = key.toLowerCase();
  338. console.log("key",key);
  339. console.log(element.breakdown[value], value);
  340. var per = 0
  341. if (element.breakdown[value]) {
  342. per = element.breakdown[value];
  343. }
  344. var intial_desc = '';
  345. if (element.categorized_feedback[key]) {
  346. // console.log(element.categorized_feedback[key].issues);
  347. intial_desc = element.categorized_feedback[key].issues.join(', ');
  348. }
  349. if(key == "image"){
  350. // Build the breakdown progress HTML
  351. let breakdownHtml = '';
  352. for (const [key, value] of Object.entries(element.image_breakdown)) {
  353. breakdownHtml += `
  354. <div style="margin-bottom: 10px;">
  355. <strong>${key.charAt(0).toUpperCase() + key.slice(1)}</strong>
  356. <div class="progress progress-sm mt-1">
  357. <div class="progress-bar bg-success" role="progressbar"
  358. aria-valuenow="${value}" aria-valuemin="0" aria-valuemax="100"
  359. style="width: ${value}%">
  360. </div>
  361. </div>
  362. <small>${value}%</small>
  363. </div>
  364. `;
  365. }
  366. initial_score += `<tr>
  367. <td class="wow bounceInLeft">
  368. <a>
  369. `+ name + `
  370. </a>
  371. </td>
  372. <td class="project_progress wow bounceInRight">
  373. <div class="progress progress-sm">
  374. <div class="progress-bar bg-green" role="progressbar"
  375. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  376. style="width: `+ per + `%">
  377. </div>
  378. </div>
  379. <small>
  380. `+ per + `%
  381. </small>
  382. </td>
  383. </tr>
  384. <tr>
  385. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  386. <div style='max-height:100px;overflow-y:auto;'>
  387. `+ breakdownHtml + `
  388. </div>
  389. </td>
  390. </tr>`;
  391. }else{
  392. initial_score += `<tr>
  393. <td class="wow bounceInLeft">
  394. <a>
  395. `+ name + `
  396. </a>
  397. </td>
  398. <td class="project_progress wow bounceInRight">
  399. <div class="progress progress-sm">
  400. <div class="progress-bar bg-green" role="progressbar"
  401. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  402. style="width: `+ per + `%">
  403. </div>
  404. </div>
  405. <small>
  406. `+ per + `%
  407. </small>
  408. </td>
  409. </tr>
  410. <tr>
  411. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  412. <div style='max-height:100px;overflow-y:auto;'>
  413. <small>
  414. `+ intial_desc + `
  415. </small>
  416. </div>
  417. </td>
  418. </tr>`;
  419. }
  420. });
  421. Object.keys(base_keys).forEach(k => {
  422. let name = k;
  423. k = k.toLowerCase();
  424. var ik = 'improved_' + k
  425. console.log("ik",ik);
  426. var after_desc = '';
  427. if (element.ai_suggestions.content[ik]) {
  428. console.log(element.ai_suggestions.content);
  429. after_desc = element.ai_suggestions.content[ik];
  430. }
  431. let missing_attributes = '';
  432. if(k == "attributes"){
  433. if(element?.ai_suggestions?.content?.missing_attributes){
  434. Object.entries(element?.ai_suggestions?.content?.missing_attributes).forEach(([key, value]) => {
  435. missing_attributes += `<li><span class="attribute-label">${key}:</span> ${value}</li>`
  436. });
  437. }
  438. }
  439. if(k == "image"){
  440. after_score += `<tr>
  441. <td class="wow bounceInLeft">
  442. <a>
  443. `+ name + ` Note
  444. </a>
  445. </td>
  446. </tr>
  447. <tr>
  448. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  449. <div style='max-height:100px;overflow-y:auto;'>
  450. <small>
  451. ${element?.ai_suggestions?.image?.note ? element.ai_suggestions.image.note : 'No notes available'}
  452. </small>
  453. </div>
  454. </td>
  455. </tr>`;
  456. }else if(k == "attributes"){
  457. after_score += `<tr>
  458. <td class="wow bounceInLeft">
  459. <a>
  460. Missing `+ name + `
  461. </a>
  462. </td>
  463. </tr>
  464. <tr>
  465. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  466. <div style='max-height:100px;overflow-y:auto;'>
  467. <small> <ul>
  468. `+ missing_attributes + `
  469. </ul></small>
  470. </div>
  471. </td>
  472. </tr>`;
  473. }else{
  474. after_score += `<tr>
  475. <td class="wow bounceInLeft">
  476. <a>
  477. `+ name + `
  478. </a>
  479. </td>
  480. </tr>
  481. <tr>
  482. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  483. <div style='max-height:100px;overflow-y:auto;'>
  484. <small>
  485. `+ after_desc + `
  486. </small>
  487. </div>
  488. </td>
  489. </tr>`;
  490. }
  491. })
  492. html += `<div class="row mb-4" >
  493. <div class="col-md-4">
  494. <div class="card">
  495. <img class="card-img-top wow pulse" data-wow-iteration="2"
  496. src="`+mediaUrl+element.image_path+`">
  497. <div class="card-block">
  498. <h4 class="card-title wow bounceInLeft d-block w-100" data-wow-delay="0.1s">`
  499. + element.title +
  500. `&nbsp;
  501. <a href="` + element?.product_link + `" target="_blank" class="text-decoration-none text-dark">
  502. <i class="bi bi-box-arrow-up-right ms-2" title="Open Product"></i>
  503. </a>
  504. </h4>
  505. <p class="card-text wow bounceInLeft d-block w-100" data-wow-delay="0.2s">` + element.description + `</p>
  506. </div>
  507. <div class="card-footer wow bounceInLeft" data-wow-delay="0.3s">
  508. <small>`+element.created_at+`</small>
  509. </div>
  510. </div>
  511. </div>
  512. <div class="col-md-4">
  513. <div class="card">
  514. <div class="card-header py-2">
  515. <div class="text-sm mb-0">Initial Score</div>
  516. </div>
  517. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  518. <input type="text" class="dial" value="`+ element.final_score + `" data-width="120" data-height="120"
  519. data-readOnly='true' data-fgColor="#3c8dbc" data-bgColor="#e8e8e8"
  520. data-thickness=".2">
  521. <div class="mt-2">Overall Score</div>
  522. </div>
  523. <table class="table table-striped projects mb-0 table-sm">
  524. <tbody>
  525. `+ initial_score + `
  526. </tbody>
  527. </table>
  528. </div>
  529. </div>
  530. <div class="col-md-4 after_score d-none">
  531. <div class="card">
  532. <div class="card-header py-2">
  533. <div class="text-sm mb-0">Forecasted Score</div>
  534. </div>
  535. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  536. <input type="text" class="dial" value="`+ element.ai_suggestions.content.quality_score_prediction + `" data-width="120" data-height="120"
  537. data-readOnly='true' data-fgColor="#198754" data-bgColor="#e8e8e8"
  538. data-thickness=".2">
  539. <div class="mt-2">Overall Score</div>
  540. </div>
  541. <table class="table table-striped projects mb-0 table-sm">
  542. <tbody>
  543. `+ after_score + `
  544. </tbody>
  545. </table>
  546. </div>
  547. </div>
  548. </div > `;
  549. // console.log('werrrrrrrrrrrrrrrrrrr', html);
  550. });
  551. $('#html').html(html);
  552. $('.dial').knob();
  553. document.querySelector('.ai-fix-issues-button').style.display = 'block';
  554. console.log('Generated Metrics:', output);
  555. $('#full-page-loader').hide();
  556. } else {
  557. console.log('Data key not found');
  558. fetch('/core/api/batch-score/', {
  559. method: 'GET', // or 'POST' if your API expects POST
  560. headers: {
  561. 'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]')?.value || ''
  562. }
  563. })
  564. .then(response => response.json())
  565. .then(data => {
  566. if (data.success) {
  567. var html = '';
  568. localStorage.setItem('analyticsdata',JSON.stringify(data.results));
  569. data.results.forEach(element => {
  570. // console.log(element.final_score);
  571. var initial_score = '';
  572. var after_score = ''
  573. var base_keys = { 'Title': 'title_quality', 'Description': 'description_quality', 'Image': 'image_score', 'Attributes': 'attributes' }
  574. Object.entries(base_keys).forEach(([key, value]) => {
  575. let name = key;
  576. key = key.toLowerCase();
  577. console.log("key",key);
  578. console.log(element.breakdown[value], value);
  579. var per = 0
  580. if (element.breakdown[value]) {
  581. per = element.breakdown[value];
  582. }
  583. var intial_desc = '';
  584. if (element.categorized_feedback[key]) {
  585. // console.log(element.categorized_feedback[key].issues);
  586. intial_desc = element.categorized_feedback[key].issues.join(', ');
  587. }
  588. if(key == "image"){
  589. // Build the breakdown progress HTML
  590. let breakdownHtml = '';
  591. for (const [key, value] of Object.entries(element.image_breakdown)) {
  592. breakdownHtml += `
  593. <div style="margin-bottom: 10px;">
  594. <strong>${key.charAt(0).toUpperCase() + key.slice(1)}</strong>
  595. <div class="progress progress-sm mt-1">
  596. <div class="progress-bar bg-success" role="progressbar"
  597. aria-valuenow="${value}" aria-valuemin="0" aria-valuemax="100"
  598. style="width: ${value}%">
  599. </div>
  600. </div>
  601. <small>${value}%</small>
  602. </div>
  603. `;
  604. }
  605. initial_score += `<tr>
  606. <td class="wow bounceInLeft">
  607. <a>
  608. `+ name + `
  609. </a>
  610. </td>
  611. <td class="project_progress wow bounceInRight">
  612. <div class="progress progress-sm">
  613. <div class="progress-bar bg-green" role="progressbar"
  614. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  615. style="width: `+ per + `%">
  616. </div>
  617. </div>
  618. <small>
  619. `+ per + `%
  620. </small>
  621. </td>
  622. </tr>
  623. <tr>
  624. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  625. <div style='max-height:100px;overflow-y:auto;'>
  626. `+ breakdownHtml + `
  627. </div>
  628. </td>
  629. </tr>`;
  630. }else{
  631. initial_score += `<tr>
  632. <td class="wow bounceInLeft">
  633. <a>
  634. `+ name + `
  635. </a>
  636. </td>
  637. <td class="project_progress wow bounceInRight">
  638. <div class="progress progress-sm">
  639. <div class="progress-bar bg-green" role="progressbar"
  640. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  641. style="width: `+ per + `%">
  642. </div>
  643. </div>
  644. <small>
  645. `+ per + `%
  646. </small>
  647. </td>
  648. </tr>
  649. <tr>
  650. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  651. <div style='max-height:100px;overflow-y:auto;'>
  652. <small>
  653. `+ intial_desc + `
  654. </small>
  655. </div>
  656. </td>
  657. </tr>`;
  658. }
  659. });
  660. Object.keys(base_keys).forEach(k => {
  661. let name = k;
  662. k = k.toLowerCase();
  663. var ik = 'improved_' + k
  664. console.log("ik",ik);
  665. var after_desc = '';
  666. if (element.ai_suggestions.content[ik]) {
  667. console.log(element.ai_suggestions.content);
  668. after_desc = element.ai_suggestions.content[ik];
  669. }
  670. let missing_attributes = '';
  671. if(k == "attributes"){
  672. if(element?.ai_suggestions?.content?.missing_attributes){
  673. Object.entries(element?.ai_suggestions?.content?.missing_attributes).forEach(([key, value]) => {
  674. missing_attributes += `<li><span class="attribute-label">${key}:</span> ${value}</li>`
  675. });
  676. }
  677. }
  678. if(k == "image"){
  679. after_score += `<tr>
  680. <td class="wow bounceInLeft">
  681. <a>
  682. `+ name + ` Note
  683. </a>
  684. </td>
  685. </tr>
  686. <tr>
  687. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  688. <div style='max-height:100px;overflow-y:auto;'>
  689. <small>
  690. ${element?.ai_suggestions?.image?.note ? element.ai_suggestions.image.note : 'No notes available'}
  691. </small>
  692. </div>
  693. </td>
  694. </tr>`;
  695. }else if(k == "attributes"){
  696. after_score += `<tr>
  697. <td class="wow bounceInLeft">
  698. <a>
  699. Missing `+ name + `
  700. </a>
  701. </td>
  702. </tr>
  703. <tr>
  704. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  705. <div style='max-height:100px;overflow-y:auto;'>
  706. <small> <ul>
  707. `+ missing_attributes + `
  708. </ul></small>
  709. </div>
  710. </td>
  711. </tr>`;
  712. }else{
  713. after_score += `<tr>
  714. <td class="wow bounceInLeft">
  715. <a>
  716. `+ name + `
  717. </a>
  718. </td>
  719. </tr>
  720. <tr>
  721. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  722. <div style='max-height:100px;overflow-y:auto;'>
  723. <small>
  724. `+ after_desc + `
  725. </small>
  726. </div>
  727. </td>
  728. </tr>`;
  729. }
  730. })
  731. html += `<div class="row mb-4" >
  732. <div class="col-md-4">
  733. <div class="card">
  734. <img class="card-img-top wow pulse" data-wow-iteration="2"
  735. src="`+mediaUrl+element.image_path+`">
  736. <div class="card-block">
  737. <h4 class="card-title wow bounceInLeft d-block w-100" data-wow-delay="0.1s">`
  738. + element.title +
  739. `&nbsp;
  740. <a href="` + element?.product_link + `" target="_blank" class="text-decoration-none text-dark">
  741. <i class="bi bi-box-arrow-up-right ms-2" title="Open Product"></i>
  742. </a>
  743. </h4>
  744. <p class="card-text wow bounceInLeft d-block w-100" data-wow-delay="0.2s">` + element.description + `</p>
  745. </div>
  746. <div class="card-footer wow bounceInLeft" data-wow-delay="0.3s">
  747. <small>`+element.created_at+`</small>
  748. </div>
  749. </div>
  750. </div>
  751. <div class="col-md-4">
  752. <div class="card">
  753. <div class="card-header py-2">
  754. <div class="text-sm mb-0">Initial Score</div>
  755. </div>
  756. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  757. <input type="text" class="dial" value="`+ element.final_score + `" data-width="120" data-height="120"
  758. data-readOnly='true' data-fgColor="#3c8dbc" data-bgColor="#e8e8e8"
  759. data-thickness=".2">
  760. <div class="mt-2">Overall Score</div>
  761. </div>
  762. <table class="table table-striped projects mb-0 table-sm">
  763. <tbody>
  764. `+ initial_score + `
  765. </tbody>
  766. </table>
  767. </div>
  768. </div>
  769. <div class="col-md-4 after_score d-none">
  770. <div class="card">
  771. <div class="card-header py-2">
  772. <div class="text-sm mb-0">Forecasted Score</div>
  773. </div>
  774. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  775. <input type="text" class="dial" value="`+ element.ai_suggestions.content.quality_score_prediction + `" data-width="120" data-height="120"
  776. data-readOnly='true' data-fgColor="#198754" data-bgColor="#e8e8e8"
  777. data-thickness=".2">
  778. <div class="mt-2">Overall Score</div>
  779. </div>
  780. <table class="table table-striped projects mb-0 table-sm">
  781. <tbody>
  782. `+ after_score + `
  783. </tbody>
  784. </table>
  785. </div>
  786. </div>
  787. </div > `;
  788. // console.log('werrrrrrrrrrrrrrrrrrr', html);
  789. });
  790. $('#html').html(html);
  791. $('.dial').knob();
  792. document.querySelector('.ai-fix-issues-button').style.display = 'block';
  793. $('#full-page-loader').hide();
  794. // });
  795. new WOW().init();
  796. // Define performance buckets
  797. const bucketRanges = {
  798. excellent: [85, 100],
  799. good: [70, 84.99],
  800. fair: [50, 69.99],
  801. poor: [0, 49.99]
  802. };
  803. // Helper function to classify score
  804. function classify(score) {
  805. for (const [bucket, [low, high]] of Object.entries(bucketRanges)) {
  806. if (score >= low && score <= high) return bucket;
  807. }
  808. return 'unknown';
  809. }
  810. // Group products by product type
  811. const grouped = {};
  812. data.results.forEach(item => {
  813. const valuesUsed = item?.ai_suggestions?.title_construction?.values_used || [];
  814. const productType = item?.category || 'Unknown';
  815. const score = item.final_score || 0;
  816. const breakdown = item.breakdown || {};
  817. const titleQuality = breakdown.title_quality || 0;
  818. const descriptionQuality = breakdown.description_quality || 0;
  819. const imageScore = breakdown.image_score || item.image_score || 0;
  820. if (!grouped[productType]) grouped[productType] = [];
  821. grouped[productType].push({
  822. score,
  823. titleQuality,
  824. descriptionQuality,
  825. imageScore,
  826. bucket: classify(score)
  827. });
  828. });
  829. // Prepare final JSON structure
  830. const output = {
  831. performance_summary: { excellent: 0, good: 0, fair: 0, poor: 0 },
  832. product_metrics: []
  833. };
  834. for (const [ptype, items] of Object.entries(grouped)) {
  835. const total = items.length;
  836. const bucketCounts = { excellent: 0, good: 0, fair: 0, poor: 0 };
  837. let scoreSum = 0, titleSum = 0, descSum = 0, imageSum = 0;
  838. items.forEach(item => {
  839. bucketCounts[item.bucket]++;
  840. scoreSum += item.score;
  841. titleSum += item.titleQuality;
  842. descSum += item.descriptionQuality;
  843. imageSum += item.imageScore;
  844. });
  845. output.performance_summary.excellent += bucketCounts.excellent;
  846. output.performance_summary.good += bucketCounts.good;
  847. output.performance_summary.fair += bucketCounts.fair;
  848. output.performance_summary.poor += bucketCounts.poor;
  849. output.product_metrics.push({
  850. product_type: ptype,
  851. products: total,
  852. avg_score: (scoreSum / total).toFixed(2),
  853. excellent_percent: `${Math.round((bucketCounts.excellent / total) * 100)}%`,
  854. good_percent: `${Math.round((bucketCounts.good / total) * 100)}%`,
  855. fair_percent: `${Math.round((bucketCounts.fair / total) * 100)}%`,
  856. poor_percent: `${Math.round((bucketCounts.poor / total) * 100)}%`,
  857. avg_title_quality: (titleSum / total).toFixed(2),
  858. avg_description_quality: (descSum / total).toFixed(2),
  859. avg_image_quality: (imageSum / total).toFixed(2)
  860. });
  861. }
  862. localStorage.setItem('performanceAnalysis',JSON.stringify(output));
  863. console.log('Generated Metrics:', output);
  864. // responseDiv.innerHTML = `<div class="alert alert-success">✅ ${data.message}</div>`;
  865. } else {
  866. $('#full-page-loader').hide();
  867. // responseDiv.innerHTML = `<div class="alert alert-danger">❌ ${data.error}</div>`;
  868. }
  869. // Remove message after 5 seconds
  870. // setTimeout(() => {
  871. // responseDiv.innerHTML = '';
  872. // }, 5000);
  873. })
  874. .catch(error => {
  875. $('#full-page-loader').hide();
  876. // responseDiv.innerHTML = `<div class="alert alert-danger">❌ API call failed: ${error}</div>`;
  877. // setTimeout(() => {
  878. // responseDiv.innerHTML = '';
  879. // }, 5000);
  880. });
  881. }
  882. });
  883. </script>
  884. </body><!--end::Body-->
  885. </html>