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

Ts/3398 interventions #3461

Merged
merged 24 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
55dc211
forecast reads model and request's interventions
Tom-Szendrey Apr 26, 2024
91787f3
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Apr 26, 2024
997e52e
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Apr 29, 2024
cc764a6
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Apr 29, 2024
0fd3acc
chore: lint server codebase
Tom-Szendrey Apr 29, 2024
bfc070c
throwing in config not model, and on UI
Tom-Szendrey Apr 30, 2024
fa9d4e4
Merge branch 'TS/3398-interventions' of https://github.com/DARPA-ASKE…
Tom-Szendrey Apr 30, 2024
f284201
removing some console
Tom-Szendrey Apr 30, 2024
0594430
adding param options + delete
Tom-Szendrey Apr 30, 2024
070e7bd
temp list did not solve issue
Tom-Szendrey Apr 30, 2024
ee821a0
Thanks Dan!
Tom-Szendrey Apr 30, 2024
1703767
timestep before value
Tom-Szendrey Apr 30, 2024
4980d1f
aligning columns
Tom-Szendrey Apr 30, 2024
dec7269
removing import from model
Tom-Szendrey Apr 30, 2024
e3d05ff
adding ID to intervention - Dan was right
Tom-Szendrey Apr 30, 2024
a9abfc5
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey Apr 30, 2024
2a1c00f
chore: lint server codebase
Tom-Szendrey Apr 30, 2024
fcb31c8
remove a console log
Tom-Szendrey Apr 30, 2024
5955ae7
Merge branch 'TS/3398-interventions' of https://github.com/DARPA-ASKE…
Tom-Szendrey Apr 30, 2024
a0d4116
cleaning up old timeseries stuff
Tom-Szendrey Apr 30, 2024
45f7e33
id in the optimize node to not break typing
Tom-Szendrey Apr 30, 2024
866dd09
parameter options required
Tom-Szendrey May 1, 2024
e231d8c
removing intervention.id
Tom-Szendrey May 1, 2024
5fcde2c
Merge branch 'main' of https://github.com/DARPA-ASKEM/TERArium into T…
Tom-Szendrey May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,20 @@
tabindex="0"
@click="
() => {
if (!configuration?.metadata?.timeseries?.[parameter.id]) {
emit('enter-value-cell', 'parameters', 'value', i, j);
}
emit('enter-value-cell', 'parameters', 'value', i, j);
}
"
@keyup.enter="
() => {
if (!configuration?.metadata?.timeseries?.[parameter.id]) {
emit('enter-value-cell', 'parameters', 'value', i, j);
}
emit('enter-value-cell', 'parameters', 'value', i, j);
}
"
>
<section
:class="!cellEditStates[i].parameters[j] ? 'editable-cell' : 'editable-cell-hidden'"
>
<div class="distribution-cell">
<!-- To represent a time series variable -->
<span v-if="configuration?.metadata?.timeseries?.[parameter.id]">TS</span>
<span v-else>{{ parameter.value }}</span>
<span>{{ parameter.value }}</span>
<span class="distribution-range" v-if="parameter.distribution"
>Min: {{ parameter.distribution.parameters.minimum }} Max:
{{ parameter.distribution.parameters.maximum }}</span
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="form">
<div class="label-col">
<label>Parameter name </label>
<Dropdown
v-if="parameterOptions"
:options="parameterOptions"
v-model.lazy="name"
@update:model-value="updateIntervention"
/>
<InputText v-else v-model.lazy="name" @update:model-value="updateIntervention" />
Tom-Szendrey marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="label-col">
<label>Timestep</label>
<tera-input-number v-model.lazy="timestep" @update:model-value="updateIntervention" />
</div>
<div class="label-col">
<label>Value</label>
<tera-input-number v-model.lazy="value" @update:model-value="updateIntervention" />
</div>
<Button label="Delete" icon="pi pi-trash" @click="$emit('delete')" rounded text />
</div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Intervention } from '@/types/Types';
import teraInputNumber from '@/components/widgets/tera-input-number.vue';
import Button from 'primevue/button';
import InputText from 'primevue/inputtext';
import Dropdown from 'primevue/dropdown';

const props = defineProps<{
intervention: Intervention;
parameterOptions?: string[];
}>();
const emit = defineEmits(['update-value', 'delete']);

const name = ref(props.intervention.name);
const timestep = ref(props.intervention.timestep);
const value = ref(props.intervention.value);

function updateIntervention() {
const intervention: Intervention = {
id: props.intervention.id,
name: name.value,
timestep: timestep.value,
value: value.value
};
emit('update-value', intervention);
}
</script>

<style scoped>
.form {
display: flex;
}

.label-col {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</template>
</Column>

<!-- Value type: Matrix or a Dropdown with: Time varying, Constant, Distribution (with icons) -->
<!-- Value type: Matrix or a Dropdown with: Constant, Distribution (with icons) -->
<Column field="type" header="Value Type" class="w-2">
<template #body="slotProps">
<Button
Expand Down Expand Up @@ -212,20 +212,6 @@
/>
-->
</span>

<!-- Time series -->
<span
class="timeseries-container mr-2"
v-else-if="slotProps.data.type === ParamType.TIME_SERIES"
>
<InputText
:placeholder="'step:value, step:value, (e.g., 0:25, 1:26, 2:27 etc.)'"
v-model.lazy="slotProps.data.timeseries"
:disabled="readonly"
@update:model-value="(val) => updateTimeseries(slotProps.data.value.id, val)"
/>
<small v-if="errorMessage" class="invalid-message">{{ errorMessage }}</small>
</span>
</template>
</Column>

Expand Down Expand Up @@ -323,37 +309,21 @@
</Column>
<Column header="Value type">
<template #body="{ data }">
{{ typeOptions[getParamType(data.parameter, data.configuration.configuration)].label }}
{{ typeOptions[getParamType(data.parameter)].label }}
</template>
</Column>
<Column header="Value">
<template #body="{ data }">
<span
v-if="
getParamType(data.parameter, data.configuration.configuration) ===
ParamType.CONSTANT
"
>
<span v-if="getParamType(data.parameter) === ParamType.CONSTANT">
{{ data.parameter.value }}
</span>
<div
class="distribution-container"
v-else-if="
getParamType(data.parameter, data.configuration.configuration) ===
ParamType.DISTRIBUTION
"
v-else-if="getParamType(data.parameter) === ParamType.DISTRIBUTION"
>
<span>Min: {{ data.parameter.distribution.parameters.minimum }}</span>
<span>Max: {{ data.parameter.distribution.parameters.maximum }}</span>
</div>
<span
v-else-if="
getParamType(data.parameter, data.configuration.configuration) ===
ParamType.TIME_SERIES
"
>
{{ data.configuration?.configuration?.metadata?.timeseries?.[data.parameter.id] }}
</span>
</template>
</Column>
<Column header="Source">
Expand Down Expand Up @@ -404,8 +374,6 @@ import { MiraModel, MiraTemplateParams } from '@/model-representation/mira/mira-
import { isStratifiedModel, collapseParameters } from '@/model-representation/mira/mira';
import {
updateVariable,
validateTimeSeries,
getTimeseries,
getParameterMetadata,
getParameters,
updateParameterMetadata
Expand All @@ -426,8 +394,7 @@ const props = defineProps<{

const typeOptions = [
{ label: 'Constant', value: ParamType.CONSTANT, icon: 'pi pi-hashtag' },
{ label: 'Distribution', value: ParamType.DISTRIBUTION, icon: 'custom-icon-distribution' },
{ label: 'Time varying', value: ParamType.TIME_SERIES, icon: 'pi pi-clock' }
{ label: 'Distribution', value: ParamType.DISTRIBUTION, icon: 'custom-icon-distribution' }
];

const emit = defineEmits(['update-value', 'update-model']);
Expand Down Expand Up @@ -486,13 +453,11 @@ const tableFormattedParams = ref<ModelConfigTableData[]>([]);
// FIXME: This method doee not really work in this context, the different types
// of CONSTANT/TIME_SERIES/DISTRIBUTION are not mutually exclusive, a parameter
// can have one or more types
const getParamType = (param: ModelParameter | undefined, model: Model = props.model) => {
const getParamType = (param: ModelParameter | undefined) => {
let type = ParamType.CONSTANT;
if (!param) return type;

if (model.metadata?.timeseries?.[param.id] && model.metadata?.timeseries?.[param.id] !== null) {
type = ParamType.TIME_SERIES;
} else if (param?.distribution) {
if (param?.distribution) {
type = ParamType.DISTRIBUTION;
}
return type;
Expand All @@ -507,7 +472,6 @@ const buildParameterTable = () => {
const tableFormattedMatrix: ModelConfigTableData[] = vals.map((v) => {
const param = getParameters(model).find((i) => i.id === v);
const paramType = getParamType(param);
const timeseriesValue = getTimeseries(props.model, param!.id);
const parametersMetadata = getParameterMetadata(props.model, param!.id);
const sourceValue = parametersMetadata?.source;
return {
Expand All @@ -519,8 +483,7 @@ const buildParameterTable = () => {
units: param?.units?.expression ?? '',
value: param,
source: sourceValue,
visibility: false,
timeseries: timeseriesValue
visibility: false
};
});
formattedParams.push({
Expand All @@ -541,7 +504,6 @@ const buildParameterTable = () => {
if (!param) return;
const paramType = getParamType(param);

const timeseriesValue = getTimeseries(props.model, param.id);
const parametersMetadata = getParameterMetadata(props.model, param.id);
const sourceValue = parametersMetadata?.source;
formattedParams.push({
Expand All @@ -553,16 +515,14 @@ const buildParameterTable = () => {
unit: param.units?.expression,
value: param,
source: sourceValue,
visibility: false,
timeseries: timeseriesValue
visibility: false
});
});

// Stockflow has auxiliaries
const auxiliaries = model.model?.auxiliaries ?? [];
auxiliaries.forEach((aux) => {
const paramType = getParamType(aux);
const timeseriesValue = model.metadata?.timeseries?.[aux.id];
const parametersMetadata = model.metadata?.parameters?.[aux.id];
const sourceValue = parametersMetadata?.source;
formattedParams.push({
Expand All @@ -574,8 +534,7 @@ const buildParameterTable = () => {
unit: aux.units?.expression,
value: aux,
source: sourceValue,
visibility: false,
timeseries: timeseriesValue
visibility: false
});
});
}
Expand All @@ -594,8 +553,6 @@ const modelType = computed(() => getModelType(props.model));

// const addPlusMinus = ref(10);

const errorMessage = ref('');

const expandedRows = ref([]);

const openMatrixModal = (datum: ModelConfigTableData) => {
Expand Down Expand Up @@ -624,25 +581,6 @@ const updateParamValue = (param: ModelParameter, key: string, value: any) => {
emit('update-value', [clonedParam]);
};

const updateTimeseries = (id: string, value: string) => {
// Empty string => removal
if (value === '') {
const clonedModel = cloneDeep(props.model);
if (clonedModel.metadata && clonedModel.metadata.timeseries) {
clonedModel.metadata.timeseries[id] = null;
}
emit('update-model', clonedModel);
return;
}

if (!validateTimeSeries(value)) return;
const clonedModel = cloneDeep(props.model);
clonedModel.metadata ??= {};
clonedModel.metadata.timeseries ??= {};
clonedModel.metadata.timeseries[id] = value;
emit('update-model', clonedModel);
};

const updateMetadataFromInput = (id: string, key: string, value: any) => {
const clonedModel = cloneDeep(props.model);
updateParameterMetadata(clonedModel, id, key, value);
Expand Down Expand Up @@ -672,20 +610,14 @@ const applySelectedValue = () => {
if (!selectedValue.value) return;

const clonedModel = cloneDeep(props.model);
const timeseries =
selectedValue.value.configuration.configuration.metadata?.timeseries?.[
selectedValue.value.parameter.id
];
const metadata =
selectedValue.value.configuration.configuration.metadata?.parameters?.[
selectedValue.value.parameter.id
] ?? {};

clonedModel.metadata ??= {};
clonedModel.metadata.parameters ??= {};
clonedModel.metadata.timeseries ??= {};
clonedModel.metadata.parameters[selectedValue.value.parameter.id] = metadata;
clonedModel.metadata.timeseries[selectedValue.value.parameter.id] = timeseries;

// default source to use confirguration's source if there is no source
clonedModel.metadata.parameters[selectedValue.value.parameter.id].source =
Expand Down Expand Up @@ -770,10 +702,6 @@ watch(
text-align: right;
}

.timeseries-container {
font-size: var(--font-caption);
}

.add-plus-minus {
width: 3rem;
margin-left: var(--gap-xsmall);
Expand Down Expand Up @@ -828,11 +756,6 @@ watch(
color: var(--text-color-danger);
}

.timeseries-container {
display: flex;
flex-direction: column;
}

.secondary-text {
color: var(--text-color-subdued);
}
Expand Down
Loading
Loading