|
| 1 | +// Create a map to store the relationship between feature_id and feature_name from feature_data |
| 2 | +def featureNameMap = [:]; |
| 3 | + |
| 4 | +// Populate the map from feature_data |
| 5 | +if (ctx.containsKey('feature_data') && ctx.feature_data != null) { |
| 6 | + for (int i = 0; i < ctx.feature_data.length; i++) { |
| 7 | + def feature = ctx.feature_data[i]; |
| 8 | + if (feature != null && feature.containsKey('feature_id') && feature.containsKey('feature_name')) { |
| 9 | + featureNameMap[feature.feature_id] = feature.feature_name; |
| 10 | + ctx['feature_data_' + feature.feature_name] = feature.data; // Flatten feature_data as before |
| 11 | + } |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +// Flatten nested entity field |
| 16 | +if (ctx.containsKey('entity') && ctx.entity != null) { |
| 17 | + for (int i = 0; i < ctx.entity.length; i++) { |
| 18 | + def entity = ctx.entity[i]; |
| 19 | + if (entity != null && entity.containsKey('name') && entity.containsKey('value')) { |
| 20 | + ctx['entity_' + entity.name] = entity.value; |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +// Flatten nested relevant_attribution field |
| 26 | +if (ctx.containsKey('relevant_attribution') && ctx.relevant_attribution != null) { |
| 27 | + for (int i = 0; i < ctx.relevant_attribution.length; i++) { |
| 28 | + def attribution = ctx.relevant_attribution[i]; |
| 29 | + if (attribution != null && attribution.containsKey('feature_id') && attribution.containsKey('data')) { |
| 30 | + def featureName = featureNameMap[attribution.feature_id]; |
| 31 | + if (featureName != null) { |
| 32 | + ctx['relevant_attribution_' + featureName] = attribution.data; |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// Flatten nested expected_values field |
| 39 | +if (ctx.containsKey('expected_values') && ctx.expected_values != null) { |
| 40 | + for (int i = 0; i < ctx.expected_values.length; i++) { |
| 41 | + def expected = ctx.expected_values[i]; |
| 42 | + if (expected != null && expected.containsKey('value_list') && expected.value_list != null) { |
| 43 | + for (int j = 0; j < expected.value_list.length; j++) { |
| 44 | + def value = expected.value_list[j]; |
| 45 | + if (value != null && value.containsKey('feature_id') && value.containsKey('data')) { |
| 46 | + def featureName = featureNameMap[value.feature_id]; |
| 47 | + if (featureName != null) { |
| 48 | + ctx['expected_values_' + featureName] = value.data; |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// Flatten nested past_values field |
| 57 | +if (ctx.containsKey('past_values') && ctx.past_values != null) { |
| 58 | + for (int i = 0; i < ctx.past_values.length; i++) { |
| 59 | + def pastValue = ctx.past_values[i]; |
| 60 | + if (pastValue != null && pastValue.containsKey('feature_id') && pastValue.containsKey('data')) { |
| 61 | + def featureName = featureNameMap[pastValue.feature_id]; |
| 62 | + if (featureName != null) { |
| 63 | + ctx['past_value_' + featureName] = pastValue.data; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments