* Generate key combination base on the columns we want to merge on * e.g df = { * key1: ["KO", "K0", "K3", "K4"], * Key2: ["K1", "K1", "K3", "K5"], * A: [1,2,3,4] * B: [3,4,5,6] * } * keycomb = generateKeyCombination(df.values, [0,1]) * This should output * { * '
(values: ArrayType2D, colIndex: ArrayType1D)
| 91 | * @param colIndex |
| 92 | */ |
| 93 | private generateKeyCombination(values: ArrayType2D, colIndex: ArrayType1D): keyComb { |
| 94 | let colKeyComb: keyComb = {} |
| 95 | |
| 96 | for (let i=0; i < values.length; i++) { |
| 97 | let rowValues = values[i] |
| 98 | let rowKeyCombValues = []; |
| 99 | for (let j =0; j < colIndex.length; j++) { |
| 100 | let index = colIndex[j] as number |
| 101 | rowKeyCombValues.push(rowValues[index]) |
| 102 | } |
| 103 | let rowKeyComb = rowKeyCombValues.join('_') |
| 104 | let otherValues = rowValues.filter((val, index) => { |
| 105 | return !colIndex.includes(index) |
| 106 | }) |
| 107 | if (utils.keyInObject(colKeyComb, rowKeyComb)) { |
| 108 | colKeyComb[rowKeyComb].filters.push(otherValues) |
| 109 | } else { |
| 110 | colKeyComb[rowKeyComb] = { |
| 111 | filters: [otherValues], |
| 112 | combValues: rowKeyCombValues |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | return colKeyComb |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Generate columns for the newly generated merged DataFrame |
no test coverage detected