Skip to content

Commit

Permalink
Fix undefine expect value for feature attribution (#310)
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>

Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang authored Aug 10, 2022
1 parent 7ace8b4 commit 25431a0
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions server/routes/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,7 @@ export default class AdService {
? toFixedNumberForAnomaly(Number.parseFloat(featureData.data))
: 0,
name: featureData.feature_name,
expectedValue: result._source.anomaly_grade > 0
? this.getExpectedValue(result, featureData.feature_id) : featureData.data
expectedValue: this.getExpectedValue(result, featureData)
});
});
});
Expand Down Expand Up @@ -1135,22 +1134,26 @@ export default class AdService {
? toFixedNumberForAnomaly(Number.parseFloat(featureData.data))
: 0,
name: featureData.feature_name,
expectedValue: rawResult._source.anomaly_grade > 0
? this.getExpectedValue(rawResult, featureData.feature_id)
: featureData.data
expectedValue: this.getExpectedValue(rawResult, featureData)
};
});
return featureResult;
};

getExpectedValue = (rawResult: any, featureId: string) => {
const expectedValueList = rawResult._source.expected_values;
if (expectedValueList.length > 0) {
expectedValueList[0].value_list.forEach((expect: any) => {
if (expect.feature_id === featureId) {
return expect.data;
}
})
getExpectedValue = (rawResult: any, featureData: any) => {
let expectedValue = featureData.data != null && featureData.data !== 'NaN'
? toFixedNumberForAnomaly(Number.parseFloat(featureData.data))
: 0;
if (rawResult._source.anomaly_grade > 0) {
const expectedValueList = rawResult._source.expected_values;
if (expectedValueList?.length > 0) {
expectedValueList[0].value_list.forEach((expect: any) => {
if (expect.feature_id === featureData.feature_id) {
expectedValue = expect.data;
}
})
}
}
return expectedValue
}
}

0 comments on commit 25431a0

Please sign in to comment.