|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { isAdvancedConfig } from './action_clone'; |
| 8 | + |
| 9 | +describe('Analytics job clone action', () => { |
| 10 | + describe('isAdvancedConfig', () => { |
| 11 | + test('should detect a classification job created with the form', () => { |
| 12 | + const formCreatedClassificationJob = { |
| 13 | + description: "Classification job with 'bank-marketing' dataset", |
| 14 | + source: { |
| 15 | + index: ['bank-marketing'], |
| 16 | + query: { |
| 17 | + match_all: {}, |
| 18 | + }, |
| 19 | + }, |
| 20 | + dest: { |
| 21 | + index: 'dest_bank_1', |
| 22 | + results_field: 'ml', |
| 23 | + }, |
| 24 | + analysis: { |
| 25 | + classification: { |
| 26 | + dependent_variable: 'y', |
| 27 | + num_top_classes: 2, |
| 28 | + prediction_field_name: 'y_prediction', |
| 29 | + training_percent: 2, |
| 30 | + randomize_seed: 6233212276062807000, |
| 31 | + }, |
| 32 | + }, |
| 33 | + analyzed_fields: { |
| 34 | + includes: [], |
| 35 | + excludes: [], |
| 36 | + }, |
| 37 | + model_memory_limit: '350mb', |
| 38 | + allow_lazy_start: false, |
| 39 | + }; |
| 40 | + |
| 41 | + expect(isAdvancedConfig(formCreatedClassificationJob)).toBe(false); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should detect a outlier_detection job created with the form', () => { |
| 45 | + const formCreatedOutlierDetectionJob = { |
| 46 | + description: "Outlier detection job with 'glass' dataset", |
| 47 | + source: { |
| 48 | + index: ['glass_withoutdupl_norm'], |
| 49 | + query: { |
| 50 | + match_all: {}, |
| 51 | + }, |
| 52 | + }, |
| 53 | + dest: { |
| 54 | + index: 'dest_glass_1', |
| 55 | + results_field: 'ml', |
| 56 | + }, |
| 57 | + analysis: { |
| 58 | + outlier_detection: { |
| 59 | + compute_feature_influence: true, |
| 60 | + outlier_fraction: 0.05, |
| 61 | + standardization_enabled: true, |
| 62 | + }, |
| 63 | + }, |
| 64 | + analyzed_fields: { |
| 65 | + includes: [], |
| 66 | + excludes: ['id', 'outlier'], |
| 67 | + }, |
| 68 | + model_memory_limit: '1mb', |
| 69 | + allow_lazy_start: false, |
| 70 | + }; |
| 71 | + expect(isAdvancedConfig(formCreatedOutlierDetectionJob)).toBe(false); |
| 72 | + }); |
| 73 | + |
| 74 | + test('should detect a regression job created with the form', () => { |
| 75 | + const formCreatedRegressionJob = { |
| 76 | + description: "Regression job with 'electrical-grid-stability' dataset", |
| 77 | + source: { |
| 78 | + index: ['electrical-grid-stability'], |
| 79 | + query: { |
| 80 | + match_all: {}, |
| 81 | + }, |
| 82 | + }, |
| 83 | + dest: { |
| 84 | + index: 'dest_grid_1', |
| 85 | + results_field: 'ml', |
| 86 | + }, |
| 87 | + analysis: { |
| 88 | + regression: { |
| 89 | + dependent_variable: 'stab', |
| 90 | + prediction_field_name: 'stab_prediction', |
| 91 | + training_percent: 20, |
| 92 | + randomize_seed: -2228827740028660200, |
| 93 | + }, |
| 94 | + }, |
| 95 | + analyzed_fields: { |
| 96 | + includes: [], |
| 97 | + excludes: [], |
| 98 | + }, |
| 99 | + model_memory_limit: '150mb', |
| 100 | + allow_lazy_start: false, |
| 101 | + }; |
| 102 | + |
| 103 | + expect(isAdvancedConfig(formCreatedRegressionJob)).toBe(false); |
| 104 | + }); |
| 105 | + |
| 106 | + test('should detect advanced classification job', () => { |
| 107 | + const advancedClassificationJob = { |
| 108 | + description: "Classification job with 'bank-marketing' dataset", |
| 109 | + source: { |
| 110 | + index: ['bank-marketing'], |
| 111 | + query: { |
| 112 | + match_all: {}, |
| 113 | + }, |
| 114 | + }, |
| 115 | + dest: { |
| 116 | + index: 'dest_bank_1', |
| 117 | + results_field: 'CUSTOM_RESULT_FIELD', |
| 118 | + }, |
| 119 | + analysis: { |
| 120 | + classification: { |
| 121 | + dependent_variable: 'y', |
| 122 | + num_top_classes: 2, |
| 123 | + prediction_field_name: 'y_prediction', |
| 124 | + training_percent: 2, |
| 125 | + randomize_seed: 6233212276062807000, |
| 126 | + }, |
| 127 | + }, |
| 128 | + analyzed_fields: { |
| 129 | + includes: [], |
| 130 | + excludes: [], |
| 131 | + }, |
| 132 | + model_memory_limit: '350mb', |
| 133 | + allow_lazy_start: false, |
| 134 | + }; |
| 135 | + |
| 136 | + expect(isAdvancedConfig(advancedClassificationJob)).toBe(true); |
| 137 | + }); |
| 138 | + |
| 139 | + test('should detect advanced outlier_detection job', () => { |
| 140 | + const advancedOutlierDetectionJob = { |
| 141 | + description: "Outlier detection job with 'glass' dataset", |
| 142 | + source: { |
| 143 | + index: ['glass_withoutdupl_norm'], |
| 144 | + query: { |
| 145 | + // TODO check default for `match` |
| 146 | + match_all: {}, |
| 147 | + }, |
| 148 | + }, |
| 149 | + dest: { |
| 150 | + index: 'dest_glass_1', |
| 151 | + results_field: 'ml', |
| 152 | + }, |
| 153 | + analysis: { |
| 154 | + outlier_detection: { |
| 155 | + compute_feature_influence: false, |
| 156 | + outlier_fraction: 0.05, |
| 157 | + standardization_enabled: true, |
| 158 | + }, |
| 159 | + }, |
| 160 | + analyzed_fields: { |
| 161 | + includes: [], |
| 162 | + excludes: ['id', 'outlier'], |
| 163 | + }, |
| 164 | + model_memory_limit: '1mb', |
| 165 | + allow_lazy_start: false, |
| 166 | + }; |
| 167 | + expect(isAdvancedConfig(advancedOutlierDetectionJob)).toBe(true); |
| 168 | + }); |
| 169 | + |
| 170 | + test('should detect a custom query', () => { |
| 171 | + const advancedRegressionJob = { |
| 172 | + description: "Regression job with 'electrical-grid-stability' dataset", |
| 173 | + source: { |
| 174 | + index: ['electrical-grid-stability'], |
| 175 | + query: { |
| 176 | + match: { |
| 177 | + custom_field: 'custom_match', |
| 178 | + }, |
| 179 | + }, |
| 180 | + }, |
| 181 | + dest: { |
| 182 | + index: 'dest_grid_1', |
| 183 | + results_field: 'ml', |
| 184 | + }, |
| 185 | + analysis: { |
| 186 | + regression: { |
| 187 | + dependent_variable: 'stab', |
| 188 | + prediction_field_name: 'stab_prediction', |
| 189 | + training_percent: 20, |
| 190 | + randomize_seed: -2228827740028660200, |
| 191 | + }, |
| 192 | + }, |
| 193 | + analyzed_fields: { |
| 194 | + includes: [], |
| 195 | + excludes: [], |
| 196 | + }, |
| 197 | + model_memory_limit: '150mb', |
| 198 | + allow_lazy_start: false, |
| 199 | + }; |
| 200 | + |
| 201 | + expect(isAdvancedConfig(advancedRegressionJob)).toBe(true); |
| 202 | + }); |
| 203 | + |
| 204 | + test('should detect custom analysis settings', () => { |
| 205 | + const config = { |
| 206 | + description: "Classification clone with 'bank-marketing' dataset", |
| 207 | + source: { |
| 208 | + index: 'bank-marketing', |
| 209 | + }, |
| 210 | + dest: { |
| 211 | + index: 'bank_classification4', |
| 212 | + }, |
| 213 | + analyzed_fields: { |
| 214 | + excludes: [], |
| 215 | + }, |
| 216 | + analysis: { |
| 217 | + classification: { |
| 218 | + dependent_variable: 'y', |
| 219 | + training_percent: 71, |
| 220 | + max_trees: 1500, |
| 221 | + }, |
| 222 | + }, |
| 223 | + model_memory_limit: '400mb', |
| 224 | + }; |
| 225 | + |
| 226 | + expect(isAdvancedConfig(config)).toBe(true); |
| 227 | + }); |
| 228 | + |
| 229 | + test('should detect as advanced if the prop is unknown', () => { |
| 230 | + const config = { |
| 231 | + description: "Classification clone with 'bank-marketing' dataset", |
| 232 | + source: { |
| 233 | + index: 'bank-marketing', |
| 234 | + }, |
| 235 | + dest: { |
| 236 | + index: 'bank_classification4', |
| 237 | + }, |
| 238 | + analyzed_fields: { |
| 239 | + excludes: [], |
| 240 | + }, |
| 241 | + analysis: { |
| 242 | + classification: { |
| 243 | + dependent_variable: 'y', |
| 244 | + training_percent: 71, |
| 245 | + maximum_number_trees: 1500, |
| 246 | + }, |
| 247 | + }, |
| 248 | + model_memory_limit: '400mb', |
| 249 | + }; |
| 250 | + |
| 251 | + expect(isAdvancedConfig(config)).toBe(true); |
| 252 | + }); |
| 253 | + }); |
| 254 | +}); |
0 commit comments