Skip to content
Draft
Changes from all commits
Commits
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
72 changes: 71 additions & 1 deletion src/components/SimulationVuer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,65 @@
</div>
</template>

<script setup>
const emit = defineEmits(['data-ready'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use data-available (or dataAvailable).


function generateMockSeries(type, length = 100) {
const data = []
for (let i = 0; i < length; i++) {
if (type === 'sine') {
// Smooth curve.
data.push(Math.sin(i * 0.1) * 10)
} else {
// Random noise.
data.push(Math.random() * 10)
}
Comment on lines +62 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add some mock data for the variable of integration?

}
return data
}

function getDataView(requests) {
if (!requests || !Array.isArray(requests)) {
console.error("getDataView: Request must be an array.")
return {};
}

const response = {};
const EXPECTED_ID = 'nz.ac.auckland.simulation-data-request'
const EXPECTED_MAJOR_VERSION = 0;

requests.forEach((req, index) => {
// --- VALIDATION BLOCK ---

// Check request is expected type.
if (req.id !== EXPECTED_ID) {
console.warn(`[Mock] Request #${index} ignored: Invalid ID '${req.id}'`)
return // Skip this specific item.
}

// Test version compatibility.
const requestMajorVersion = parseInt(req.version.split('.')[0])
if (requestMajorVersion !== EXPECTED_MAJOR_VERSION) {
console.warn(`[Mock] Request #${index} ignored: Version mismatch. Expected v${EXPECTED_MAJOR_VERSION}.x, got v${req.version}`)
return // Skip this specific item.
}
Comment on lines +86 to +97
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother with this, but... meh.


// --- MOCK RESPONSE BLOCK ---

if (req.variable && req.variable.includes('v_in')) {
response[req.identifier] = generateMockSeries('sine')
} else {
// Default fallback for other variables.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also come here if req.variable is not truthy.

response[req.identifier] = generateMockSeries('random')
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect req.variable to be something like membrane/V or sodium_current/i_Na. As for the variable of integration, we could use VOI as a special variable name. So, here, I would expect to add a case for where req.variable === 'VOI'?

})

return response
}

defineExpose({ getDataView })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why getDataView? Why not simply getData?

</script>

<script>
import { PlotVuer } from "@abi-software/plotvuer";
import "@abi-software/plotvuer/dist/style.css";
Expand All @@ -75,6 +134,17 @@ const IdType = Object.freeze({
RAW_COMBINE_ARCHIVE: 'raw_combine_archive',
});

function isWebProtocol(urlString) {
try {
const url = new URL(urlString);
// protocol property includes the colon, e.g., "https:"
return url.protocol === "http:" || url.protocol === "https:";
} catch (err) {
// string was not a valid URL
return false;
}
}

/**
* SimulationVuer
*/
Expand Down Expand Up @@ -117,7 +187,7 @@ export default {
idType = IdType.DATASET_ID;
} else if (this.id instanceof Uint8Array) {
idType = IdType.RAW_COMBINE_ARCHIVE;
} else if (this.id.startsWith("https://")) {
} else if (isWebProtocol(this.id)) {
idType = IdType.DATASET_URL;
} else {
idType = IdType.PMR_PATH;
Expand Down