tango-app-api-analysis-traffic 3.1.0-alpha.5 → 3.1.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-analysis-traffic",
3
- "version": "3.1.0-alpha.5",
3
+ "version": "3.1.0-alpha.7",
4
4
  "description": "Traffic Analysis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -18,6 +18,8 @@
18
18
  "dotenv": "^16.4.5",
19
19
  "express": "^4.19.2",
20
20
  "handlebars": "^4.7.8",
21
+ "html-pdf": "^3.0.1",
22
+ "html-pdf-node": "^1.0.8",
21
23
  "joi-to-swagger": "^6.2.0",
22
24
  "lodash": "^4.17.21",
23
25
  "mongodb": "^6.8.0",
@@ -3,15 +3,20 @@ import * as clientService from '../services/clients.services.js';
3
3
  import * as userService from '../services/user.service.js';
4
4
  import * as storeService from '../services/stores.service.js';
5
5
  import { findCamera } from '../services/camera.service.js';
6
- import handlebars, { registerHelpers } from './handlebars.js';
7
6
  const __filename = fileURLToPath( import.meta.url );
8
7
  const __dirname = dirname( __filename );
9
8
  import { fileURLToPath } from 'url';
10
9
  import { dirname } from 'path';
11
10
  import puppeteer from 'puppeteer';
12
- import { readFileSync } from 'fs';
13
- import { join } from 'path';
11
+ // import { readFileSync } from 'fs';
12
+ // import { join } from 'path';
14
13
  import dayjs from 'dayjs';
14
+ import fs from 'fs';
15
+ import path from 'path';
16
+ import htmlpdf from 'html-pdf-node';
17
+ // import pdf from 'html-pdf';
18
+ import Handlebars, { registerHelpers } from './handlebars.js';
19
+
15
20
  registerHelpers();
16
21
 
17
22
  // Lamda Service Call //
@@ -279,11 +284,11 @@ export const sendEmailers = async ( req, res ) => {
279
284
  let storeData = {
280
285
  storeId: getStoreSourceData.storeId,
281
286
  storeName: getStoreSourceData.storeName,
282
- storeLocation: getStoreSourceData.storeProfile.city+' '+getStoreSourceData.storeProfile.pincode,
287
+ storeLocation: getStoreSourceData.storeProfile?.city+' '+getStoreSourceData.storeProfile.pincode,
283
288
  storeCount: emailerSourceData._source.storeIds.length-1,
284
289
  storeBaseImage: cameraBaseImage,
285
290
  };
286
- console.log( 'cameraBaseImage 1=>', cameraBaseImage );
291
+ // console.log( 'cameraBaseImage 1=>', cameraBaseImage );
287
292
  // // Get Client Data ///
288
293
  let clientData = await clientService.findOne( { clientId: emailerSourceData._source.clientId }, { clientId: 1, emailersConfig: 1, featureConfigs: 1, clientName: 1 } );
289
294
 
@@ -308,8 +313,11 @@ export const sendEmailers = async ( req, res ) => {
308
313
  missedOpportunityCalculation: clientData?.featureConfigs?.missedOpportunityCalculation || 'engagers-conversion',
309
314
  bufferTime: 30,
310
315
  },
316
+ templateId: emailerSourceData._id,
311
317
  };
312
318
  // console.log( 'templateData =>', templateData );
319
+ // console.log( 'emailerSourceData =>', emailerSourceData );
320
+
313
321
 
314
322
  // // Get Lamda Metrics Data ////
315
323
  let lamdaMetrics = await getLamdaMetricsData( templateData );
@@ -380,7 +388,7 @@ async function getLamdaMetricsData( templateData ) {
380
388
  // Default Value
381
389
  }
382
390
  } catch ( error ) {
383
- console.log( 'error getLamdaMetricsData=>', error );
391
+ // console.log( 'error getLamdaMetricsData=>', error );
384
392
  logger.error( { error: error, function: 'getLamdaMetricsData' } );
385
393
  return false;
386
394
  }
@@ -448,7 +456,7 @@ async function lamdaAPI1( templateData ) {
448
456
  }
449
457
  return lamdaAPIResultData;
450
458
  } catch ( error ) {
451
- console.log( 'error lamdaAPI1=>', error );
459
+ // console.log( 'error lamdaAPI1=>', error );
452
460
  logger.error( { error: error, function: 'lamdaAPI1' } );
453
461
  return false;
454
462
  }
@@ -520,7 +528,7 @@ async function lamdaAPI2( templateData ) {
520
528
  }
521
529
  return lamdaAPIResultData;
522
530
  } catch ( error ) {
523
- console.log( 'error lamdaAPI2=>', error );
531
+ // console.log( 'error lamdaAPI2=>', error );
524
532
  logger.error( { error: error, function: 'lamdaAPI2' } );
525
533
  return false;
526
534
  }
@@ -629,18 +637,17 @@ async function lamdaAPI3( templateData ) {
629
637
  let newTemplateData = templateData;
630
638
  const overallLamdaURL = 'https://bqk7ozecu7smfrzyb2hbb5lo540avjkl.lambda-url.ap-south-1.on.aws/';
631
639
  let lamdaAPIResultData = await LamdaServiceCall( overallLamdaURL, newTemplateData );
632
- if ( !lamdaAPIResultData || lamdaAPIResultData.status_code !== 200 ) {
640
+ if ( !lamdaAPIResultData || lamdaAPIResultData.status_code !== '200' ) {
633
641
  return '';
634
642
  }
635
643
  return lamdaAPIResultData;
636
644
  } catch ( error ) {
637
- console.log( 'error lamdaAPI3=>', error );
645
+ // console.log( 'error lamdaAPI3=>', error );
638
646
  logger.error( { error: error, function: 'lamdaAPI3' } );
639
647
  return false;
640
648
  }
641
649
  }
642
650
 
643
-
644
651
  async function lamdaAPI4( templateData ) {
645
652
  try {
646
653
  // let lamdaAPIResultData = {
@@ -757,7 +764,7 @@ async function lamdaAPI4( templateData ) {
757
764
  }
758
765
  return lamdaAPIResultData;
759
766
  } catch ( error ) {
760
- console.log( 'error lamdaAPI4=>', error );
767
+ // console.log( 'error lamdaAPI4=>', error );
761
768
  logger.error( { error: error, function: 'lamdaAPI4' } );
762
769
  return false;
763
770
  }
@@ -803,11 +810,11 @@ async function hourlyChartLamdaAPI( templateData ) {
803
810
 
804
811
  let hourlyData = lamdaAPIResultData.hourlyData || [];
805
812
  let hourlyChartImagePath = await overallHourlyChart( hourlyData );
806
-
813
+ // console.log( 'dayjs().format', dayjs().format );
807
814
  // Upload hourly chart
808
815
  const hourlyChartParams = {
809
- Bucket: bucketDetails.mailer,
810
- Key: `${dayjs().format( 'YYYY-MM-DD-HH:mm:ss' )}/mail/emailHourlyUserChart.png`,
816
+ Bucket: bucketDetails.emailers,
817
+ Key: `emailer/${templateData.clientId}/${dayjs().format( 'YYYY-MM-DD' )}/${templateData.templateId}/hourlyChart/${dayjs().unix()}.png`,
811
818
  ContentType: 'image/png',
812
819
  body: hourlyChartImagePath,
813
820
  };
@@ -815,16 +822,16 @@ async function hourlyChartLamdaAPI( templateData ) {
815
822
  const hourlyChartResponse = await fileUpload( hourlyChartParams );
816
823
  if ( hourlyChartResponse && hourlyChartResponse.Key ) {
817
824
  hourlyChartUrl = await signedUrl( {
818
- Bucket: bucketDetails.mailer,
825
+ Bucket: bucketDetails.emailers,
819
826
  file_path: hourlyChartResponse.Key,
820
827
  } );
821
828
  } else {
822
829
  throw new Error( 'S3 Upload failed for hourly chart' );
823
830
  }
824
- console.log( 'chartUrl hourlyChartLamdaAPI=>', hourlyChartUrl );
831
+ // console.log( 'chartUrl hourlyChartLamdaAPI=>', hourlyChartUrl );
825
832
  return hourlyChartUrl;
826
833
  } catch ( error ) {
827
- console.log( ' error hourlyChartLamdaAPI=>', error );
834
+ // console.log( ' error hourlyChartLamdaAPI=>', error );
828
835
  logger.error( { error: error, function: 'hourlyChartLamdaAPI' } );
829
836
  return false;
830
837
  }
@@ -855,26 +862,30 @@ async function dailyChartLamdaAPI( templateData ) {
855
862
  if ( !lamdaAPIResultData || lamdaAPIResultData.status_code !== '200' ) {
856
863
  return chartUrl;
857
864
  }
865
+ // console.log( 'Unix timestamp:', dayjs().unix() );
858
866
 
859
867
  let dailyData = lamdaAPIResultData.storeData || [];
860
868
  let chartImagePath = await overallChart( dailyData );
869
+
861
870
  // Upload overall chart
862
871
  const overallChartParams = {
863
- Bucket: bucketDetails.mailer,
864
- Key: `${dayjs().format( 'YYYY-MM-DD-HH:mm:ss' )}/mail/emaildailyUserChart.png`,
872
+ Bucket: bucketDetails.emailers,
873
+ Key: `emailer/${templateData.clientId}/${dayjs().format( 'YYYY-MM-DD' )}/${templateData.templateId}/dailyChart/${dayjs().unix()}.png`,
874
+ // Key: `${dayjs().format( 'YYYY-MM-DD-HH:mm:ss' )}/mail/emaildailyUserChart.png`,
875
+ // ${templateData.templateType}
865
876
  ContentType: 'image/png',
866
877
  body: chartImagePath,
867
878
  };
868
879
  const overallChartResponse = await fileUpload( overallChartParams );
869
880
  if ( overallChartResponse && overallChartResponse.Key ) {
870
881
  chartUrl = await signedUrl( {
871
- Bucket: bucketDetails.mailer,
882
+ Bucket: bucketDetails.emailers,
872
883
  file_path: overallChartResponse.Key,
873
884
  } );
874
885
  } else {
875
886
  throw new Error( 'S3 Upload failed for overall chart' );
876
887
  }
877
- console.log( 'chartUrl dailyChartLamdaAPI=>', chartUrl );
888
+ // console.log( 'chartUrl dailyChartLamdaAPI=>', chartUrl );
878
889
  return chartUrl;
879
890
  } catch ( error ) {
880
891
  logger.error( { error: error, function: 'dailyChartLamdaAPI' } );
@@ -1031,6 +1042,7 @@ async function dailyFootfallTrendChartLamdaAPI( templateData ) {
1031
1042
  // return lamdaAPIResultData;
1032
1043
 
1033
1044
  let newTemplateData = templateData;
1045
+ // console.log( 'Template Data:', templateData );
1034
1046
  // newTemplateData.dateType = 'weekly';
1035
1047
  let processTypeValue = 'engagers';
1036
1048
  if ( templateData.featureConfigs.conversionCalculation !== 'engagers-count' ) {
@@ -1047,34 +1059,42 @@ async function dailyFootfallTrendChartLamdaAPI( templateData ) {
1047
1059
  newTemplateData.processType = processTypeValue;
1048
1060
  newTemplateData.limit = 31;
1049
1061
  newTemplateData.offset = 0;
1062
+ // console.log( 'newTemplateData', newTemplateData );
1050
1063
  const overallLamdaURL = 'https://x6sjlqwaqd64kyioxhwrwfesbm0jjitx.lambda-url.ap-south-1.on.aws/';
1051
1064
  let lamdaAPIResultData = await LamdaServiceCall( overallLamdaURL, newTemplateData );
1065
+ // console.log( 'lamdaAPIResultData =>', lamdaAPIResultData );
1052
1066
  if ( !lamdaAPIResultData || lamdaAPIResultData.status_code !== '200' ) {
1053
1067
  return chartUrl;
1054
1068
  }
1055
1069
 
1056
1070
  let dailyData = lamdaAPIResultData.footfallTrendData || [];
1057
1071
  let chartImagePath = await footfallTrend( dailyData );
1072
+ // console.log( 'chartImagePath =>', chartImagePath );
1058
1073
  // Upload overall chart
1074
+ // console.log( 'Unix timestamp:', dayjs().unix() );
1059
1075
  const overallChartParams = {
1060
- Bucket: bucketDetails.mailer,
1061
- Key: `${dayjs().format( 'YYYY-MM-DD-HH:mm:ss' )}/mail/emailweeklyUserChart.png`,
1076
+ Bucket: bucketDetails.emailers,
1077
+ Key: `emailer/${templateData.clientId}/${dayjs().format( 'YYYY-MM-DD' )}/${templateData.templateId}/footfallTrendChart/${dayjs().unix()}.png`,
1078
+ // Key: `${dayjs().format( 'YYYY-MM-DD-HH:mm:ss' )}/mail/emailweeklyUserChart.png`,
1062
1079
  ContentType: 'image/png',
1063
1080
  body: chartImagePath,
1064
1081
  };
1082
+ // console.log( 'bucketDetails =>', bucketDetails.mailer );
1083
+ // console.log( 'overallChartParams =>', overallChartParams );
1065
1084
  const overallChartResponse = await fileUpload( overallChartParams );
1085
+ // console.log("overallChartResponse =>", overallChartResponse);
1066
1086
  if ( overallChartResponse && overallChartResponse.Key ) {
1067
1087
  chartUrl = await signedUrl( {
1068
- Bucket: bucketDetails.mailer,
1088
+ Bucket: bucketDetails.emailers,
1069
1089
  file_path: overallChartResponse.Key,
1070
1090
  } );
1071
1091
  } else {
1072
1092
  throw new Error( 'S3 Upload failed for overall chart' );
1073
1093
  }
1074
- console.log( 'chartUrl dailyFootfallTrendChartLamdaAPI=>', chartUrl );
1094
+ // console.log( 'chartUrl dailyFootfallTrendChartLamdaAPI=>', chartUrl );
1075
1095
  return chartUrl;
1076
1096
  } catch ( error ) {
1077
- console.log( 'error dailyFootfallTrendChartLamdaAPI=>', error );
1097
+ // console.log( 'error dailyFootfallTrendChartLamdaAPI=>', error );
1078
1098
  logger.error( { error: error, function: 'dailyFootfallTrendChartLamdaAPI' } );
1079
1099
  return false;
1080
1100
  }
@@ -1094,7 +1114,7 @@ async function getLamdaChartData( templateData ) {
1094
1114
  ] );
1095
1115
  resultLamdaChartData.dailyData = chartImagePath;
1096
1116
  resultLamdaChartData.hourlyData = hourlyChartImagePath;
1097
- console.log( 'resultLamdaChartData 555=>', resultLamdaChartData );
1117
+ // console.log( 'resultLamdaChartData 555=>', resultLamdaChartData );
1098
1118
  return resultLamdaChartData;
1099
1119
  } else {
1100
1120
  // Default Value
@@ -1102,7 +1122,7 @@ async function getLamdaChartData( templateData ) {
1102
1122
  return resultLamdaChartData;
1103
1123
  }
1104
1124
  } catch ( error ) {
1105
- console.log( 'error getLamdaChartData=>', error );
1125
+ // console.log( 'error getLamdaChartData=>', error );
1106
1126
  logger.error( { error: error, function: 'getLamdaChartData' } );
1107
1127
  return false;
1108
1128
  }
@@ -1111,40 +1131,30 @@ async function getLamdaChartData( templateData ) {
1111
1131
  async function emailerSendEmail( storeData, clientData, lamdaMetrics, lamdaCharts, templateData ) {
1112
1132
  try {
1113
1133
  let hbsFileName = '../hbs/dailyMailerSingle.hbs';
1114
- if ( templateData.allStores.length == 1 && templateData.templateType == 'daily' ) {
1115
- // // Call Lamda API No 1 Single Store Single Date
1134
+ if ( templateData.allStores.length === 1 && templateData.templateType === 'daily' ) {
1116
1135
  hbsFileName = '../hbs/dailyMailerSingle.hbs';
1117
- } else if ( templateData.allStores.length > 1 && templateData.templateType == 'daily' ) {
1118
- // // Call Lamda API No 3 Multiple Store Single Date
1136
+ } else if ( templateData.allStores.length > 1 && templateData.templateType === 'daily' ) {
1119
1137
  hbsFileName = '../hbs/dailyMailerMultiple.hbs';
1120
- } else if ( templateData.allStores.length == 1 && templateData.templateType == 'weekly' ) {
1121
- // // Call Lamda API No 2 Single Store Multiple Date
1138
+ } else if ( templateData.allStores.length === 1 && templateData.templateType === 'weekly' ) {
1122
1139
  hbsFileName = '../hbs/weeklyMailerSingle.hbs';
1123
- } else if ( templateData.allStores.length > 1 && templateData.templateType == 'weekly' ) {
1124
- // // Call Lamda API No 4 Multiple Store Multiple Date
1140
+ } else if ( templateData.allStores.length > 1 && templateData.templateType === 'weekly' ) {
1125
1141
  hbsFileName = '../hbs/weeklyMailerMultiple.hbs';
1126
- } else if ( templateData.allStores.length == 1 && templateData.templateType == 'monthly' ) {
1127
- // // Call Lamda API No 5 Single Store Multiple Date
1142
+ } else if ( templateData.allStores.length === 1 && templateData.templateType === 'monthly' ) {
1128
1143
  hbsFileName = '../hbs/dailyMailerSingle.hbs';
1129
- } else if ( templateData.allStores.length > 1 && templateData.templateType == 'monthly' ) {
1130
- // // Call Lamda API No 6 Multiple Store Multiple Date
1144
+ } else if ( templateData.allStores.length > 1 && templateData.templateType === 'monthly' ) {
1131
1145
  hbsFileName = '../hbs/dailyMailerSingle.hbs';
1132
- } else {
1133
- // Default Value
1134
1146
  }
1135
- // Prepare email with Handlebars template
1136
- const fileContent = readFileSync(
1137
- join( __dirname, hbsFileName ),
1138
- 'utf8',
1139
- );
1140
- const htmlContent = handlebars.compile( fileContent );
1141
1147
 
1142
- const emailVars = {
1143
- // email: inputData.email,
1148
+ // Prepare email with Handlebars template
1149
+ const hbsFilePath = path.join( __dirname, hbsFileName );
1150
+ const templateHtml = fs.readFileSync( hbsFilePath, 'utf8' );
1151
+ const template = Handlebars.compile( templateHtml );
1152
+ console.log( 'JSON.parse( process.env.URL ).apiDomain', JSON.parse( process.env.URL ).apiDomain );
1153
+ const html = template( { data: {
1144
1154
  clientName: clientData.clientName,
1145
- domain: JSON.parse( process.env.URL ).apiDomain,
1146
- overallChartImage: lamdaCharts.dailyData, // Use the S3 URL for the overall chart
1147
- hourlyChartImage: lamdaCharts.hourlyData, // Use the S3 URL for the hourly chart
1155
+ domain: JSON.parse( process.env.URL ).domain,
1156
+ overallChartImage: lamdaCharts.dailyData,
1157
+ hourlyChartImage: lamdaCharts.hourlyData,
1148
1158
  lamdaMetrics: lamdaMetrics,
1149
1159
  storeData: storeData,
1150
1160
  templateData: templateData,
@@ -1157,29 +1167,43 @@ async function emailerSendEmail( storeData, clientData, lamdaMetrics, lamdaChart
1157
1167
  missedOpportunityCalculation: clientData?.featureConfigs?.missedOpportunityCalculation || 'engagers-conversion',
1158
1168
  bufferTime: 30,
1159
1169
  },
1170
+ } } );
1171
+
1172
+
1173
+ let file = { content: html };
1174
+ let options = {
1175
+ format: 'A4',
1176
+ margin: {
1177
+ top: '0.5in',
1178
+ right: '0.5in',
1179
+ bottom: '0.5in',
1180
+ left: '0.5in',
1181
+ },
1182
+ printBackground: true,
1183
+ preferCSSPageSize: true,
1160
1184
  };
1161
1185
 
1162
- const html = htmlContent( { data: emailVars } );
1186
+ let pdfBuffer = await htmlpdf.generatePdf( file, options );
1187
+ // console.log( 'PDF generated successfully' );
1163
1188
 
1164
- // Prepare email subject and send the email
1165
1189
  const subject = `Footfall Trend Report for ${clientData.clientName}`;
1166
1190
  const ses = JSON.parse( process.env.SES );
1167
1191
 
1168
- // templateData.userEmail
1169
1192
  await sendEmailWithSES(
1170
1193
  'nafila@tangotech.co.in',
1171
1194
  subject,
1172
1195
  html,
1173
- '',
1196
+ {
1197
+ filename: `Attachment_${Date.now()}.pdf`,
1198
+ content: pdfBuffer,
1199
+ contentType: 'application/pdf',
1200
+ },
1174
1201
  ses.adminEmail,
1175
1202
  );
1176
1203
 
1177
- // return res.sendSuccess( { result: 'EMAIL-SENT' } );
1178
-
1179
1204
  return true;
1180
1205
  } catch ( error ) {
1181
- console.log( 'error emailerSendEmail=>', error );
1182
- logger.error( { error: error, function: 'emailerSendEmail' } );
1206
+ console.error( 'Error in emailerSendEmail:', error );
1183
1207
  return false;
1184
1208
  }
1185
1209
  }
@@ -1694,7 +1718,7 @@ const footfallTrend = async ( data ) => {
1694
1718
  await page.waitForSelector( '#Footfalltrend', { visible: true } );
1695
1719
  weeklyChartBuffer = await page.screenshot( { encoding: 'binary' } );
1696
1720
  } catch ( err ) {
1697
- // console.error( 'Error generating chart screenshot:', err );
1721
+ // console.log( 'Error generating chart screenshot:', err );
1698
1722
  throw new Error( 'Failed to generate chart screenshot' );
1699
1723
  } finally {
1700
1724
  await browser.close();
@@ -1702,180 +1726,3 @@ const footfallTrend = async ( data ) => {
1702
1726
 
1703
1727
  return weeklyChartBuffer;
1704
1728
  };
1705
-
1706
-
1707
- // const footfallTrend = async ( data ) => {
1708
- // console.log( 'Generating footfall chart...' );
1709
-
1710
- // const browser = await puppeteer.launch( { headless: true } );
1711
- // const page = await browser.newPage();
1712
-
1713
- // const chartHtmlContent = `
1714
- // <!DOCTYPE html>
1715
- // <html>
1716
- // <head>
1717
- // <style>
1718
- // #Footfalltrend {
1719
- // width: 100%;
1720
- // height: 600px;
1721
- // }
1722
- // </style>
1723
- // <script src="https://cdn.amcharts.com/lib/5/index.js"></script>
1724
- // <script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
1725
- // <script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
1726
- // </head>
1727
- // <body>
1728
- // <div id="Footfalltrend"></div>
1729
- // <script>
1730
- // am5.ready(function() {
1731
- // const root = am5.Root.new('Footfalltrend');
1732
- // root.setThemes([am5themes_Animated.new(root)]);
1733
-
1734
- // const chart = root.container.children.push(
1735
- // am5xy.XYChart.new(root, {
1736
- // panX: false,
1737
- // panY: false,
1738
- // wheelX: 'panX',
1739
- // wheelY: 'zoomX',
1740
- // layout: root.verticalLayout
1741
- // })
1742
- // );
1743
-
1744
- // chart.set("scrollbarX", am5.Scrollbar.new(root, {
1745
- // orientation: "horizontal"
1746
- // }));
1747
-
1748
- // const xRenderer = am5xy.AxisRendererX.new(root, {
1749
- // minGridDistance: 20,
1750
- // minorGridEnabled: true,
1751
- // });
1752
-
1753
- // xRenderer.labels.template.setAll({
1754
- // rotation: -45,
1755
- // centerY: am5.p50,
1756
- // centerX: am5.p100,
1757
- // paddingRight: 5,
1758
- // });
1759
-
1760
- // const xAxis = chart.xAxes.push(
1761
- // am5xy.CategoryAxis.new(root, {
1762
- // categoryField: "storeName",
1763
- // renderer: xRenderer,
1764
- // tooltip: am5.Tooltip.new(root, { labelText: "{fullStoreName}" })
1765
- // })
1766
- // );
1767
-
1768
- // const formattedData = ${JSON.stringify( data )}.map((item) => ({
1769
- // fullStoreName: item.storeName,
1770
- // storeName: item.storeName,
1771
- // footfall: Number(item.footfall_count),
1772
- // conversion: Number(item.conversion_count),
1773
- // bounced: Number(item.bounced_count),
1774
- // engagers: Number(item.engagers_count),
1775
- // missedopportunities: Number(item.missedOpportunity_count),
1776
- // }));
1777
-
1778
- // formattedData.sort((a, b) => {
1779
- // const dateA = new Date(a.storeName);
1780
- // const dateB = new Date(b.storeName);
1781
- // return dateA - dateB;
1782
- // });
1783
-
1784
- // xAxis.data.setAll(formattedData);
1785
-
1786
- // const yAxis = chart.yAxes.push(
1787
- // am5xy.ValueAxis.new(root, {
1788
- // min: 0,
1789
- // renderer: am5xy.AxisRendererY.new(root, {})
1790
- // })
1791
- // );
1792
-
1793
- // yAxis.children.unshift(am5.Label.new(root, {
1794
- // rotation: -90,
1795
- // text: "Footfall",
1796
- // y: am5.p50,
1797
- // centerX: am5.p50,
1798
- // fontFamily: "Arial",
1799
- // fontSize: "14px",
1800
- // fill: am5.color(0x000000)
1801
- // }));
1802
-
1803
- // const createColumnSeries = (name, field, color) => {
1804
- // const series = chart.series.push(
1805
- // am5xy.ColumnSeries.new(root, {
1806
- // name: name,
1807
- // xAxis: xAxis,
1808
- // yAxis: yAxis,
1809
- // valueYField: field,
1810
- // categoryXField: "storeName",
1811
- // fill: color,
1812
- // stroke: color,
1813
- // stacked: true,
1814
- // })
1815
- // );
1816
-
1817
- // series.data.setAll(formattedData);
1818
-
1819
- // series.bullets.push(() => {
1820
- // return am5.Bullet.new(root, {
1821
- // sprite: am5.Label.new(root, {
1822
- // text: "{valueY}",
1823
- // fill: root.interfaceColors.get("alternativeText"),
1824
- // centerY: am5.p50,
1825
- // centerX: am5.p50,
1826
- // populateText: true,
1827
- // fontSize: 12 // Reduce font size
1828
- // })
1829
- // });
1830
- // });
1831
-
1832
- // series.columns.template.setAll({
1833
- // tooltipText: "{name}: {valueY}",
1834
- // width: am5.percent(90),
1835
- // tooltipY: 0,
1836
- // });
1837
-
1838
- // series.appear(1000);
1839
- // return series;
1840
- // };
1841
-
1842
- // createColumnSeries("Bounced", "bounced", am5.color(0x67b7dc));
1843
- // createColumnSeries("Missed Opportunity", "missedopportunities", am5.color(0x6794dc));
1844
- // createColumnSeries("Conversion", "conversion", am5.color(0x6771dc));
1845
-
1846
- // const legend = chart.children.push(
1847
- // am5.Legend.new(root, {
1848
- // centerX: am5.p50,
1849
- // x: am5.p50
1850
- // })
1851
- // );
1852
-
1853
- // legend.data.setAll(chart.series.values);
1854
-
1855
- // chart.set("cursor", am5xy.XYCursor.new(root, {
1856
- // behavior: "none"
1857
- // }));
1858
-
1859
- // chart.appear(1000, 100);
1860
- // });
1861
- // </script>
1862
- // </body>
1863
- // </html>
1864
- // `;
1865
- // let weeklyChartBuffer;
1866
- // try {
1867
- // await page.setContent( chartHtmlContent, { waitUntil: 'domcontentloaded' } );
1868
- // await page.waitForSelector( '#Footfalltrend', { visible: true } );
1869
- // weeklyChartBuffer = await page.screenshot( { encoding: 'binary' } );
1870
- // // await page.screenshot( { path: chartImagePath } );
1871
- // // console.log( 'Screenshot saved to:', chartImagePath );
1872
- // // console.log( 'Screenshot saved to:', chartImagePath );
1873
- // } catch ( err ) {
1874
- // console.error( 'Error generating chart screenshot:', err );
1875
- // throw new Error( 'Failed to generate chart screenshot' );
1876
- // } finally {
1877
- // await browser.close();
1878
- // }
1879
-
1880
- // return weeklyChartBuffer;
1881
- // };