2018-02-28 10:20:26 -08:00
|
|
|
import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance';
|
2017-10-16 11:35:13 -07:00
|
|
|
import { lowQualitySuggestionConfidenceThreshold } from 'wherehows-web/constants';
|
2018-02-28 10:20:26 -08:00
|
|
|
import { arrayMap } from 'wherehows-web/utils/array';
|
2017-10-03 18:07:38 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a list of suggestions with confidence values, and if the confidence is greater than
|
|
|
|
* a low confidence threshold
|
2017-12-11 13:13:34 -08:00
|
|
|
* @param {number} confidenceLevel percentage indicating how confidence the system is in the suggested value
|
2017-10-03 18:07:38 -07:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2017-10-16 11:35:13 -07:00
|
|
|
const isHighConfidenceSuggestion = ({ confidenceLevel = 0 }: { confidenceLevel: number }): boolean =>
|
|
|
|
confidenceLevel > lowQualitySuggestionConfidenceThreshold;
|
2017-10-03 18:07:38 -07:00
|
|
|
|
2018-02-28 10:20:26 -08:00
|
|
|
/**
|
|
|
|
* Extracts the field suggestion from an IComplianceChangeSet field.
|
|
|
|
* If a suggestionAuthority property exists on the field, then the user has already either accepted or ignored
|
|
|
|
* the suggestion for this field. It's value should not be taken into account on re-renders,
|
|
|
|
* in place, this substitutes an empty suggestion
|
|
|
|
* @param {IComplianceChangeSet} field
|
|
|
|
* @return {{identifierType: IComplianceChangeSet.identifierType, logicalType: IComplianceChangeSet.logicalType, confidence: number} | void}
|
|
|
|
*/
|
|
|
|
const getFieldSuggestions = (
|
2018-02-28 11:16:09 -08:00
|
|
|
field: IComplianceChangeSet = <IComplianceChangeSet>{}
|
2018-02-28 10:20:26 -08:00
|
|
|
): {
|
|
|
|
identifierType: IComplianceChangeSet['identifierType'];
|
|
|
|
logicalType: IComplianceChangeSet['logicalType'];
|
|
|
|
confidence: number;
|
|
|
|
} | void => {
|
|
|
|
const { suggestion } = field.hasOwnProperty('suggestionAuthority') ? { suggestion: void 0 } : field;
|
|
|
|
|
|
|
|
if (suggestion && isHighConfidenceSuggestion(suggestion)) {
|
|
|
|
const { identifierType, logicalType, confidenceLevel: confidence } = suggestion;
|
|
|
|
return { identifierType, logicalType, confidence: +(confidence * 100).toFixed(2) };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the suggestions for a list of IComplianceChangeSet fields
|
|
|
|
* @type {(array: Array<IComplianceChangeSet>) => Array<{identifierType: ComplianceFieldIdValue | NonIdLogicalType | null; logicalType: IdLogicalType | null; confidence: number} | void>}
|
|
|
|
*/
|
|
|
|
const getFieldsSuggestions = arrayMap(getFieldSuggestions);
|
|
|
|
|
|
|
|
export { isHighConfidenceSuggestion, getFieldSuggestions, getFieldsSuggestions };
|