@rh-support/utils 0.2.31 → 0.2.34-alpha-0

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.
@@ -22,4 +22,5 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -34,3 +34,4 @@ __exportStar(require("./customElementUtils"), exports);
34
34
  __exportStar(require("./userUtils"), exports);
35
35
  __exportStar(require("./styleUtils"), exports);
36
36
  __exportStar(require("./translation-helper"), exports);
37
+ __exportStar(require("./outlier"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"insightRuleInfoUtils.d.ts","sourceRoot":"","sources":["../../src/insightRuleInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AASlE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,UAM3E;AAOD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,OAIzE"}
1
+ {"version":3,"file":"insightRuleInfoUtils.d.ts","sourceRoot":"","sources":["../../src/insightRuleInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AASlE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,UAI3E;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,OAIzE"}
@@ -14,15 +14,9 @@ doT_1.default.templateSettings = assign_1.default({}, doT_1.default.templateSett
14
14
  function getRuleReasonHtml(ruleReason, reportDetails) {
15
15
  var resultText = parseDotTemplate(ruleReason, reportDetails);
16
16
  var html = ui_toolkit_1.markdownToHTML(resultText);
17
- var anchorTagRegex = new RegExp("<a", 'g');
18
- var modifiedHtml = html.toString().replace(anchorTagRegex, '<a class="pf-c-button pf-m-link anchor-tag-button"');
19
- return modifiedHtml;
17
+ return html;
20
18
  }
21
19
  exports.getRuleReasonHtml = getRuleReasonHtml;
22
- // TODO: Remove modifiedHtml once Accordion Bug is fixed and Replace with below code
23
- // const resultText = parseDotTemplate(ruleReason, reportDetails);
24
- // const html = markdownToHTML(resultText);
25
- // return html as string;
26
20
  function parseDotTemplate(dotString, reportDetails) {
27
21
  var tempFn = doT_1.default.template(dotString);
28
22
  var parsedDotString = tempFn(reportDetails);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export declare const outlier: (array: Array<number>) => Array<number>;
16
+ //# sourceMappingURL=outlier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outlier.d.ts","sourceRoot":"","sources":["../../src/outlier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,OAAO,UAAW,MAAM,MAAM,CAAC,KAAG,MAAM,MAAM,CAkC1D,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Outlier Function
4
+ * Refer: https://www.cuemath.com/outlier-formula/
5
+ *
6
+ * An outlier function which takers array of number and find high outlier and low outlier
7
+ * 1. Taker array of number and sort then in ascending order.
8
+ * 2. Calculate first(q1) and third(q3) quartile.
9
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
10
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
11
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
12
+ *
13
+ * @param {number[]} numbers
14
+ * @returns {number[]} upper and lower boundary value
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.outlier = void 0;
18
+ var outlier = function (array) {
19
+ // Take array length
20
+ var arrayLength = array.length;
21
+ // Check if length is smaller than four then return array result as it is
22
+ if (arrayLength < 4) {
23
+ return array;
24
+ }
25
+ var q1, q3, iqr, upperBoundary, lowerBoundary;
26
+ // Make a copy of array plus sort it in ascending order
27
+ var sortedArray = array.slice().sort(function (a, b) { return a - b; });
28
+ // Find the quartiles range
29
+ // If median is odd adjust the index by minus one
30
+ if (((arrayLength - 1) / 4) % 1 === 0 || (arrayLength / 4) % 1 === 0) {
31
+ q1 = (1 / 2) * (sortedArray[Math.floor(arrayLength / 4) - 1] + sortedArray[Math.floor(arrayLength / 4)]);
32
+ q3 =
33
+ (1 / 2) *
34
+ (sortedArray[Math.ceil(arrayLength * (3 / 4)) - 1] + sortedArray[Math.ceil(arrayLength * (3 / 4))]);
35
+ }
36
+ else {
37
+ q1 = sortedArray[Math.floor(arrayLength / 4)];
38
+ q3 = sortedArray[Math.floor(arrayLength * (3 / 4))];
39
+ }
40
+ // Calculate inter-quartile range
41
+ iqr = q3 - q1;
42
+ // upper boundary
43
+ upperBoundary = q3 + iqr * 1.5;
44
+ // lower boundary
45
+ lowerBoundary = q1 - iqr * 1.5;
46
+ return [upperBoundary, lowerBoundary];
47
+ };
48
+ exports.outlier = outlier;
@@ -4,20 +4,13 @@ export interface ITroubleshootProductResponse {
4
4
  otherProducts: Partial<ISEProduct>[];
5
5
  productsResult: Partial<ISEProduct>[];
6
6
  }
7
- export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
7
+ export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[], topCount?: number) => ITroubleshootProductResponse;
8
8
  /**
9
- * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
10
- * and need to create partial response like method `handleProductSearchResponse`
11
- * @param productsResultEntitled IProductV2[]
12
- * @returns ITroubleshootProductResponse
13
- */
14
- export declare const handleEntitledProductResponse: (productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
15
- /**
16
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
9
+ * Tries to get top products with priority given to recentlyFiledAgainst
17
10
  * before checking general top products from un-authed SE API
18
11
  * @param products Partial<ISEProduct>
19
12
  */
20
- export declare function getTopProducts(products: Partial<ISEProduct>[]): Partial<ISEProduct>[];
13
+ export declare function getTopProducts(products: Partial<ISEProduct>[], topCount?: number): Partial<ISEProduct>[];
21
14
  export declare function isOnlyVersion(versions: string[]): boolean;
22
15
  export declare function getVersionIfOnlyVersion(versions: string[]): string;
23
16
  export declare function getUniqueSortedVersions(versions: string[]): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"productsUtils.d.ts","sourceRoot":"","sources":["../../src/productsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAWhF,MAAM,WAAW,4BAA4B;IACzC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACnC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACrC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;CACzC;AAED,eAAO,MAAM,2BAA2B,sBACjB,UAAU,EAAE,2BACP,UAAU,EAAE,KACrC,4BA6BF,CAAC;AAEF;;;;;GAKG;AACH,eAA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AE/C;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAEzD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAEzD;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,MAAM,MAAM,eAmBnD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,aAExC,CAAC;AAEF,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAkBlE"}
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.getVersion = exports.versionSort = exports.versionSorter = exports.getUniqueSortedVersions = exports.getVersionIfOnlyVersion = exports.isOnlyVersion = exports.getTopProducts = exports.handleEntitledProductResponse = exports.handleProductSearchResponse = void 0;
38
+ exports.getVersion = exports.versionSort = exports.versionSorter = exports.getUniqueSortedVersions = exports.getVersionIfOnlyVersion = exports.isOnlyVersion = exports.getTopProducts = exports.handleProductSearchResponse = void 0;
39
39
  var difference_1 = __importDefault(require("lodash/difference"));
40
40
  var forEach_1 = __importDefault(require("lodash/forEach"));
41
41
  var isEmpty_1 = __importDefault(require("lodash/isEmpty"));
@@ -44,8 +44,9 @@ var orderBy_1 = __importDefault(require("lodash/orderBy"));
44
44
  var remove_1 = __importDefault(require("lodash/remove"));
45
45
  var uniq_1 = __importDefault(require("lodash/uniq"));
46
46
  var validatorUtils_1 = require("./validatorUtils");
47
- var handleProductSearchResponse = function (productsResultAll, productsResultEntitled) {
47
+ var handleProductSearchResponse = function (productsResultAll, productsResultEntitled, topCount) {
48
48
  if (productsResultEntitled === void 0) { productsResultEntitled = []; }
49
+ if (topCount === void 0) { topCount = 5; }
49
50
  var productsResultEntitledMap = {};
50
51
  forEach_1.default(productsResultEntitled, function (p) {
51
52
  // if (p.supportedForCustomer) { // Needs confirmation froom CCM team before adding
@@ -60,9 +61,8 @@ var handleProductSearchResponse = function (productsResultAll, productsResultEnt
60
61
  ? product.featuredVersion
61
62
  : (_d = product === null || product === void 0 ? void 0 : product.versions[0]) !== null && _d !== void 0 ? _d : '' });
62
63
  });
63
- // first top 5 products before sorting
64
64
  // we get products based on the highest number of support cases
65
- var topProducts = getTopProducts(productsResult);
65
+ var topProducts = getTopProducts(productsResult, topCount);
66
66
  var productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
67
67
  return {
68
68
  productsResult: productsResultSorted,
@@ -72,37 +72,18 @@ var handleProductSearchResponse = function (productsResultAll, productsResultEnt
72
72
  };
73
73
  exports.handleProductSearchResponse = handleProductSearchResponse;
74
74
  /**
75
- * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
76
- * and need to create partial response like method `handleProductSearchResponse`
77
- * @param productsResultEntitled IProductV2[]
78
- * @returns ITroubleshootProductResponse
79
- */
80
- var handleEntitledProductResponse = function (productsResultEntitled) {
81
- if (productsResultEntitled === void 0) { productsResultEntitled = []; }
82
- var productsResult = productsResultEntitled.map(function (product) {
83
- return __assign(__assign({}, product), { product: product.name });
84
- });
85
- var topProducts = getTopProducts(productsResult);
86
- var productsResultSorted = orderBy_1.default(productsResult, ['product'], ['asc']);
87
- return {
88
- productsResult: productsResultSorted,
89
- topProducts: topProducts,
90
- otherProducts: difference_1.default(productsResultSorted, topProducts),
91
- };
92
- };
93
- exports.handleEntitledProductResponse = handleEntitledProductResponse;
94
- /**
95
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
75
+ * Tries to get top products with priority given to recentlyFiledAgainst
96
76
  * before checking general top products from un-authed SE API
97
77
  * @param products Partial<ISEProduct>
98
78
  */
99
- function getTopProducts(products) {
79
+ function getTopProducts(products, topCount) {
80
+ if (topCount === void 0) { topCount = 5; }
100
81
  var toReturn = remove_1.default(__spreadArray([], __read(products)), function (o) { return o.recentlyFiledAgainst; });
101
- if (toReturn.length < 5) {
82
+ if (toReturn.length < topCount) {
102
83
  var generalTopProducts = remove_1.default(__spreadArray([], __read(products)), function (o) { return !o.recentlyFiledAgainst && o.isTopProduct; });
103
84
  toReturn.push.apply(toReturn, __spreadArray([], __read(generalTopProducts)));
104
85
  }
105
- return toReturn.slice(0, 5);
86
+ return toReturn.slice(0, topCount);
106
87
  }
107
88
  exports.getTopProducts = getTopProducts;
108
89
  function isOnlyVersion(versions) {
@@ -22,4 +22,5 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
25
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,yBAAyB,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
package/lib/esm/index.js CHANGED
@@ -22,3 +22,4 @@ export * from './customElementUtils';
22
22
  export * from './userUtils';
23
23
  export * from './styleUtils';
24
24
  export * from './translation-helper';
25
+ export * from './outlier';
@@ -1 +1 @@
1
- {"version":3,"file":"insightRuleInfoUtils.d.ts","sourceRoot":"","sources":["../../src/insightRuleInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AASlE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,UAM3E;AAOD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,OAIzE"}
1
+ {"version":3,"file":"insightRuleInfoUtils.d.ts","sourceRoot":"","sources":["../../src/insightRuleInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yCAAyC,CAAC;AASlE,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,UAI3E;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,OAIzE"}
@@ -8,14 +8,8 @@ doT.templateSettings = assign({}, doT.templateSettings, {
8
8
  export function getRuleReasonHtml(ruleReason, reportDetails) {
9
9
  const resultText = parseDotTemplate(ruleReason, reportDetails);
10
10
  const html = markdownToHTML(resultText);
11
- const anchorTagRegex = new RegExp(`<a`, 'g');
12
- const modifiedHtml = html.toString().replace(anchorTagRegex, '<a class="pf-c-button pf-m-link anchor-tag-button"');
13
- return modifiedHtml;
11
+ return html;
14
12
  }
15
- // TODO: Remove modifiedHtml once Accordion Bug is fixed and Replace with below code
16
- // const resultText = parseDotTemplate(ruleReason, reportDetails);
17
- // const html = markdownToHTML(resultText);
18
- // return html as string;
19
13
  export function parseDotTemplate(dotString, reportDetails) {
20
14
  const tempFn = doT.template(dotString);
21
15
  const parsedDotString = tempFn(reportDetails);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export declare const outlier: (array: Array<number>) => Array<number>;
16
+ //# sourceMappingURL=outlier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outlier.d.ts","sourceRoot":"","sources":["../../src/outlier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,OAAO,UAAW,MAAM,MAAM,CAAC,KAAG,MAAM,MAAM,CAkC1D,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Outlier Function
3
+ * Refer: https://www.cuemath.com/outlier-formula/
4
+ *
5
+ * An outlier function which takers array of number and find high outlier and low outlier
6
+ * 1. Taker array of number and sort then in ascending order.
7
+ * 2. Calculate first(q1) and third(q3) quartile.
8
+ * 3. Calculate inter-quartile(iqr) range (q3-q1).
9
+ * 4. Find the upper boundary value by formula q3 + iqr*1.5.
10
+ * 5. Find the lower boundary value by formula q1 - iqr*1.5
11
+ *
12
+ * @param {number[]} numbers
13
+ * @returns {number[]} upper and lower boundary value
14
+ */
15
+ export const outlier = (array) => {
16
+ // Take array length
17
+ const arrayLength = array.length;
18
+ // Check if length is smaller than four then return array result as it is
19
+ if (arrayLength < 4) {
20
+ return array;
21
+ }
22
+ let q1, q3, iqr, upperBoundary, lowerBoundary;
23
+ // Make a copy of array plus sort it in ascending order
24
+ const sortedArray = array.slice().sort((a, b) => a - b);
25
+ // Find the quartiles range
26
+ // If median is odd adjust the index by minus one
27
+ if (((arrayLength - 1) / 4) % 1 === 0 || (arrayLength / 4) % 1 === 0) {
28
+ q1 = (1 / 2) * (sortedArray[Math.floor(arrayLength / 4) - 1] + sortedArray[Math.floor(arrayLength / 4)]);
29
+ q3 =
30
+ (1 / 2) *
31
+ (sortedArray[Math.ceil(arrayLength * (3 / 4)) - 1] + sortedArray[Math.ceil(arrayLength * (3 / 4))]);
32
+ }
33
+ else {
34
+ q1 = sortedArray[Math.floor(arrayLength / 4)];
35
+ q3 = sortedArray[Math.floor(arrayLength * (3 / 4))];
36
+ }
37
+ // Calculate inter-quartile range
38
+ iqr = q3 - q1;
39
+ // upper boundary
40
+ upperBoundary = q3 + iqr * 1.5;
41
+ // lower boundary
42
+ lowerBoundary = q1 - iqr * 1.5;
43
+ return [upperBoundary, lowerBoundary];
44
+ };
@@ -4,20 +4,13 @@ export interface ITroubleshootProductResponse {
4
4
  otherProducts: Partial<ISEProduct>[];
5
5
  productsResult: Partial<ISEProduct>[];
6
6
  }
7
- export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
7
+ export declare const handleProductSearchResponse: (productsResultAll: ISEProduct[], productsResultEntitled?: IProductV2[], topCount?: number) => ITroubleshootProductResponse;
8
8
  /**
9
- * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
10
- * and need to create partial response like method `handleProductSearchResponse`
11
- * @param productsResultEntitled IProductV2[]
12
- * @returns ITroubleshootProductResponse
13
- */
14
- export declare const handleEntitledProductResponse: (productsResultEntitled?: IProductV2[]) => ITroubleshootProductResponse;
15
- /**
16
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
9
+ * Tries to get top products with priority given to recentlyFiledAgainst
17
10
  * before checking general top products from un-authed SE API
18
11
  * @param products Partial<ISEProduct>
19
12
  */
20
- export declare function getTopProducts(products: Partial<ISEProduct>[]): Partial<ISEProduct>[];
13
+ export declare function getTopProducts(products: Partial<ISEProduct>[], topCount?: number): Partial<ISEProduct>[];
21
14
  export declare function isOnlyVersion(versions: string[]): boolean;
22
15
  export declare function getVersionIfOnlyVersion(versions: string[]): string;
23
16
  export declare function getUniqueSortedVersions(versions: string[]): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"productsUtils.d.ts","sourceRoot":"","sources":["../../src/productsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAWhF,MAAM,WAAW,4BAA4B;IACzC,WAAW,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACnC,aAAa,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IACrC,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;CACzC;AAED,eAAO,MAAM,2BAA2B,sBACjB,UAAU,EAAE,2BACP,UAAU,EAAE,KACrC,4BA6BF,CAAC;AAEF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,EAAE,MAAM,EAAE,WAE/C;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAEzD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAEzD;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,MAAM,MAAM,eAmBnD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,aAExC,CAAC;AAEF,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAkBlE"}
@@ -6,7 +6,7 @@ import orderBy from 'lodash/orderBy';
6
6
  import filter from 'lodash/remove';
7
7
  import uniq from 'lodash/uniq';
8
8
  import { isNumber } from './validatorUtils';
9
- export const handleProductSearchResponse = (productsResultAll, productsResultEntitled = []) => {
9
+ export const handleProductSearchResponse = (productsResultAll, productsResultEntitled = [], topCount = 5) => {
10
10
  const productsResultEntitledMap = {};
11
11
  forEach(productsResultEntitled, (p) => {
12
12
  // if (p.supportedForCustomer) { // Needs confirmation froom CCM team before adding
@@ -21,9 +21,8 @@ export const handleProductSearchResponse = (productsResultAll, productsResultEnt
21
21
  ? product.featuredVersion
22
22
  : (_d = product === null || product === void 0 ? void 0 : product.versions[0]) !== null && _d !== void 0 ? _d : '' });
23
23
  });
24
- // first top 5 products before sorting
25
24
  // we get products based on the highest number of support cases
26
- const topProducts = getTopProducts(productsResult);
25
+ const topProducts = getTopProducts(productsResult, topCount);
27
26
  const productsResultSorted = orderBy(productsResult, ['product'], ['asc']);
28
27
  return {
29
28
  productsResult: productsResultSorted,
@@ -32,35 +31,17 @@ export const handleProductSearchResponse = (productsResultAll, productsResultEnt
32
31
  };
33
32
  };
34
33
  /**
35
- * This method is used for parsing `hydra/rest/products/contact/{userName}` response form API
36
- * and need to create partial response like method `handleProductSearchResponse`
37
- * @param productsResultEntitled IProductV2[]
38
- * @returns ITroubleshootProductResponse
39
- */
40
- export const handleEntitledProductResponse = (productsResultEntitled = []) => {
41
- const productsResult = productsResultEntitled.map((product) => {
42
- return Object.assign(Object.assign({}, product), { product: product.name });
43
- });
44
- const topProducts = getTopProducts(productsResult);
45
- const productsResultSorted = orderBy(productsResult, ['product'], ['asc']);
46
- return {
47
- productsResult: productsResultSorted,
48
- topProducts,
49
- otherProducts: difference(productsResultSorted, topProducts),
50
- };
51
- };
52
- /**
53
- * Tries to get top 5 products with priority given to recentlyFiledAgainst
34
+ * Tries to get top products with priority given to recentlyFiledAgainst
54
35
  * before checking general top products from un-authed SE API
55
36
  * @param products Partial<ISEProduct>
56
37
  */
57
- export function getTopProducts(products) {
38
+ export function getTopProducts(products, topCount = 5) {
58
39
  const toReturn = filter([...products], (o) => o.recentlyFiledAgainst);
59
- if (toReturn.length < 5) {
40
+ if (toReturn.length < topCount) {
60
41
  const generalTopProducts = filter([...products], (o) => !o.recentlyFiledAgainst && o.isTopProduct);
61
42
  toReturn.push(...generalTopProducts);
62
43
  }
63
- return toReturn.slice(0, 5);
44
+ return toReturn.slice(0, topCount);
64
45
  }
65
46
  export function isOnlyVersion(versions) {
66
47
  return (versions === null || versions === void 0 ? void 0 : versions.length) && versions.length === 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/utils",
3
- "version": "0.2.31",
3
+ "version": "0.2.34-alpha-0",
4
4
  "description": "> TODO: description",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -45,7 +45,7 @@
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "peerDependencies": {
48
- "@cee-eng/hydrajs": "4.7.20",
48
+ "@cee-eng/hydrajs": "4.7.22",
49
49
  "@cee-eng/ui-toolkit": "1.1.6",
50
50
  "@rh-support/api": "0.3.9",
51
51
  "@rh-support/types": "0.2.0",
@@ -61,9 +61,9 @@
61
61
  "solr-query-builder": "1.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cee-eng/hydrajs": "4.7.20",
64
+ "@cee-eng/hydrajs": "4.7.22",
65
65
  "@cee-eng/ui-toolkit": "1.1.6",
66
- "@rh-support/api": "0.3.10",
66
+ "@rh-support/api": "0.3.13",
67
67
  "@rh-support/types": "0.2.0",
68
68
  "dompurify": "^2.2.6",
69
69
  "dot": "^1.1.3",
@@ -87,5 +87,5 @@
87
87
  "@types/react-dom": "^17.0.9",
88
88
  "moment-timezone": "^0.5.32"
89
89
  },
90
- "gitHead": "274324da926ca7deeaeba9fe702cacd0129941a1"
90
+ "gitHead": "c493eace4748f428da4c41f386381e609dd39651"
91
91
  }