Skip to content

Commit

Permalink
Model config empty input total (#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
asylves1 authored Nov 11, 2024
1 parent 5cf732f commit 1978c9c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<tera-model-configuration-item
:configuration="configuration"
:selected="selectedConfigId === configuration.id"
:empty-input-count="missingInputCount(configuration)"
@click="onSelectConfiguration(configuration)"
@delete="fetchConfigurations(model.id)"
@download="downloadModelArchive(configuration)"
Expand Down Expand Up @@ -255,6 +256,7 @@ import { getMMT, getModel, getModelConfigurationsForModel, getCalendarSettingsFr
import {
createModelConfiguration,
getArchive,
getMissingInputAmount,
getModelConfigurationById,
setInitialExpression,
setInitialSource,
Expand Down Expand Up @@ -299,6 +301,7 @@ const emit = defineEmits(['append-output', 'update-state', 'select-output', 'clo
const isFetchingPDF = ref(false);
const isDocViewerOpen = ref(true);
const selectedConfigMissingInputCount = ref('');
const currentActiveIndexes = ref([0, 1, 2]);
const pdfData = ref<{ document: any; data: string; isPdf: boolean; name: string }[]>([]);
Expand Down Expand Up @@ -329,6 +332,23 @@ const calibratedConfigObservables = computed<Observable[]>(() =>
}))
);
const getTotalInput = (modelConfiguration: ModelConfiguration) =>
modelConfiguration.initialSemanticList.length + modelConfiguration.parameterSemanticList.length;
const getMissingInputCountMessage = (modelConfiguration: ModelConfiguration) => {
const amount = getMissingInputAmount(modelConfiguration);
const total = getTotalInput(modelConfiguration);
const precent = (amount / total) * 100;
return amount ? `Missing values: ${amount}/${total} (${precent.toFixed(0)}%)` : '';
};
const missingInputCount = (modelConfiguration: ModelConfiguration) => {
if (selectedConfigId.value === modelConfiguration.id) {
return selectedConfigMissingInputCount.value;
}
return getMissingInputCountMessage(modelConfiguration);
};
// Check if the model configuration is the same as the original
const isModelConfigChanged = computed(() => !isModelConfigsEqual(originalConfig, knobs.value.transientModelConfig));
Expand Down Expand Up @@ -740,6 +760,7 @@ const debounceUpdateState = debounce(() => {
configuredMmt.value = makeConfiguredMMT(mmt.value, knobs.value.transientModelConfig);
emit('update-state', state);
selectedConfigMissingInputCount.value = getMissingInputCountMessage(state.transientModelConfig);
}, 100);
watch(
() => knobs.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ContextMenu ref="contextMenu" :model="contextMenuItems" />
<p>{{ configuration.description }}</p>
<p>{{ formatTimestamp(configuration.createdOn) }}</p>
<span v-if="emptyInputCount" :class="{ 'input-count': emptyInputCount }">{{ emptyInputCount }}</span>
</div>
</template>

Expand All @@ -23,6 +24,7 @@ const emit = defineEmits(['delete', 'use', 'download']);
const props = defineProps<{
configuration: ModelConfiguration;
selected?: boolean;
emptyInputCount?: string;
}>();
const confirm = useConfirm();
Expand Down Expand Up @@ -102,10 +104,18 @@ header {
}
}
p {
p,
span {
color: var(--text-color-subdued);
font-size: var(--font-caption);
padding-right: var(--gap-6);
&.input-count {
background-color: var(--error-background);
}
}
span {
padding-right: unset;
}
p + p {
Expand Down
30 changes: 29 additions & 1 deletion packages/client/hmi-client/src/services/model-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ObservableSemantic,
ParameterSemantic
} from '@/types/Types';
import { isEmpty } from 'lodash';
import { isEmpty, isNaN, isNumber } from 'lodash';
import { pythonInstance } from '@/python/PyodideController';
import { DistributionType } from './distribution';

Expand Down Expand Up @@ -207,3 +207,31 @@ export function getOtherValues(configs: ModelConfiguration[], id: string, key: s
});
return otherValues;
}

export function isNumberInputEmpty(value: string) {
const number = parseFloat(value);
return isNaN(number) || !isNumber(number);
}

export function getMissingInputAmount(modelConfiguration: ModelConfiguration) {
let missingInputs = 0;
modelConfiguration.initialSemanticList.forEach((initial) => {
if (isNumberInputEmpty(initial.expression)) {
missingInputs++;
}
});

modelConfiguration.parameterSemanticList.forEach((parameter) => {
if (parameter.distribution.type === DistributionType.Constant) {
if (isNumberInputEmpty(parameter.distribution.parameters.value)) {
missingInputs++;
}
} else if (
isNumberInputEmpty(parameter.distribution.parameters.minimum) ||
isNumberInputEmpty(parameter.distribution.parameters.maximum)
) {
missingInputs++;
}
});
return missingInputs;
}

0 comments on commit 1978c9c

Please sign in to comment.