tango-app-api-audit 3.5.41 → 3.5.43

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/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # README #
2
-
3
- This README would normally document whatever steps are necessary to get your application up and running.
4
-
5
- ### What is this repository for? ###
6
-
7
- * Quick summary
8
- * Version
9
- * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
-
11
- ### How do I get set up? ###
12
-
13
- * Summary of set up
14
- * Configuration
15
- * Dependencies
16
- * Database configuration
17
- * How to run tests
18
- * Deployment instructions
19
-
20
- ### Contribution guidelines ###
21
-
22
- * Writing tests
23
- * Code review
24
- * Other guidelines
25
-
26
- ### Who do I talk to? ###
27
-
28
- * Repo owner or admin
1
+ # README #
2
+
3
+ This README would normally document whatever steps are necessary to get your application up and running.
4
+
5
+ ### What is this repository for? ###
6
+
7
+ * Quick summary
8
+ * Version
9
+ * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
+
11
+ ### How do I get set up? ###
12
+
13
+ * Summary of set up
14
+ * Configuration
15
+ * Dependencies
16
+ * Database configuration
17
+ * How to run tests
18
+ * Deployment instructions
19
+
20
+ ### Contribution guidelines ###
21
+
22
+ * Writing tests
23
+ * Code review
24
+ * Other guidelines
25
+
26
+ ### Who do I talk to? ###
27
+
28
+ * Repo owner or admin
29
29
  * Other community or team contact
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.5.41",
3
+ "version": "3.5.43",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -255,9 +255,9 @@ export async function getList( req, res ) {
255
255
  'Store ID': element?._source?.storeId || 'Un Assigned',
256
256
  'Store Name': element?._source?.storeName ||'Un Assigned',
257
257
  'Engagement ID': element?._source?.engagementId,
258
- 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
258
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 )+' %': '0 %',
259
259
  'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
260
- 'Trust Score': element?._source?.trustScore ||0,
260
+ 'Trust Score': `${element?._source?.trustScore || 0} %`,
261
261
  'Test Duration': duration || '',
262
262
  'Audit Status': element?._source?.auditStatus || '',
263
263
  'Audited By': userName?.userName || '',
@@ -280,7 +280,8 @@ export async function getList( req, res ) {
280
280
  const testDuration = searchValue[i]?._source?.testDuration;
281
281
  const minutes = Math.floor( testDuration / 60 );
282
282
  const seconds = testDuration % 60;
283
- searchValue[i]._source.complianceScore = searchValue[i]?._source?.totalSteps>0 ? Math.round( ( searchValue[i]?._source?.coveredStepsAI/ searchValue[i]?._source?.totalSteps )*100 ): 0;
283
+ searchValue[i]._source.complianceScore = searchValue[i]?._source?.totalSteps>0 ? Math.round( ( searchValue[i]?._source?.coveredStepsAI/ searchValue[i]?._source?.totalSteps )*100 ) + ' %': '0 %';
284
+ searchValue[i]._source.trustScore = searchValue[i]._source.trustScore !== null && searchValue[i]._source.trustScore !== undefined? Math( searchValue[i]._source.trustScore ) + ' %': 'NA';
284
285
  searchValue[i]._source.min = minutes;
285
286
  searchValue[i]._source.sec = seconds;
286
287
  searchValue[i]._source.auditedBy = userName?.userName || '';
@@ -1209,12 +1210,19 @@ export async function summaryList( req, res ) {
1209
1210
  [inputData?.sortBy]: sortOrder,
1210
1211
  };
1211
1212
  }
1213
+ let clusterFilter = [
1214
+ { 'Teamlead.email': { $in: inputData.RMList } },
1215
+ { clientId: { $eq: inputData?.clientId } },
1216
+ ];
1217
+ if ( inputData?.cluster && inputData?.cluster?.length> 0 ) {
1218
+ clusterFilter.push( {
1219
+ clusterName: { $in: inputData?.cluster },
1220
+ } );
1221
+ }
1212
1222
  const clusterQuery =[
1213
1223
  { $match: {
1214
- $and: [
1215
- { 'Teamlead.email': { $in: inputData.RMList } },
1216
- { clientId: { $eq: inputData?.clientId } },
1217
- ],
1224
+ $and: clusterFilter,
1225
+
1218
1226
  },
1219
1227
  },
1220
1228
  { $unwind: { path: '$Teamlead', preserveNullAndEmptyArrays: true } },
@@ -1349,6 +1357,23 @@ export async function summaryList( req, res ) {
1349
1357
  $sort: sort,
1350
1358
  },
1351
1359
  ];
1360
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
1361
+ clusterQuery.push( {
1362
+ $match: {
1363
+ $or: [
1364
+ { clusterName: { $regex: inputData.searchValue, $options: 'i' } },
1365
+ ],
1366
+ },
1367
+ } );
1368
+
1369
+ RMQuery.push( {
1370
+ $match: {
1371
+ $or: [
1372
+ { RMName: { $regex: inputData.searchValue, $options: 'i' } },
1373
+ ],
1374
+ },
1375
+ } );
1376
+ }
1352
1377
  const getcount = await aggregateClusters( inputData.keyType === 'rm'?RMQuery: clusterQuery );
1353
1378
  const count = getcount?.length || 0;
1354
1379
  if ( count == 0 ) {
@@ -1379,7 +1404,6 @@ export async function summaryList( req, res ) {
1379
1404
  const temp =[];
1380
1405
  for ( const [ i, cluster ] of getCluster.entries() ) {
1381
1406
  temp.push( cluster );
1382
-
1383
1407
  const getClusterQuery= {
1384
1408
  'size': 0,
1385
1409
  'query': {
@@ -1419,7 +1443,7 @@ export async function summaryList( req, res ) {
1419
1443
  temp[i].totalFiles = getResponse?.body?.aggregations?.total_count?.value || 0,
1420
1444
  temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
1421
1445
  temp[i].complianceScore = `${ Math.round( getResponse?.body?.aggregations?.avg_complianceScore?.value || 0 )} %`;
1422
- temp[i].trustScore = getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ==null || getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value == undefined ?'NA':`${getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value + ' %'}`;
1446
+ temp[i].trustScore = getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ==null || getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value == undefined ?'NA':`${Math.round( getResponse?.body?.aggregations?.audited_trustScore?.avg_trustScore?.value ) + ' %'}`;
1423
1447
  }
1424
1448
  }
1425
1449
 
@@ -1431,8 +1455,8 @@ export async function summaryList( req, res ) {
1431
1455
  if ( inputData?.keyType == 'rm' ) {
1432
1456
  exportData.push( {
1433
1457
  'RM Name': element?.RMName,
1434
- 'Cluster Count': element?.clusterCount,
1435
- 'Store Count': element?.storesCount,
1458
+ 'Clusters Count': element?.clusterCount,
1459
+ 'Stores Count': element?.storesCount,
1436
1460
  'Total Tango AI Files': element.totalFiles,
1437
1461
  'Trust Audit Completed': element.completedFiles,
1438
1462
  'Tango Score': element?.complianceScore,
@@ -1443,7 +1467,7 @@ export async function summaryList( req, res ) {
1443
1467
  } else {
1444
1468
  exportData.push( {
1445
1469
  'Cluster Name': element?.clusterName,
1446
- 'Store Count': element?.storesCount,
1470
+ 'Stores Count': element?.storesCount,
1447
1471
  'Total Tango AI Files': element.totalFiles,
1448
1472
  'Trust Audit Completed': element.completedFiles,
1449
1473
  'Tango Score': element?.complianceScore,
@@ -1673,7 +1697,7 @@ export async function summaryList( req, res ) {
1673
1697
  'Engagement ID': element?._source?.engagementId,
1674
1698
  'Tango Score': `${element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0} %`,
1675
1699
  'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
1676
- 'Trust Score': `${element?._source?.trustScore ||0}`,
1700
+ 'Trust Score': `${element?._source?.trustScore ||0} %`,
1677
1701
  'Test Duration': duration || '',
1678
1702
  'Audit Status': element?._source?.auditStatus || '',
1679
1703
  'Audited By': userName?.userName || '',
@@ -1859,16 +1883,16 @@ export async function summaryCard( req, res ) {
1859
1883
  aggs: {
1860
1884
 
1861
1885
 
1862
- totalFiles: { value_count: { field: '_id' } },
1886
+ 'totalFiles': { value_count: { field: '_id' } },
1863
1887
 
1864
- completedFiles: {
1888
+ 'completedFiles': {
1865
1889
  filter: {
1866
- terms: { 'auditStatus.keyword': [ 'audited', 'reAudited' ] },
1890
+ terms: { 'auditStatus.keyword': [ 'Audited', 'ReAudited' ] },
1867
1891
  },
1868
1892
  },
1869
1893
 
1870
1894
  // ratio calc must be inside the same level
1871
- completedRatio: {
1895
+ 'completedRatio': {
1872
1896
  bucket_script: {
1873
1897
  buckets_path: {
1874
1898
  audited: 'completedFiles._count',
@@ -1878,31 +1902,23 @@ export async function summaryCard( req, res ) {
1878
1902
  },
1879
1903
  },
1880
1904
 
1881
- tangoScore: {
1882
- scripted_metric: {
1883
- init_script: 'state.sum = 0; state.count = 0;',
1884
- map_script: `
1885
- if (doc['totalSteps'].size() != 0 && doc['totalSteps'].value > 0) {
1886
- state.sum += (doc['coveredStepsAI'].value / doc['totalSteps'].value) * 100;
1887
- state.count += 1;
1888
- }
1889
- `,
1890
- combine_script: 'return state;',
1891
- reduce_script: `
1892
- double totalSum = 0;
1893
- double totalCount = 0;
1894
- for (s in states) {
1895
- totalSum += s.sum;
1896
- totalCount += s.count;
1897
- }
1898
- return totalCount > 0 ? totalSum / totalCount : 0;
1899
- `,
1905
+ 'tangoScore': {
1906
+ 'avg': {
1907
+ script: {
1908
+ source: `
1909
+ if (doc['totalSteps'].size() > 0 && doc['coveredStepsAI'].size() > 0 && doc['totalSteps'].value > 0) {
1910
+ return (1.0 * doc['coveredStepsAI'].value / doc['totalSteps'].value) * 100.0;
1911
+ } else {
1912
+ return null;
1913
+ }
1914
+ `,
1915
+ },
1900
1916
  },
1901
1917
  },
1902
1918
 
1903
- trustScore: {
1919
+ 'trustScore': {
1904
1920
  filter: {
1905
- terms: { 'auditStatus.keyword': [ 'audited', 'reAudited' ] },
1921
+ terms: { 'auditStatus.keyword': [ 'Audited', 'ReAudited' ] },
1906
1922
  },
1907
1923
  aggs: {
1908
1924
  avg_val: { avg: { field: 'trustScore' } },
@@ -1910,7 +1926,7 @@ export async function summaryCard( req, res ) {
1910
1926
  },
1911
1927
 
1912
1928
  // 5. Past week comparison
1913
- trend: {
1929
+ 'trend': {
1914
1930
  date_range: {
1915
1931
  field: 'date',
1916
1932
  format: 'yyyy-MM-dd',
@@ -1923,7 +1939,7 @@ export async function summaryCard( req, res ) {
1923
1939
  total_count: { value_count: { field: '_id' } },
1924
1940
  },
1925
1941
  },
1926
- tangoScoreTrend: {
1942
+ 'tangoScoreTrend': {
1927
1943
  bucket_script: {
1928
1944
  buckets_path: {
1929
1945
  current: 'trend[\'current\']>total_count',
@@ -1961,7 +1977,7 @@ export async function summaryCard( req, res ) {
1961
1977
  const temp= getOutput?.body?.aggregations?.all_docs?.wrapper?.buckets?.filtered;
1962
1978
  initialValue.totalFiles =temp?.totalFiles?.value;
1963
1979
  initialValue.completedFiles =temp?.completedFiles?.doc_count;
1964
- initialValue.completedRatio =temp?.completedRatio?.value || 0;
1980
+ initialValue.completedRatio =Math.round( temp?.completedRatio?.value || 0 );
1965
1981
  initialValue.tangoScore =Math.round( temp?.tangoScore?.value || 0 );
1966
1982
  initialValue.tangoScoreTrend =temp?.tangoScoreTrend?.value || 0;
1967
1983
  initialValue.trustScore =temp?.trustScore?.avg_val?.value == null || temp?.trustScore?.avg_val?.value === undefined ? 'NA':Math.round( temp?.trustScore?.avg_val?.value );
@@ -151,6 +151,9 @@ export const summaryListSchema = joi.object( {
151
151
  RMList: joi.array().items(
152
152
  joi.string().required(),
153
153
  ).optional(),
154
+ cluster: joi.array().items(
155
+ joi.string().required(),
156
+ ).optional(),
154
157
  storeId: joi.array().items( joi.string().required() ).required(),
155
158
  complianceScore: joi.number().optional().allow( null ),
156
159
  nearAddition: joi.string().optional().allow( '' ),