Skip to content

Instantly share code, notes, and snippets.

@frogbandit
Last active September 29, 2021 21:28
Show Gist options
  • Save frogbandit/ef82360b536976fbfb82f034d8b8b864 to your computer and use it in GitHub Desktop.
Save frogbandit/ef82360b536976fbfb82f034d8b8b864 to your computer and use it in GitHub Desktop.
Nova Credit Income Model Reconcile Confidence Scores
export interface ConfidenceScores {
score_conventional: number;
score_non_conventional: number;
score_non_wage?: number;
};
/**
* Given a list of inflow streams with confidence scores separated for wage, non-wage, and non-conventional,
* filter out any inflow streams below all thresholds, then find and map the highest score remaining
* as the final confidence score for the inflow stream.
* @param inflowStreamsWithConfidenceScores The list of inflow streams with their separated confidence scores.
* @returns The list of inflow streams above at least 1 score threshold with the final confidence score mapped
* — each inflow stream still includes each individual confidence score for insertion to the model logs table
*/
const reconcileConfidenceScores = <T1 extends ConfidenceScores, T2 extends T1 & { confidence_score: number } >(
inflowStreamsWithConfidenceScores: T1[],
): T2[] => {
const initial: T2[] = [];
return inflowStreamsWithConfidenceScores.reduce((list, withConfidenceInputs) => {
const finalConfidenceScore = getMaxScoreAboveThreshold(withConfidenceInputs);
if (finalConfidenceScore === null) {
return list;
}
const withFinalConfidenceScore = {
...withConfidenceInputs,
confidence_score: Math.round(finalConfidenceScore),
};
list.push(withFinalConfidenceScore as T2);
return list;
}, initial);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment