Skip to content

Commit

Permalink
update types
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Jul 8, 2020
1 parent 744a5dd commit 8559b4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,32 @@ export const useRefreshAnalyticsList = (

const DEFAULT_SIG_FIGS = 3;

interface RegressionEvaluteExtractedResponse {
mse: number | string;
msle: number | string;
huber: number | string;
r_squared: number | string;
}

export const EMPTY_STAT = '--';

export function getValuesFromResponse(response: RegressionEvaluateResponse) {
const results = {};
const results: RegressionEvaluteExtractedResponse = {
mse: EMPTY_STAT,
msle: EMPTY_STAT,
huber: EMPTY_STAT,
r_squared: EMPTY_STAT,
};

if (response?.regression) {
for (const statType in response.regression) {
if (response.regression.hasOwnProperty(statType)) {
let currentStatValue = response.regression[statType]?.value;
let currentStatValue =
response.regression[statType as keyof RegressionEvaluateResponse['regression']]?.value;
if (currentStatValue) {
currentStatValue = Number(currentStatValue.toPrecision(DEFAULT_SIG_FIGS));
}
results[statType] = currentStatValue;
results[statType as keyof RegressionEvaluteExtractedResponse] = currentStatValue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@ import {
isRegressionEvaluateResponse,
ANALYSIS_CONFIG_TYPE,
REGRESSION_STATS,
EMPTY_STAT,
} from '../../../../common/analytics';

const EMPTY_STAT = '--';
interface Props {
jobConfig: DataFrameAnalyticsConfig;
jobStatus?: DATA_FRAME_TASK_STATE;
searchQuery: SavedSearchQuery;
}

const defaultEval: Eval = { mse: '', msle: '', huber: '', rSquared: '', error: null };
const EMPTY_STATS = {
mse: EMPTY_STAT,
msle: EMPTY_STAT,
huber: EMPTY_STAT,
rSquared: EMPTY_STAT,
};

const defaultEval: Eval = {
...EMPTY_STATS,
error: null,
};

export const EvaluatePanel: FC<Props> = ({ jobConfig, jobStatus, searchQuery }) => {
const {
Expand Down Expand Up @@ -96,10 +106,7 @@ export const EvaluatePanel: FC<Props> = ({ jobConfig, jobStatus, searchQuery })
} else {
setIsLoadingGeneralization(false);
setGeneralizationEval({
mse: EMPTY_STAT,
msle: EMPTY_STAT,
huber: EMPTY_STAT,
rSquared: EMPTY_STAT,
...EMPTY_STATS,
error: genErrorEval.error,
});
}
Expand Down Expand Up @@ -136,10 +143,7 @@ export const EvaluatePanel: FC<Props> = ({ jobConfig, jobStatus, searchQuery })
} else {
setIsLoadingTraining(false);
setTrainingEval({
mse: EMPTY_STAT,
msle: EMPTY_STAT,
rSquared: EMPTY_STAT,
huber: EMPTY_STAT,
...EMPTY_STATS,
error: trainingErrorEval.error,
});
}
Expand Down

0 comments on commit 8559b4b

Please sign in to comment.