Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: show rate expression instead of rate name #1756

Merged
merged 15 commits into from
Sep 8, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<!-- Model equations -->
<AccordionTab header="Model equations">
<section :class="isEditingEQ ? `diagram-container-editing` : `diagram-container`">
<section v-if="props.isEditable" class="controls">
<section v-if="props.isEditable && props.isEquationsEditable" class="controls">
<Button
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
v-if="isEditingEQ"
@click="cancelEditEquations"
Expand Down Expand Up @@ -252,6 +252,7 @@ const emit = defineEmits([
const props = defineProps<{
model: Model | null;
isEditable: boolean;
isEquationsEditable?: boolean;
nodePreview?: boolean;
}>();

Expand All @@ -270,6 +271,8 @@ const latexEquationsOriginalList = ref<string[]>([]);
const observablesRefs = ref<any[]>([]);
const observervablesList = ref<Observable[]>([]);

const mathContainerStyle = computed(() => (props.isEquationsEditable ? '-1rem' : '0rem'));

// For model editing
interface AddStateObj {
id: string;
Expand Down Expand Up @@ -790,7 +793,7 @@ section math-editor {
border: 4px solid transparent;
border-radius: var(--border-radius);
position: relative;
top: -1rem;
top: v-bind('mathContainerStyle');
}

.observable-editor-container {
Expand Down
18 changes: 18 additions & 0 deletions packages/client/hmi-client/src/components/models/tera-model.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<tera-model-diagram
:model="model"
:isEditable="!featureConfig.isPreview"
:isEquationsEditable="canEditEquations"
@update-model-content="updateModelContent"
@update-model-observables="updateModelObservables"
/>
Expand Down Expand Up @@ -201,6 +202,8 @@ const isNamingModel = computed(() => props.assetId === '' || isRenamingModel.val

const stratifiedModelType = computed(() => model.value && getStratificationType(model.value));

const canEditEquations = ref(true);

/*
* User Menu
*/
Expand Down Expand Up @@ -301,8 +304,23 @@ watch(
{ immediate: true }
);

function modelIsEmpty(targetModel: Model): boolean {
// model does not have any states or transitions
if (targetModel.model?.states?.length === 0 && targetModel.model?.transitions?.length === 0) {
return true;
}

return false;
}
async function fetchModel() {
model.value = await getModel(props.assetId);

// we can only edit equations when the AMR is empty
if (model.value && !modelIsEmpty(model.value)) {
canEditEquations.value = false;
} else {
canEditEquations.value = true;
}
mwdchang marked this conversation as resolved.
Show resolved Hide resolved
}

onUpdated(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export const convertAMRToACSet = (amr: Model) => {
});
});

// post processing to use expressions rather than ids
result.T = result.T.map((transition) => {
const foundRate = amr.semantics?.ode.rates.find((rate) => rate.target === transition.tname);

// default to the id if there is a case where there is no expression
return { tname: foundRate ? `(${foundRate!.expression})` : transition.tname };
});

return result;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/client/hmi-client/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ export const cleanLatexEquations = (equations: Array<string>): Array<string> =>
.replaceAll('\\left', '')
.replaceAll('{align}', '')
.replaceAll('=&', '=')
// scientific variables such as \beta and \gamma are not parsed when there is a '*' (with no space) placed after them - other math operaters do work though
.replaceAll('*', ' *')
.trim()
);

Expand Down