tango-app-api-infra 3.3.3-beta.11 → 3.3.3-beta.12

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-infra",
3
- "version": "3.3.3-beta.11",
3
+ "version": "3.3.3-beta.12",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1914,8 +1914,58 @@ export async function infraTable( req, res ) {
1914
1914
  let result = await aggregateTangoTicket( query );
1915
1915
  if ( req.body.export && result.length > 0 ) {
1916
1916
  const exportdata = [];
1917
+
1917
1918
  if ( req.user.userType === 'tango' ) {
1918
- result.forEach( ( element ) => {
1919
+ for ( const element of result ) {
1920
+ // find total downtime
1921
+ const issueDate = new Date( element?.issueDate )
1922
+ .toISOString()
1923
+ .split( 'T' )[0]
1924
+ .split( '-' )
1925
+ .reverse()
1926
+ .join( '-' );
1927
+ const query = {
1928
+ size: 0,
1929
+ query: {
1930
+ bool: {
1931
+ must: [
1932
+ { term: { 'doc.store_id.keyword': element.storeId } },
1933
+ { term: { 'doc.date.keyword': issueDate } },
1934
+ ],
1935
+ },
1936
+ },
1937
+ aggs: {
1938
+ total_avg_downtime: {
1939
+ scripted_metric: {
1940
+ init_script: 'state.total = 0.0;',
1941
+ map_script: `
1942
+ def streams = params._source.doc.streamwise_downtime;
1943
+ if (streams != null && streams.size() > 0) {
1944
+ double sum = 0.0;
1945
+ for (s in streams) {
1946
+ sum += s.down_time;
1947
+ }
1948
+ state.total += sum / streams.size();
1949
+ }
1950
+ `,
1951
+ combine_script: 'return state.total;',
1952
+ reduce_script: `
1953
+ double finalSum = 0.0;
1954
+ for (s in states) {
1955
+ finalSum += s;
1956
+ }
1957
+ return finalSum;
1958
+ `,
1959
+ },
1960
+ },
1961
+ },
1962
+ };
1963
+
1964
+ const openSearchdata = await getOpenSearchData( opensearch.downTimeHourly, query );
1965
+ const value = openSearchdata?.body?.aggregations?.total_avg_downtime?.value ?? 0;
1966
+ const rounded = Math.round( value );
1967
+
1968
+
1919
1969
  exportdata.push( {
1920
1970
  'Ticket ID': element.ticketId,
1921
1971
  'Created Date': dayjs( element.issueDate ).format( 'DD MMM, YYYY' ),
@@ -1928,13 +1978,62 @@ export async function infraTable( req, res ) {
1928
1978
  'Resolved By': element.userName,
1929
1979
  'Status': element.status,
1930
1980
  'Configured Ticket Time': `${element.configuredDownTime? element.configuredDownTime*60 : 0} min`,
1981
+ 'Total Downtime': `${rounded} min`,
1931
1982
  'Primary Issues': element.primaryIssue == '-' ? 'Issue not identified' : element.primaryIssue,
1932
1983
  'Secondary Issues': element.secondaryIssue,
1933
1984
  'Comment': element.otherscomment ? element.otherscomment : ( element.commentText ? element.commentText : '-' ),
1934
1985
  } );
1935
- } );
1986
+ }
1936
1987
  } else {
1937
- result.forEach( ( element ) => {
1988
+ for ( const element of result ) {
1989
+ // find total downtime
1990
+ const issueDate = new Date( element?.issueDate )
1991
+ .toISOString()
1992
+ .split( 'T' )[0]
1993
+ .split( '-' )
1994
+ .reverse()
1995
+ .join( '-' );
1996
+ const query = {
1997
+ size: 0,
1998
+ query: {
1999
+ bool: {
2000
+ must: [
2001
+ { term: { 'doc.store_id.keyword': element.storeId } },
2002
+ { term: { 'doc.date.keyword': issueDate } },
2003
+ ],
2004
+ },
2005
+ },
2006
+ aggs: {
2007
+ total_avg_downtime: {
2008
+ scripted_metric: {
2009
+ init_script: 'state.total = 0.0;',
2010
+ map_script: `
2011
+ def streams = params._source.doc.streamwise_downtime;
2012
+ if (streams != null && streams.size() > 0) {
2013
+ double sum = 0.0;
2014
+ for (s in streams) {
2015
+ sum += s.down_time;
2016
+ }
2017
+ state.total += sum / streams.size();
2018
+ }
2019
+ `,
2020
+ combine_script: 'return state.total;',
2021
+ reduce_script: `
2022
+ double finalSum = 0.0;
2023
+ for (s in states) {
2024
+ finalSum += s;
2025
+ }
2026
+ return finalSum;
2027
+ `,
2028
+ },
2029
+ },
2030
+ },
2031
+ };
2032
+
2033
+ const openSearchdata = await getOpenSearchData( opensearch.downTimeHourly, query );
2034
+ const value = openSearchdata?.body?.aggregations?.total_avg_downtime?.value ?? 0;
2035
+ const rounded = Math.round( value );
2036
+
1938
2037
  exportdata.push( {
1939
2038
  'Ticket ID': element.ticketId,
1940
2039
  'Created Date': dayjs( element.issueDate ).format( 'DD MMM, YYYY' ),
@@ -1942,11 +2041,12 @@ export async function infraTable( req, res ) {
1942
2041
  'Store ID': element.storeId,
1943
2042
  'Status': element.status,
1944
2043
  'Configured Ticket Time': `${element.configuredDownTime? element.configuredDownTime*60 : 0} min`,
2044
+ 'Total Downtime': `${rounded} min`,
1945
2045
  'Primary Issues': element.primaryIssue == '-' ? 'Issue not identified' : element.primaryIssue,
1946
2046
  'Secondary Issues': element.secondaryIssue,
1947
2047
  'Comment': element.otherscomment ? element.otherscomment : ( element.commentText ? element.commentText : '-' ),
1948
2048
  } );
1949
- } );
2049
+ }
1950
2050
  }
1951
2051
 
1952
2052
  await download( exportdata, res );