-
Notifications
You must be signed in to change notification settings - Fork 6
Mock API for retrieving data from simulation run #96
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,65 @@ | |
| </div> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| const emit = defineEmits(['data-ready']) | ||
|
|
||
| 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also come here if |
||
| response[req.identifier] = generateMockSeries('random') | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect |
||
| }) | ||
|
|
||
| return response | ||
| } | ||
|
|
||
| defineExpose({ getDataView }) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
| </script> | ||
|
|
||
| <script> | ||
| import { PlotVuer } from "@abi-software/plotvuer"; | ||
| import "@abi-software/plotvuer/dist/style.css"; | ||
|
|
@@ -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 | ||
| */ | ||
|
|
@@ -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; | ||
|
|
||
There was a problem hiding this comment.
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(ordataAvailable).