get-data.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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() : product.product_type ? product.product_type.trim().toLowerCase() : '';
  247. const filterValue = targetCategory.trim().toLowerCase();
  248. return productCategory === filterValue;
  249. });
  250. return filteredData;
  251. }
  252. document.addEventListener('DOMContentLoaded', function () {
  253. var html = '';
  254. // const responseDiv = document.getElementById('batchScoreMessage');
  255. // Show loader
  256. $('#full-page-loader').show();
  257. // console.log("localStorage.getItem('analyticsdata')",localStorage.getItem('analyticsdata'));
  258. if (localStorage.getItem('analyticsdata') !== null) {
  259. // console.log('Data key exists in localStorage');
  260. apiresults_stringify = localStorage.getItem('analyticsdata');
  261. apiresults_without_filter = JSON.parse(apiresults_stringify);
  262. apiresults = filterProductsByCategory();
  263. // apiresults = [];
  264. // Define performance buckets
  265. const bucketRanges = {
  266. excellent: [85, 100],
  267. good: [70, 84.99],
  268. fair: [50, 69.99],
  269. poor: [0, 49.99]
  270. };
  271. // Helper function to classify score
  272. function classify(score) {
  273. for (const [bucket, [low, high]] of Object.entries(bucketRanges)) {
  274. if (score >= low && score <= high) return bucket;
  275. }
  276. return 'unknown';
  277. }
  278. // Group products by product type
  279. const grouped = {};
  280. apiresults.forEach(item => {
  281. const valuesUsed = item?.ai_suggestions?.title_construction?.values_used || [];
  282. const productType = item?.category || item?.product_type || 'Unknown';
  283. const score = item.final_score || 0;
  284. const breakdown = item.breakdown || {};
  285. const titleQuality = breakdown.title_quality || 0;
  286. const descriptionQuality = breakdown.description_quality || 0;
  287. const imageScore = breakdown.image_score || item.image_score || 0;
  288. if (!grouped[productType]) grouped[productType] = [];
  289. grouped[productType].push({
  290. score,
  291. titleQuality,
  292. descriptionQuality,
  293. imageScore,
  294. bucket: classify(score)
  295. });
  296. });
  297. // Prepare final JSON structure
  298. const output = {
  299. performance_summary: { excellent: 0, good: 0, fair: 0, poor: 0 },
  300. product_metrics: []
  301. };
  302. for (const [ptype, items] of Object.entries(grouped)) {
  303. const total = items.length;
  304. const bucketCounts = { excellent: 0, good: 0, fair: 0, poor: 0 };
  305. let scoreSum = 0, titleSum = 0, descSum = 0, imageSum = 0;
  306. items.forEach(item => {
  307. bucketCounts[item.bucket]++;
  308. scoreSum += item.score;
  309. titleSum += item.titleQuality;
  310. descSum += item.descriptionQuality;
  311. imageSum += item.imageScore;
  312. });
  313. output.performance_summary.excellent += bucketCounts.excellent;
  314. output.performance_summary.good += bucketCounts.good;
  315. output.performance_summary.fair += bucketCounts.fair;
  316. output.performance_summary.poor += bucketCounts.poor;
  317. output.product_metrics.push({
  318. product_type: ptype,
  319. products: total,
  320. avg_score: (scoreSum / total).toFixed(2),
  321. excellent_percent: `${Math.round((bucketCounts.excellent / total) * 100)}%`,
  322. good_percent: `${Math.round((bucketCounts.good / total) * 100)}%`,
  323. fair_percent: `${Math.round((bucketCounts.fair / total) * 100)}%`,
  324. poor_percent: `${Math.round((bucketCounts.poor / total) * 100)}%`,
  325. avg_title_quality: (titleSum / total).toFixed(2),
  326. avg_description_quality: (descSum / total).toFixed(2),
  327. avg_image_quality: (imageSum / total).toFixed(2)
  328. });
  329. }
  330. localStorage.setItem('performanceAnalysis',JSON.stringify(output));
  331. apiresults.forEach(element => {
  332. // console.log(element.final_score);
  333. var initial_score = '';
  334. var after_score = ''
  335. var base_keys = { 'Title': 'title_quality', 'Description': 'description_quality', 'Image': 'image_score', 'Attributes': 'attributes' }
  336. Object.entries(base_keys).forEach(([key, value]) => {
  337. let name = key;
  338. key = key.toLowerCase();
  339. console.log("key",key);
  340. console.log(element.breakdown[value], value);
  341. var per = 0
  342. if (element.breakdown[value]) {
  343. per = element.breakdown[value];
  344. }
  345. var intial_desc = '';
  346. if (element.categorized_feedback[key]) {
  347. // console.log(element.categorized_feedback[key].issues);
  348. intial_desc = element.categorized_feedback[key].issues.join(', ');
  349. }
  350. if(key == "image"){
  351. // Build the breakdown progress HTML
  352. let breakdownHtml = '';
  353. for (const [key, value] of Object.entries(element.image_breakdown)) {
  354. breakdownHtml += `
  355. <div style="margin-bottom: 10px;">
  356. <strong>${key.charAt(0).toUpperCase() + key.slice(1)}</strong>
  357. <div class="progress progress-sm mt-1">
  358. <div class="progress-bar bg-success" role="progressbar"
  359. aria-valuenow="${value}" aria-valuemin="0" aria-valuemax="100"
  360. style="width: ${value}%">
  361. </div>
  362. </div>
  363. <small>${value}%</small>
  364. </div>
  365. `;
  366. }
  367. initial_score += `<tr>
  368. <td class="wow bounceInLeft">
  369. <a>
  370. `+ name + `
  371. </a>
  372. </td>
  373. <td class="project_progress wow bounceInRight">
  374. <div class="progress progress-sm">
  375. <div class="progress-bar bg-green" role="progressbar"
  376. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  377. style="width: `+ per + `%">
  378. </div>
  379. </div>
  380. <small>
  381. `+ per + `%
  382. </small>
  383. </td>
  384. </tr>
  385. <tr>
  386. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  387. <div style='max-height:100px;overflow-y:auto;'>
  388. `+ breakdownHtml + `
  389. </div>
  390. </td>
  391. </tr>`;
  392. }else{
  393. initial_score += `<tr>
  394. <td class="wow bounceInLeft">
  395. <a>
  396. `+ name + `
  397. </a>
  398. </td>
  399. <td class="project_progress wow bounceInRight">
  400. <div class="progress progress-sm">
  401. <div class="progress-bar bg-green" role="progressbar"
  402. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  403. style="width: `+ per + `%">
  404. </div>
  405. </div>
  406. <small>
  407. `+ per + `%
  408. </small>
  409. </td>
  410. </tr>
  411. <tr>
  412. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  413. <div style='max-height:100px;overflow-y:auto;'>
  414. <small>
  415. `+ intial_desc + `
  416. </small>
  417. </div>
  418. </td>
  419. </tr>`;
  420. }
  421. });
  422. Object.keys(base_keys).forEach(k => {
  423. let name = k;
  424. k = k.toLowerCase();
  425. var ik = 'improved_' + k
  426. console.log("ik",ik);
  427. var after_desc = '';
  428. if (element.ai_suggestions.content[ik]) {
  429. console.log(element.ai_suggestions.content);
  430. after_desc = element.ai_suggestions.content[ik];
  431. }
  432. let missing_attributes = '';
  433. if(k == "attributes"){
  434. if(element?.ai_suggestions?.content?.missing_attributes){
  435. Object.entries(element?.ai_suggestions?.content?.missing_attributes).forEach(([key, value]) => {
  436. missing_attributes += `<li><span class="attribute-label">${key}:</span> ${value}</li>`
  437. });
  438. }
  439. }
  440. if(k == "image"){
  441. after_score += `<tr>
  442. <td class="wow bounceInLeft">
  443. <a>
  444. `+ name + ` Note
  445. </a>
  446. </td>
  447. </tr>
  448. <tr>
  449. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  450. <div style='max-height:100px;overflow-y:auto;'>
  451. <small>
  452. ${element?.ai_suggestions?.image?.note ? element.ai_suggestions.image.note : 'No notes available'}
  453. </small>
  454. </div>
  455. </td>
  456. </tr>`;
  457. }else if(k == "attributes"){
  458. after_score += `<tr>
  459. <td class="wow bounceInLeft">
  460. <a>
  461. Missing `+ name + `
  462. </a>
  463. </td>
  464. </tr>
  465. <tr>
  466. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  467. <div style='max-height:100px;overflow-y:auto;'>
  468. <small> <ul>
  469. `+ missing_attributes + `
  470. </ul></small>
  471. </div>
  472. </td>
  473. </tr>`;
  474. }else{
  475. after_score += `<tr>
  476. <td class="wow bounceInLeft">
  477. <a>
  478. `+ name + `
  479. </a>
  480. </td>
  481. </tr>
  482. <tr>
  483. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  484. <div style='max-height:100px;overflow-y:auto;'>
  485. <small>
  486. `+ after_desc + `
  487. </small>
  488. </div>
  489. </td>
  490. </tr>`;
  491. }
  492. })
  493. html += `<div class="row mb-4" >
  494. <div class="col-md-4">
  495. <div class="card">
  496. <img class="card-img-top wow pulse" data-wow-iteration="2"
  497. src="`+mediaUrl+element.image_path+`">
  498. <div class="card-block">
  499. <h4 class="card-title wow bounceInLeft d-block w-100" data-wow-delay="0.1s">`
  500. + element.title +
  501. `&nbsp;
  502. <a href="` + element?.product_link + `" target="_blank" class="text-decoration-none text-dark">
  503. <i class="bi bi-box-arrow-up-right ms-2" title="Open Product"></i>
  504. </a>
  505. </h4>
  506. <p class="card-text wow bounceInLeft d-block w-100" data-wow-delay="0.2s">` + element.description + `</p>
  507. </div>
  508. <div class="card-footer wow bounceInLeft" data-wow-delay="0.3s">
  509. <small>`+element.created_at+`</small>
  510. </div>
  511. </div>
  512. </div>
  513. <div class="col-md-4">
  514. <div class="card">
  515. <div class="card-header py-2">
  516. <div class="text-sm mb-0">Initial Score</div>
  517. </div>
  518. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  519. <input type="text" class="dial" value="`+ element.final_score + `" data-width="120" data-height="120"
  520. data-readOnly='true' data-fgColor="#3c8dbc" data-bgColor="#e8e8e8"
  521. data-thickness=".2">
  522. <div class="mt-2">Overall Score</div>
  523. </div>
  524. <table class="table table-striped projects mb-0 table-sm">
  525. <tbody>
  526. `+ initial_score + `
  527. </tbody>
  528. </table>
  529. </div>
  530. </div>
  531. <div class="col-md-4 after_score d-none">
  532. <div class="card">
  533. <div class="card-header py-2">
  534. <div class="text-sm mb-0">Forecasted Score</div>
  535. </div>
  536. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  537. <input type="text" class="dial" value="`+ element.ai_suggestions.content.quality_score_prediction + `" data-width="120" data-height="120"
  538. data-readOnly='true' data-fgColor="#198754" data-bgColor="#e8e8e8"
  539. data-thickness=".2">
  540. <div class="mt-2">Overall Score</div>
  541. </div>
  542. <table class="table table-striped projects mb-0 table-sm">
  543. <tbody>
  544. `+ after_score + `
  545. </tbody>
  546. </table>
  547. </div>
  548. </div>
  549. </div > `;
  550. // console.log('werrrrrrrrrrrrrrrrrrr', html);
  551. });
  552. $('#html').html(html);
  553. $('.dial').knob();
  554. document.querySelector('.ai-fix-issues-button').style.display = 'block';
  555. console.log('Generated Metrics:', output);
  556. $('#full-page-loader').hide();
  557. } else {
  558. console.log('Data key not found');
  559. fetch('/core/api/batch-score/', {
  560. method: 'GET', // or 'POST' if your API expects POST
  561. headers: {
  562. 'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]')?.value || ''
  563. }
  564. })
  565. .then(response => response.json())
  566. .then(data => {
  567. if (data.success) {
  568. var html = '';
  569. localStorage.setItem('analyticsdata',JSON.stringify(data.results));
  570. data.results.forEach(element => {
  571. // console.log(element.final_score);
  572. var initial_score = '';
  573. var after_score = ''
  574. var base_keys = { 'Title': 'title_quality', 'Description': 'description_quality', 'Image': 'image_score', 'Attributes': 'attributes' }
  575. Object.entries(base_keys).forEach(([key, value]) => {
  576. let name = key;
  577. key = key.toLowerCase();
  578. console.log("key",key);
  579. console.log(element.breakdown[value], value);
  580. var per = 0
  581. if (element.breakdown[value]) {
  582. per = element.breakdown[value];
  583. }
  584. var intial_desc = '';
  585. if (element.categorized_feedback[key]) {
  586. // console.log(element.categorized_feedback[key].issues);
  587. intial_desc = element.categorized_feedback[key].issues.join(', ');
  588. }
  589. if(key == "image"){
  590. // Build the breakdown progress HTML
  591. let breakdownHtml = '';
  592. for (const [key, value] of Object.entries(element.image_breakdown)) {
  593. breakdownHtml += `
  594. <div style="margin-bottom: 10px;">
  595. <strong>${key.charAt(0).toUpperCase() + key.slice(1)}</strong>
  596. <div class="progress progress-sm mt-1">
  597. <div class="progress-bar bg-success" role="progressbar"
  598. aria-valuenow="${value}" aria-valuemin="0" aria-valuemax="100"
  599. style="width: ${value}%">
  600. </div>
  601. </div>
  602. <small>${value}%</small>
  603. </div>
  604. `;
  605. }
  606. initial_score += `<tr>
  607. <td class="wow bounceInLeft">
  608. <a>
  609. `+ name + `
  610. </a>
  611. </td>
  612. <td class="project_progress wow bounceInRight">
  613. <div class="progress progress-sm">
  614. <div class="progress-bar bg-green" role="progressbar"
  615. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  616. style="width: `+ per + `%">
  617. </div>
  618. </div>
  619. <small>
  620. `+ per + `%
  621. </small>
  622. </td>
  623. </tr>
  624. <tr>
  625. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  626. <div style='max-height:100px;overflow-y:auto;'>
  627. `+ breakdownHtml + `
  628. </div>
  629. </td>
  630. </tr>`;
  631. }else{
  632. initial_score += `<tr>
  633. <td class="wow bounceInLeft">
  634. <a>
  635. `+ name + `
  636. </a>
  637. </td>
  638. <td class="project_progress wow bounceInRight">
  639. <div class="progress progress-sm">
  640. <div class="progress-bar bg-green" role="progressbar"
  641. aria-valuenow="`+ per + `" aria-valuemin="0" aria-valuemax="100"
  642. style="width: `+ per + `%">
  643. </div>
  644. </div>
  645. <small>
  646. `+ per + `%
  647. </small>
  648. </td>
  649. </tr>
  650. <tr>
  651. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  652. <div style='max-height:100px;overflow-y:auto;'>
  653. <small>
  654. `+ intial_desc + `
  655. </small>
  656. </div>
  657. </td>
  658. </tr>`;
  659. }
  660. });
  661. Object.keys(base_keys).forEach(k => {
  662. let name = k;
  663. k = k.toLowerCase();
  664. var ik = 'improved_' + k
  665. console.log("ik",ik);
  666. var after_desc = '';
  667. if (element.ai_suggestions.content[ik]) {
  668. console.log(element.ai_suggestions.content);
  669. after_desc = element.ai_suggestions.content[ik];
  670. }
  671. let missing_attributes = '';
  672. if(k == "attributes"){
  673. if(element?.ai_suggestions?.content?.missing_attributes){
  674. Object.entries(element?.ai_suggestions?.content?.missing_attributes).forEach(([key, value]) => {
  675. missing_attributes += `<li><span class="attribute-label">${key}:</span> ${value}</li>`
  676. });
  677. }
  678. }
  679. if(k == "image"){
  680. after_score += `<tr>
  681. <td class="wow bounceInLeft">
  682. <a>
  683. `+ name + ` Note
  684. </a>
  685. </td>
  686. </tr>
  687. <tr>
  688. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  689. <div style='max-height:100px;overflow-y:auto;'>
  690. <small>
  691. ${element?.ai_suggestions?.image?.note ? element.ai_suggestions.image.note : 'No notes available'}
  692. </small>
  693. </div>
  694. </td>
  695. </tr>`;
  696. }else if(k == "attributes"){
  697. after_score += `<tr>
  698. <td class="wow bounceInLeft">
  699. <a>
  700. Missing `+ name + `
  701. </a>
  702. </td>
  703. </tr>
  704. <tr>
  705. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  706. <div style='max-height:100px;overflow-y:auto;'>
  707. <small> <ul>
  708. `+ missing_attributes + `
  709. </ul></small>
  710. </div>
  711. </td>
  712. </tr>`;
  713. }else{
  714. after_score += `<tr>
  715. <td class="wow bounceInLeft">
  716. <a>
  717. `+ name + `
  718. </a>
  719. </td>
  720. </tr>
  721. <tr>
  722. <td class="wow bounceInLeft" colspan='2' data-wow-delay="0.2s">
  723. <div style='max-height:100px;overflow-y:auto;'>
  724. <small>
  725. `+ after_desc + `
  726. </small>
  727. </div>
  728. </td>
  729. </tr>`;
  730. }
  731. })
  732. html += `<div class="row mb-4" >
  733. <div class="col-md-4">
  734. <div class="card">
  735. <img class="card-img-top wow pulse" data-wow-iteration="2"
  736. src="`+mediaUrl+element.image_path+`">
  737. <div class="card-block">
  738. <h4 class="card-title wow bounceInLeft d-block w-100" data-wow-delay="0.1s">`
  739. + element.title +
  740. `&nbsp;
  741. <a href="` + element?.product_link + `" target="_blank" class="text-decoration-none text-dark">
  742. <i class="bi bi-box-arrow-up-right ms-2" title="Open Product"></i>
  743. </a>
  744. </h4>
  745. <p class="card-text wow bounceInLeft d-block w-100" data-wow-delay="0.2s">` + element.description + `</p>
  746. </div>
  747. <div class="card-footer wow bounceInLeft" data-wow-delay="0.3s">
  748. <small>`+element.created_at+`</small>
  749. </div>
  750. </div>
  751. </div>
  752. <div class="col-md-4">
  753. <div class="card">
  754. <div class="card-header py-2">
  755. <div class="text-sm mb-0">Initial Score</div>
  756. </div>
  757. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  758. <input type="text" class="dial" value="`+ element.final_score + `" data-width="120" data-height="120"
  759. data-readOnly='true' data-fgColor="#3c8dbc" data-bgColor="#e8e8e8"
  760. data-thickness=".2">
  761. <div class="mt-2">Overall Score</div>
  762. </div>
  763. <table class="table table-striped projects mb-0 table-sm">
  764. <tbody>
  765. `+ initial_score + `
  766. </tbody>
  767. </table>
  768. </div>
  769. </div>
  770. <div class="col-md-4 after_score d-none">
  771. <div class="card">
  772. <div class="card-header py-2">
  773. <div class="text-sm mb-0">Forecasted Score</div>
  774. </div>
  775. <div class="card-body text-center wow bounceInDown" data-wow-iteration="0.5">
  776. <input type="text" class="dial" value="`+ element.ai_suggestions.content.quality_score_prediction + `" data-width="120" data-height="120"
  777. data-readOnly='true' data-fgColor="#198754" data-bgColor="#e8e8e8"
  778. data-thickness=".2">
  779. <div class="mt-2">Overall Score</div>
  780. </div>
  781. <table class="table table-striped projects mb-0 table-sm">
  782. <tbody>
  783. `+ after_score + `
  784. </tbody>
  785. </table>
  786. </div>
  787. </div>
  788. </div > `;
  789. // console.log('werrrrrrrrrrrrrrrrrrr', html);
  790. });
  791. $('#html').html(html);
  792. $('.dial').knob();
  793. document.querySelector('.ai-fix-issues-button').style.display = 'block';
  794. $('#full-page-loader').hide();
  795. // });
  796. new WOW().init();
  797. // Define performance buckets
  798. const bucketRanges = {
  799. excellent: [85, 100],
  800. good: [70, 84.99],
  801. fair: [50, 69.99],
  802. poor: [0, 49.99]
  803. };
  804. // Helper function to classify score
  805. function classify(score) {
  806. for (const [bucket, [low, high]] of Object.entries(bucketRanges)) {
  807. if (score >= low && score <= high) return bucket;
  808. }
  809. return 'unknown';
  810. }
  811. // Group products by product type
  812. const grouped = {};
  813. data.results.forEach(item => {
  814. const valuesUsed = item?.ai_suggestions?.title_construction?.values_used || [];
  815. const productType = item?.category || item?.product_type || 'Unknown';
  816. const score = item.final_score || 0;
  817. const breakdown = item.breakdown || {};
  818. const titleQuality = breakdown.title_quality || 0;
  819. const descriptionQuality = breakdown.description_quality || 0;
  820. const imageScore = breakdown.image_score || item.image_score || 0;
  821. if (!grouped[productType]) grouped[productType] = [];
  822. grouped[productType].push({
  823. score,
  824. titleQuality,
  825. descriptionQuality,
  826. imageScore,
  827. bucket: classify(score)
  828. });
  829. });
  830. // Prepare final JSON structure
  831. const output = {
  832. performance_summary: { excellent: 0, good: 0, fair: 0, poor: 0 },
  833. product_metrics: []
  834. };
  835. for (const [ptype, items] of Object.entries(grouped)) {
  836. const total = items.length;
  837. const bucketCounts = { excellent: 0, good: 0, fair: 0, poor: 0 };
  838. let scoreSum = 0, titleSum = 0, descSum = 0, imageSum = 0;
  839. items.forEach(item => {
  840. bucketCounts[item.bucket]++;
  841. scoreSum += item.score;
  842. titleSum += item.titleQuality;
  843. descSum += item.descriptionQuality;
  844. imageSum += item.imageScore;
  845. });
  846. output.performance_summary.excellent += bucketCounts.excellent;
  847. output.performance_summary.good += bucketCounts.good;
  848. output.performance_summary.fair += bucketCounts.fair;
  849. output.performance_summary.poor += bucketCounts.poor;
  850. output.product_metrics.push({
  851. product_type: ptype,
  852. products: total,
  853. avg_score: (scoreSum / total).toFixed(2),
  854. excellent_percent: `${Math.round((bucketCounts.excellent / total) * 100)}%`,
  855. good_percent: `${Math.round((bucketCounts.good / total) * 100)}%`,
  856. fair_percent: `${Math.round((bucketCounts.fair / total) * 100)}%`,
  857. poor_percent: `${Math.round((bucketCounts.poor / total) * 100)}%`,
  858. avg_title_quality: (titleSum / total).toFixed(2),
  859. avg_description_quality: (descSum / total).toFixed(2),
  860. avg_image_quality: (imageSum / total).toFixed(2)
  861. });
  862. }
  863. localStorage.setItem('performanceAnalysis',JSON.stringify(output));
  864. console.log('Generated Metrics:', output);
  865. $('#full-page-loader').hide();
  866. // responseDiv.innerHTML = `<div class="alert alert-success">✅ ${data.message}</div>`;
  867. } else {
  868. $('#full-page-loader').hide();
  869. // responseDiv.innerHTML = `<div class="alert alert-danger">❌ ${data.error}</div>`;
  870. }
  871. // Remove message after 5 seconds
  872. // setTimeout(() => {
  873. // responseDiv.innerHTML = '';
  874. // }, 5000);
  875. })
  876. .catch(error => {
  877. $('#full-page-loader').hide();
  878. // responseDiv.innerHTML = `<div class="alert alert-danger">❌ API call failed: ${error}</div>`;
  879. // setTimeout(() => {
  880. // responseDiv.innerHTML = '';
  881. // }, 5000);
  882. });
  883. }
  884. });
  885. </script>
  886. </body><!--end::Body-->
  887. </html>