Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Sep 1, 2023
2 parents 7d470c4 + 204997e commit 3f45776
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/server/src/controllers/appsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AppsController {
loadSessionId: sessionId || "",
shareNotFound: shareNotFound || "",
mathjaxSrc: "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js",
enableI18n: wodinConfig.enableI18n ?? true, // if option not set then true by default
enableI18n: wodinConfig.enableI18n ?? false, // if option not set then false by default
defaultLanguage: wodinConfig?.defaultLanguage || "en"
};
res.render("app", viewOptions);
Expand Down
8 changes: 4 additions & 4 deletions app/server/tests/controllers/appsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("appsController", () => {
shareNotFound: "",
mathjaxSrc,
defaultLanguage: "en",
enableI18n: true
enableI18n: false
});
expect(mockStatus).not.toBeCalled();
});
Expand All @@ -104,7 +104,7 @@ describe("appsController", () => {
shareNotFound: "",
mathjaxSrc,
defaultLanguage: "en",
enableI18n: true
enableI18n: false
});
});

Expand All @@ -130,7 +130,7 @@ describe("appsController", () => {
shareNotFound: "",
mathjaxSrc,
defaultLanguage: "en",
enableI18n: true
enableI18n: false
});
});

Expand All @@ -154,7 +154,7 @@ describe("appsController", () => {
shareNotFound: "tiny-mouse",
mathjaxSrc,
defaultLanguage: "en",
enableI18n: true
enableI18n: false
});
});

Expand Down
4 changes: 3 additions & 1 deletion app/static/src/app/components/options/EditParamSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
<error-info :error="batchParsError"></error-info>
</div>
</div>
<sensitivity-param-values v-if="settingsInternal.variationType !== 'Custom'" :batch-pars="batchPars">
<sensitivity-param-values v-if="settingsInternal.variationType !== 'Custom'"
:batch-pars="batchPars"
:param-name="settingsInternal.parameterToVary">
</sensitivity-param-values>
</div>
<div class="modal-footer">
Expand Down
4 changes: 3 additions & 1 deletion app/static/src/app/components/options/SensitivityOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<strong>Number of runs:</strong> {{ settings.numberOfRuns}}
</li>
</ul>
<sensitivity-param-values v-if="settings.variationType !== 'Custom'" :batch-pars="allBatchPars[idx]">
<sensitivity-param-values v-if="settings.variationType !== 'Custom'"
:batch-pars="allBatchPars[idx]"
:param-name="settings.parameterToVary!">
</sensitivity-param-values>
<hr v-if="idx < allSettings.length-1" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ export default defineComponent({
batchPars: {
type: Object as PropType<BatchPars>,
required: false
},
paramName: {
type: String,
required: false
}
},
components: {
VueFeather
},
setup(props) {
const paramValues = computed(() => props.batchPars?.values || []);
const paramValues = computed(() => {
const varyingPar = props.batchPars?.varying.filter((v) => v.name === props.paramName);
return varyingPar?.length ? varyingPar[0].values : [];
});
const valuesText = computed(() => {
const formatValue = format(".3f");
const { length } = paramValues.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import {
import { AxisType, newPlot, Plots } from "plotly.js-basic-dist-min";
import { useStore } from "vuex";
import {
config, fadePlotStyle, filterSeriesSet, margin, odinToPlotly, updatePlotTraceName
config, fadePlotStyle, filterUserTypeSeriesSet, margin, odinToPlotly, updatePlotTraceName
} from "../../plot";
import { SensitivityPlotExtremePrefix, SensitivityPlotType, SensitivityScaleType } from "../../store/sensitivity/state";
import { SensitivityMutation } from "../../store/sensitivity/mutations";
import { Batch, OdinSeriesSet } from "../../types/responseTypes";
import { Batch, OdinUserTypeSeriesSet } from "../../types/responseTypes";
import { runPlaceholderMessage } from "../../utils";
import { RunGetter } from "../../store/run/getters";
import { Dict } from "../../types/utilTypes";
Expand Down Expand Up @@ -91,8 +91,9 @@ export default defineComponent({
const plotData = computed(() => {
if (batch.value) {
let data: null | OdinSeriesSet;
const paramSetData: Dict<OdinSeriesSet> = {};
const paramName = store.state.sensitivity.paramSettings.parameterToVary;
let data: null | OdinUserTypeSeriesSet;
const paramSetData: Dict<OdinUserTypeSeriesSet> = {};
if (plotSettings.value.plotType === SensitivityPlotType.ValueAtTime) {
verifyValidPlotSettingsTime(store.state, store.commit);
data = batch.value.valueAtTime(plotSettings.value.time);
Expand All @@ -110,7 +111,7 @@ export default defineComponent({
});
}
const filtered = filterSeriesSet(data!, selectedVariables.value);
const filtered = filterUserTypeSeriesSet(data!, paramName, selectedVariables.value);
const result = [...odinToPlotly(filtered, palette.value, { includeLegendGroup: true })];
Object.keys(paramSetData).forEach((name: string) => {
const dash = lineStylesForParamSets.value[name];
Expand All @@ -121,7 +122,7 @@ export default defineComponent({
dash
};
const psData = paramSetData[name];
const psFiltered = filterSeriesSet(psData, selectedVariables.value);
const psFiltered = filterUserTypeSeriesSet(psData, paramName, selectedVariables.value);
const psPlotData = odinToPlotly(psFiltered, palette.value, options);
const currentParamSet = parameterSets.value.find((paramSet) => paramSet.name === name);
psPlotData.forEach((plotTrace) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "../../plot";
import {
Batch,
DiscreteSeriesValues, OdinSeriesSet, OdinSolution
DiscreteSeriesValues, OdinSeriesSet, OdinSolution, VaryingPar
} from "../../types/responseTypes";
import { AppType } from "../../store/appState/state";
import { runPlaceholderMessage } from "../../utils";
Expand All @@ -52,6 +52,7 @@ export default defineComponent({
const parameterSetDisplayNames = computed(() => {
return parameterSets.value.map((paramSet) => paramSet.displayName);
});
const paramSettings = computed(() => store.state.sensitivity.paramSettings);
const parameterSetBatches = computed(() => {
const result = {} as Dict<Batch>;
Expand Down Expand Up @@ -88,6 +89,9 @@ export default defineComponent({
const time = {
mode: "grid" as const, tStart: start, tEnd: end, nPoints: points
};
const varyingParamName = paramSettings.value.parameterToVary;
const varyingPar = pars.varying.filter((v: VaryingPar) => v.name === varyingParamName);
const parValues = varyingPar.length ? varyingPar[0].values : [];
const addSolutionOutputToResult = (
solution: OdinSolution,
Expand Down Expand Up @@ -120,7 +124,7 @@ export default defineComponent({
showLegend: false
};
addSolutionOutputToResult(sln, plotlyOptions,
(plotTrace) => updatePlotTraceName(plotTrace, pars.name, pars.values[slnIdx]));
(plotTrace) => updatePlotTraceName(plotTrace, varyingParamName, parValues[slnIdx]));
});
if (centralSolution.value) {
Expand Down Expand Up @@ -151,8 +155,8 @@ export default defineComponent({
addSolutionOutputToResult(sln, plotlyOptions,
(plotTrace) => updatePlotTraceName(
plotTrace,
pars.name,
pars.values[slnIdx],
varyingParamName,
parValues[slnIdx],
currentParamSet!.displayName
));
});
Expand Down
10 changes: 6 additions & 4 deletions app/static/src/app/excel/wodinSensitivitySummaryDownload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as XLSX from "xlsx";
import { WodinExcelDownload } from "./wodinExcelDownload";
import { SensitivityPlotExtreme, SensitivityPlotExtremePrefix } from "../store/sensitivity/state";
import { OdinSeriesSet } from "../types/responseTypes";
import { OdinUserType, OdinUserTypeSeriesSet } from "../types/responseTypes";

interface ExtremeSummarySheetSettings {
name: string,
Expand All @@ -16,10 +16,12 @@ const extremeSummarySheets: ExtremeSummarySheetSettings[] = [
{ name: "TimeAtMax", extremePrefix: SensitivityPlotExtremePrefix.time, extreme: SensitivityPlotExtreme.Max }
];
export class WodinSensitivitySummaryDownload extends WodinExcelDownload {
private _addSummarySheetFromOdinSeriesSet = (data: OdinSeriesSet, varyingParameter: string, sheetName: string) => {
const sheetData = data.x.map((x: number, index: number) => {
private _addSummarySheetFromOdinSeriesSet = (data: OdinUserTypeSeriesSet, varyingParameter: string,
sheetName: string) => {
const sheetData = data.x.map((x: OdinUserType, index: number) => {
const xValue = x[varyingParameter];
return Object.fromEntries([
[varyingParameter, x],
[varyingParameter, xValue],
...data.values.map((v) => [v.name, v.y[index]])
]);
});
Expand Down
11 changes: 10 additions & 1 deletion app/static/src/app/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { format } from "d3-format";
import { Palette, paletteData } from "./palette";
import type { AllFitData, FitData, FitDataLink } from "./store/fitData/state";
import {
DiscreteSeriesSet, OdinSeriesSet, OdinSeriesSetValues
DiscreteSeriesSet, OdinSeriesSet, OdinSeriesSetValues, OdinUserTypeSeriesSet
} from "./types/responseTypes";
import { Dict } from "./types/utilTypes";

Expand All @@ -22,6 +22,15 @@ export const config = {
responsive: true
};

export function filterUserTypeSeriesSet(s: OdinUserTypeSeriesSet, param: string, names: string[]): OdinSeriesSet {
const values = s.values.filter((v) => names.includes(v.name));
const xValues = s.x.map((x) => x[param]);
return {
x: xValues,
values
};
}

export function filterSeriesSet(s: OdinSeriesSet, names: string[]): OdinSeriesSet {
const values = s.values.filter((v) => names.includes(v.name));
return {
Expand Down
45 changes: 28 additions & 17 deletions app/static/src/app/types/responseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export interface OdinModelResponse{
error?: OdinModelResponseError
}

// This is strictly a little more restrictive than what odin supports,
// but wodin does not support fancy user variables yet and we can sort
// that out later (odin allows the union of number, number[], and a
// tensor type - the latter two will be a challenge to expose nicely
// in the interface).
export type OdinUserType = Dict<number>;

// This is Odin's SeriesSetValues and SeriesSet
export interface OdinSeriesSetValues {
description?: string;
Expand All @@ -95,6 +102,11 @@ export type OdinSeriesSet = {
values: OdinSeriesSetValues[];
}

export type OdinUserTypeSeriesSet = {
x: OdinUserType[],
values: OdinSeriesSetValues[]
}

export interface TimeGrid {
mode: "grid";
tStart: number;
Expand All @@ -117,13 +129,6 @@ export interface OdinFitData {
value: number[]
}

// This is strictly a little more restrictive than what odin supports,
// but wodin does not support fancy user variables yet and we can sort
// that out later (odin allows the union of number, number[], and a
// tensor type - the latter two will be a challenge to expose nicely
// in the interface).
export type OdinUserType = Dict<number>;

export interface OdinFitParameters {
base: OdinUserType,
vary: string[]
Expand All @@ -147,23 +152,29 @@ export interface Simplex {
result: () => SimplexResult;
}

export interface VaryingPar {
name: string,
values: number[]
}

export interface BatchPars {
base: OdinUserType;
name: string;
values: number[];
varying: VaryingPar[];
}

export interface BatchError {
value: number,
error: string
export interface OdinRunStatus {
pars: OdinUserType,
success: boolean,
error: string | null
}

export interface Batch {
pars: BatchPars,
solutions: OdinSolution[],
errors: BatchError[],
valueAtTime: (time: number) => OdinSeriesSet,
extreme: (type: string) => OdinSeriesSet,
errors: OdinRunStatus[],
successfulVaryingParams: OdinUserType[],
valueAtTime: (time: number) => OdinUserTypeSeriesSet,
extreme: (type: string) => OdinUserTypeSeriesSet,
compute: () => boolean
}

Expand Down Expand Up @@ -207,13 +218,13 @@ export interface OdinRunnerOde {
count: number,
logarithmic: boolean,
min: number,
max: number) => BatchPars;
max: number) => VaryingPar;

batchParsDisplace: (base: OdinUserType,
name: string,
count: number,
logarithmic: boolean,
displace: number) => BatchPars;
displace: number) => VaryingPar;
batchRun: (odin: Odin,
pars: BatchPars,
tStart: number,
Expand Down
13 changes: 8 additions & 5 deletions app/static/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function generateBatchParsFromOdin(
paramSettings: SensitivityParameterSettings,
paramValues: OdinUserType
): GenerateBatchParsResult {
let batchPars = null;
let varyingParam = null;
let errorDetail = null;
// TODO: NB For now we use ode runner to generate batch pars for all app types, but expect this to change
const runner = rootState.model.odinRunnerOde;
Expand All @@ -147,7 +147,7 @@ function generateBatchParsFromOdin(

if (variationType === SensitivityVariationType.Percentage) {
try {
batchPars = runner!.batchParsDisplace(
varyingParam = runner!.batchParsDisplace(
paramValues, parameterToVary!,
numberOfRuns, logarithmic,
variationPercentage
Expand All @@ -157,7 +157,7 @@ function generateBatchParsFromOdin(
}
} else {
try {
batchPars = runner!.batchParsRange(
varyingParam = runner!.batchParsRange(
paramValues,
parameterToVary!,
numberOfRuns,
Expand All @@ -171,6 +171,7 @@ function generateBatchParsFromOdin(
}

const error = errorDetail ? { error: userMessages.sensitivity.invalidSettings, detail: errorDetail } : null;
const batchPars = errorDetail ? null : { base: paramValues!, varying: [varyingParam!] };
return {
batchPars,
error
Expand Down Expand Up @@ -198,8 +199,10 @@ export function generateBatchPars(
if (paramSettings.variationType === SensitivityVariationType.Custom) {
const batchPars: BatchPars = {
base: paramValues!,
name: paramSettings.parameterToVary!,
values: paramSettings.customValues
varying: [{
name: paramSettings.parameterToVary!,
values: paramSettings.customValues
}]
};
return {
batchPars,
Expand Down
11 changes: 1 addition & 10 deletions app/static/tests/e2e/tabs.etest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ test.describe("Wodin App tabs tests", () => {
expect(await page.innerText("nav a.navbar-brand")).toBe("WODIN Example");
expect(await page.getAttribute("nav a.navbar-brand", "href")).toBe("http://localhost:3000");
expect(await page.innerText("nav .navbar-app")).toBe("Day 1 - Basic Model");
expect(await page.innerText("nav .navbar-version >> nth=1")).toMatch(/^WODIN v[0-9].[0-9].[0-9]$/);
expect(await page.innerText("nav span .navbar-text >> nth=0")).toBe("English");
expect(await page.innerText("nav .navbar-version >> nth=0")).toMatch(/^WODIN v[0-9].[0-9].[0-9]$/);
});

test("link in header navigates to index page", async ({ page }) => {
Expand Down Expand Up @@ -59,12 +58,4 @@ test.describe("Wodin App tabs tests", () => {
await expect(await page.innerText(".wodin-right .wodin-content div.mt-4 button"))
.toBe("Run sensitivity");
});

test("can change language to French", async ({ page }) => {
const languageSwitcher = await page.locator("nav span .navbar-text >> nth=0");
await languageSwitcher.click();
const frenchMenuItem = await languageSwitcher.locator(".dropdown-item >> nth=1");
await frenchMenuItem.click();
expect(await page.innerText("nav span .navbar-text >> nth=0")).toBe("Français");
});
});
Loading

0 comments on commit 3f45776

Please sign in to comment.