Skip to content

Commit f457213

Browse files
authored
Return the unit of the simulation data we emit.
2 parents 1e1703e + ab56d5a commit f457213

File tree

15 files changed

+244
-130
lines changed

15 files changed

+244
-130
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
os: ubuntu-22.04
3030
- name: Linting
3131
os: ubuntu-22.04
32+
- name: Type checking
33+
os: ubuntu-22.04
3234
steps:
3335
- name: Set the timezone to New Zealand
3436
uses: szenius/set-timezone@v2.0
@@ -45,18 +47,18 @@ jobs:
4547
- name: OpenCOR dependencies
4648
run: bun install
4749
- name: Build OpenCOR
48-
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' }}
50+
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' && matrix.name != 'Type checking' }}
4951
run: bun run build
5052
- name: Build OpenCOR's Web app
51-
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' }}
53+
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' && matrix.name != 'Type checking' }}
5254
env:
5355
VITE_FIREBASE_API_KEY: ${{ secrets.VITE_FIREBASE_API_KEY }}
5456
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID }}
5557
VITE_FIREBASE_APP_ID: ${{ secrets.VITE_FIREBASE_APP_ID }}
5658
VITE_FIREBASE_MEASUREMENT_ID: ${{ secrets.VITE_FIREBASE_MEASUREMENT_ID }}
5759
run: bun build:web
5860
- name: Build OpenCOR as a library
59-
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' }}
61+
if: ${{ matrix.name != 'Code formatting' && matrix.name != 'Linting' && matrix.name != 'Type checking' }}
6062
run: |
6163
cd src/renderer
6264
bun install
@@ -67,5 +69,8 @@ jobs:
6769
- name: Linting
6870
if: ${{ matrix.name == 'Linting' }}
6971
run: bun lint
72+
- name: Type checking
73+
if: ${{ matrix.name == 'Type checking' }}
74+
run: bun typecheck
7075
- name: Clean OpenCOR
7176
run: bun clean

bun.lock

Lines changed: 70 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git+https://github.com/opencor/webapp.git"
2424
},
2525
"type": "module",
26-
"version": "0.20260311.0",
26+
"version": "0.20260314.0",
2727
"engines": {
2828
"bun": ">=1.2.0"
2929
},
@@ -41,6 +41,7 @@
4141
"release": "bun src/renderer/scripts/libopencor.js && electron-builder",
4242
"release:local": "bun src/renderer/scripts/libopencor.js && CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --config.mac.notarize=false --publish=never",
4343
"start": "bun src/renderer/scripts/libopencor.js && electron-vite preview",
44+
"typecheck": "bunx --bun vue-tsc --noEmit -p tsconfig.app.json",
4445
"start:web": "bun --cwd src/renderer start",
4546
"version:new": "bun src/renderer/scripts/version.new.js"
4647
},
@@ -68,19 +69,19 @@
6869
"@electron-toolkit/utils": "^4.0.0",
6970
"@tailwindcss/postcss": "^4.2.1",
7071
"@tailwindcss/vite": "^4.2.1",
71-
"@types/node": "^25.4.0",
72+
"@types/node": "^25.5.0",
7273
"@types/plotly.js": "^3.0.10",
73-
"@vitejs/plugin-vue": "^6.0.4",
74+
"@vitejs/plugin-vue": "^6.0.5",
7475
"@vue/tsconfig": "^0.9.0",
75-
"@wasm-fmt/clang-format": "^22.1.0",
76+
"@wasm-fmt/clang-format": "^22.1.1",
7677
"autoprefixer": "^10.4.27",
7778
"cmake-js": "^8.0.0",
78-
"electron": "^40.8.0",
79+
"electron": "^40.8.2",
7980
"electron-builder": "^26.8.1",
8081
"electron-conf": "^1.3.0",
8182
"electron-updater": "^6.8.3",
8283
"electron-vite": "^5.0.0",
83-
"esbuild": "^0.27.3",
84+
"esbuild": "^0.27.4",
8485
"node-addon-api": "^8.6.0",
8586
"rollup-plugin-visualizer": "^7.0.1",
8687
"stylelint": "^17.4.0",
@@ -90,6 +91,7 @@
9091
"tar": "^7.5.11",
9192
"typescript": "^5.9.3",
9293
"unplugin-vue-components": "^31.0.0",
93-
"vite": "^7.3.1"
94+
"vite": "^7.3.1",
95+
"vue-tsc": "^3.2.5"
9496
}
9597
}

src/renderer/bun.lock

Lines changed: 65 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
IOpenCORExpose,
44
IOpenCORProps,
55
IOpenCORSimulationDataEvent,
6+
IOpenCORSimulationDataValue,
67
OpenCORSimulationData,
78
OpenCORTheme
89
} from './index.ts';

src/renderer/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export interface IOpenCOREmits extends /* @vue-ignore */ Record<string, unknown[
1515
simulationData: [IOpenCORSimulationDataEvent];
1616
}
1717

18-
export type OpenCORSimulationData = Record<string, Float64Array | undefined>;
18+
export interface IOpenCORSimulationDataValue {
19+
data: Float64Array;
20+
unit: string;
21+
}
22+
23+
export type OpenCORSimulationData = Record<string, IOpenCORSimulationDataValue>;
1924

2025
export interface IOpenCORSimulationDataEvent {
2126
simulationData: OpenCORSimulationData;

src/renderer/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@
4242
},
4343
"./style.css": "./dist/opencor.css"
4444
},
45-
"version": "0.20260311.0",
45+
"version": "0.20260314.0",
4646
"scripts": {
4747
"build": "vite build && bun scripts/generate.version.js",
4848
"build:lib": "vite build --config vite.lib.config.ts && bun scripts/copy.indexdts.js",
4949
"clean": "bun scripts/clean.js",
5050
"dependencies:update": "bun scripts/dependencies.update.js",
5151
"dev": "vite dev",
52-
"format": "bun --cwd ../.. format",
53-
"format:check": "bun --cwd ../.. format:check",
52+
"format": "bunx --bun biome format --fix --max-diagnostics=none",
53+
"format:check": "bunx --bun biome format --max-diagnostics=none",
5454
"lint": "bunx --bun biome lint --fix --error-on-warnings --max-diagnostics=none && bunx stylelint '**/*.css' --fix",
5555
"start": "bun run build && vite preview",
56+
"typecheck": "bunx --bun vue-tsc --noEmit",
5657
"version:new": "bun scripts/version.new.js"
5758
},
5859
"bun": {
@@ -77,18 +78,19 @@
7778
"@biomejs/biome": "^2.4.6",
7879
"@tailwindcss/postcss": "^4.2.1",
7980
"@tailwindcss/vite": "^4.2.1",
80-
"@types/node": "^25.4.0",
81+
"@types/node": "^25.5.0",
8182
"@types/plotly.js": "^3.0.10",
82-
"@vitejs/plugin-vue": "^6.0.4",
83+
"@vitejs/plugin-vue": "^6.0.5",
8384
"@vue/tsconfig": "^0.9.0",
8485
"autoprefixer": "^10.4.27",
85-
"esbuild": "^0.27.3",
86+
"esbuild": "^0.27.4",
8687
"stylelint": "^17.4.0",
8788
"stylelint-config-standard": "^40.0.0",
8889
"tailwindcss": "^4.2.1",
8990
"tailwindcss-primeui": "^0.6.1",
9091
"typescript": "^5.9.3",
9192
"unplugin-vue-components": "^31.0.0",
92-
"vite": "^7.3.1"
93+
"vite": "^7.3.1",
94+
"vue-tsc": "^3.2.5"
9395
}
9496
}

src/renderer/src/common/common.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OpenCORSimulationData } from '../../index.ts';
1+
import type { IOpenCORSimulationDataValue, OpenCORSimulationData } from '../../index.ts';
22

33
import * as dependencies from './dependencies.ts';
44
import { electronApi } from './electronApi.ts';
@@ -215,13 +215,21 @@ export const sleep = (ms: number): Promise<void> => {
215215
return new Promise((resolve) => setTimeout(resolve, ms));
216216
};
217217

218-
// A method to get an object with undefined values for a list of model parameters.
218+
// Some constants related to simulation data values.
219219

220-
export const undefinedSimulationData = (modelParameters: string[]): OpenCORSimulationData => {
220+
export const EMPTY_FLOAT64_ARRAY = Object.freeze(new Float64Array(0));
221+
export const UNDEFINED_SIMULATION_DATA_VALUE = Object.freeze({
222+
data: EMPTY_FLOAT64_ARRAY,
223+
unit: ''
224+
}) as Readonly<IOpenCORSimulationDataValue>;
225+
226+
// A method to get an object with an empty simulation data values for a list of model parameters.
227+
228+
export const emptySimulationData = (modelParameters: string[]): OpenCORSimulationData => {
221229
const res: OpenCORSimulationData = {};
222230

223231
for (const modelParameter of modelParameters) {
224-
res[modelParameter] = undefined;
232+
res[modelParameter] = { ...UNDEFINED_SIMULATION_DATA_VALUE };
225233
}
226234

227235
return res;

src/renderer/src/common/locCommon.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { IOpenCORSimulationDataValue } from '../../index.ts';
2+
13
import * as locApi from '../libopencor/locApi.ts';
24

35
import * as common from './common.ts';
@@ -341,23 +343,44 @@ export const simulationDataInfo = (instanceTask: locApi.SedInstanceTask, name: s
341343
};
342344
};
343345

344-
// A method to retrieve the simulation data for a given name from an instance task.
346+
// A method to retrieve the simulation data value for a given name from an instance task.
345347

346-
export const simulationData = (instanceTask: locApi.SedInstanceTask, info: ISimulationDataInfo): Float64Array => {
348+
export const simulationDataValue = (
349+
instanceTask: locApi.SedInstanceTask,
350+
info: ISimulationDataInfo
351+
): IOpenCORSimulationDataValue => {
347352
switch (info.type) {
348353
case ESimulationDataInfoType.VOI:
349-
return instanceTask.voi();
354+
return {
355+
data: instanceTask.voi(),
356+
unit: instanceTask.voiUnit()
357+
};
350358
case ESimulationDataInfoType.STATE:
351-
return instanceTask.state(info.index);
359+
return {
360+
data: instanceTask.state(info.index),
361+
unit: instanceTask.stateUnit(info.index)
362+
};
352363
case ESimulationDataInfoType.RATE:
353-
return instanceTask.rate(info.index);
364+
return {
365+
data: instanceTask.rate(info.index),
366+
unit: instanceTask.rateUnit(info.index)
367+
};
354368
case ESimulationDataInfoType.CONSTANT:
355-
return instanceTask.constant(info.index);
369+
return {
370+
data: instanceTask.constant(info.index),
371+
unit: instanceTask.constantUnit(info.index)
372+
};
356373
case ESimulationDataInfoType.COMPUTED_CONSTANT:
357-
return instanceTask.computedConstant(info.index);
374+
return {
375+
data: instanceTask.computedConstant(info.index),
376+
unit: instanceTask.computedConstantUnit(info.index)
377+
};
358378
case ESimulationDataInfoType.ALGEBRAIC:
359-
return instanceTask.algebraicVariable(info.index);
379+
return {
380+
data: instanceTask.algebraicVariable(info.index),
381+
unit: instanceTask.algebraicVariableUnit(info.index)
382+
};
360383
default:
361-
return new Float64Array();
384+
return { ...common.UNDEFINED_SIMULATION_DATA_VALUE };
362385
}
363386
};

src/renderer/src/components/ContentsComponent.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ const closeAllFiles = (): void => {
181181
const simulationData = (modelParameters: string[]): Promise<IOpenCORSimulationDataEvent> => {
182182
if (!props.simulationOnly) {
183183
return Promise.resolve({
184-
simulationData: common.undefinedSimulationData(modelParameters),
184+
simulationData: common.emptySimulationData(modelParameters),
185185
issues: ['Simulation data can only be retrieved in simulation only mode.']
186186
});
187187
}
@@ -190,14 +190,14 @@ const simulationData = (modelParameters: string[]): Promise<IOpenCORSimulationDa
190190
191191
if (!simulationExperimentViews.length) {
192192
return Promise.resolve({
193-
simulationData: common.undefinedSimulationData(modelParameters),
193+
simulationData: common.emptySimulationData(modelParameters),
194194
issues: ['No simulation experiment view available.']
195195
});
196196
}
197197
198198
return simulationExperimentViews[0].simulationData(modelParameters).catch((error: unknown) => {
199199
return {
200-
simulationData: common.undefinedSimulationData(modelParameters),
200+
simulationData: common.emptySimulationData(modelParameters),
201201
issues: [common.formatError(error)]
202202
};
203203
});

0 commit comments

Comments
 (0)