-
Notifications
You must be signed in to change notification settings - Fork 3
IBEX backend integration #16
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
Open
deepakmaroo
wants to merge
5
commits into
iterorganization:develop
Choose a base branch
from
deepakmaroo:ibex-backend-integration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a485486
feat: IBEX IDS Explorer integration
deepakmaroo c6b04ed
Added ibex intergation configuration
deepakmaroo 3b6c510
Added ibex integration enable disable configuration
deepakmaroo 040e57b
Fixed type-check errors
deepakmaroo 5895b12
Remvoed unused parseUri source
deepakmaroo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| import axios from 'axios' | ||
| import type { AxiosInstance } from 'axios' | ||
|
|
||
| export interface IMASUri { | ||
| protocol: string | ||
| path: string | ||
| database: string | ||
| shot: number | ||
| run: number | ||
| occurrence: number | ||
| ids: string | ||
| node_path: string | ||
| original: string | ||
| } | ||
|
|
||
| export interface IDSNode { | ||
| path: string | ||
| name: string | ||
| dtype: string | ||
| shape: number[] | ||
| description?: string | ||
| units?: string | ||
| parent_path?: string | ||
| } | ||
|
|
||
| export interface TimeSeriesData { | ||
| name: string | ||
| unit: string | ||
| shape: number[] | ||
| downsampled_shape: number[] | ||
| ndim: number | ||
| path: string | ||
| description: string | ||
| coordinates: Array<{ | ||
| name: string | ||
| target: string | ||
| unit: string | ||
| shape: number[] | ||
| downsampled_shape: number[] | ||
| ndim: number | ||
| path: string | ||
| description: string | ||
| coordinates: any[] | ||
| shapes_dimension: boolean | ||
| value: number[] | ||
| }> | ||
| value: number[] | ||
| } | ||
|
|
||
| export class IBEXIdsAPI { | ||
| client: AxiosInstance | ||
| private baseURL: string | ||
|
|
||
| constructor(baseURL: string = '/api/ibex') { | ||
| this.baseURL = baseURL | ||
| this.client = axios.create({ | ||
| baseURL: baseURL, | ||
| timeout: 30000, | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| parseUri(uri: string): IMASUri { | ||
| console.log('Parsing URI:', uri) | ||
| let match = uri.match(/^imas:([^?]+)\?path=([^#]+)#([^:]+):(\d+)\/(.+)$/) | ||
| if (match) { | ||
| const [, protocol, path, ids, occurrence, nodePath] = match | ||
| const pathParts = path.split('/') | ||
| const database = pathParts[pathParts.length - 5] || 'unknown' | ||
| const shot = parseInt(pathParts[pathParts.length - 4]) || 0 | ||
| const run = parseInt(pathParts[pathParts.length - 3]) || 0 | ||
| return { | ||
| protocol: `imas:${protocol}`, | ||
| path, | ||
| database, | ||
| shot, | ||
| run, | ||
| occurrence: parseInt(occurrence), | ||
| ids, | ||
| node_path: nodePath, | ||
| original: uri | ||
| } | ||
| } | ||
| match = uri.match(/^imas:([^?]+)\?path=(.+)$/) | ||
| if (match) { | ||
| const [, backend, path] = match | ||
| const pathParts = path.split('/') | ||
| const database = pathParts[pathParts.length - 5] || 'unknown' | ||
| const shot = parseInt(pathParts[pathParts.length - 4]) || 0 | ||
| const run = parseInt(pathParts[pathParts.length - 3]) || 0 | ||
| return { | ||
| protocol: `imas:${backend}`, | ||
| path, | ||
| database, | ||
| shot, | ||
| run, | ||
| occurrence: 0, | ||
| ids: '', | ||
| node_path: '', | ||
| original: uri | ||
| } | ||
| } | ||
| throw new Error(`Unable to parse URI: ${uri}`) | ||
| } | ||
|
|
||
| async listNodes(baseUri: string): Promise<IDSNode[]> { | ||
| try { | ||
| console.log('Listing nodes with URI:', baseUri) | ||
| const params = new URLSearchParams() | ||
| params.append('uri', baseUri) | ||
| const response = await this.client.get('/data_entry/list_idses', { params }) | ||
| console.log('List IDSes response:', response.data) | ||
| const nodes: IDSNode[] = [] | ||
| if (response.data.idses && Array.isArray(response.data.idses)) { | ||
| response.data.idses.forEach((ids: any) => { | ||
| if (ids.occurrences && Array.isArray(ids.occurrences)) { | ||
| ids.occurrences.forEach((occ: any) => { | ||
| nodes.push({ | ||
| path: `${ids.name}:${occ}`, | ||
| name: `${ids.name}:${occ}`, | ||
| dtype: 'IDS', | ||
| shape: [], | ||
| description: `${ids.name} (occurrence ${occ})` | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
| console.log(`Found ${nodes.length} IDS nodes:`, nodes) | ||
| return nodes | ||
| } catch (error: any) { | ||
| console.error('Failed to list nodes:', error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| async getPlotData(uri: string, showErrorBars: boolean = false): Promise<TimeSeriesData> { | ||
| try { | ||
| const params = new URLSearchParams() | ||
| params.append('uri', uri) | ||
| params.append('show_error_bars', showErrorBars ? 'true' : 'false') | ||
| const response = await this.client.get('/data/plot_data', { params }) | ||
| if (response.data.data) { | ||
| return response.data.data as TimeSeriesData | ||
| } | ||
| return response.data as TimeSeriesData | ||
| } catch (error) { | ||
| console.error('Failed to get plot data:', error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| async getNodeChildren(baseUri: string, idsName: string): Promise<IDSNode[]> { | ||
| try { | ||
| console.log(`Getting child nodes for ${idsName} in URI:`, baseUri) | ||
| const name = idsName.includes(':') ? idsName.split(':')[0] : idsName | ||
| const nodeUri = `${baseUri}#${name}` | ||
| console.log('Node info URI:', nodeUri) | ||
| const params = new URLSearchParams() | ||
| params.append('uri', nodeUri) | ||
| params.append('show_error_bars', 'true') | ||
| const response = await this.client.get('/ids_info/node_info', { params }) | ||
| console.log('Node info response:', response.data) | ||
| const children: IDSNode[] = [] | ||
| const extractNodes = (data: any, prefix = '', isRoot = true) => { | ||
| if (Array.isArray(data)) { | ||
| data.forEach((item: any) => { | ||
| if (item.name) { | ||
| const fullPath = isRoot ? item.name : (prefix ? `${prefix}/${item.name}` : item.name) | ||
| children.push({ | ||
| path: fullPath, | ||
| name: item.name, | ||
| dtype: item.type || item.dtype || 'unknown', | ||
| shape: item.shape || [item.ndim || 0], | ||
| description: item.description, | ||
| units: item.units | ||
| }) | ||
| } | ||
| if (item.children) { | ||
| const newPrefix = isRoot ? item.name : (prefix ? `${prefix}/${item.name}` : item.name) | ||
| extractNodes(item.children, newPrefix, false) | ||
| } | ||
| }) | ||
| } else if (data && typeof data === 'object') { | ||
| if (data.name) { | ||
| const fullPath = isRoot ? '' : (prefix || data.name) | ||
| if (fullPath) { | ||
| children.push({ | ||
| path: fullPath, | ||
| name: data.name, | ||
| dtype: data.type || data.dtype || 'unknown', | ||
| shape: data.shape || [data.ndim || 0], | ||
| description: data.description, | ||
| units: data.units | ||
| }) | ||
| } | ||
| } | ||
| if (data.children) { | ||
| extractNodes(data.children, '', false) | ||
| } | ||
| } | ||
| } | ||
| extractNodes(response.data) | ||
| console.log(`Found ${children.length} child nodes:`, children) | ||
| return children | ||
| } catch (error: any) { | ||
| console.error('Failed to get node children:', error) | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| async findFields(baseUri: string, idsName: string): Promise<string[]> { | ||
| try { | ||
| console.log(`Finding fields for ${idsName} in URI:`, baseUri) | ||
| const name = idsName.includes(':') ? idsName.split(':')[0] : idsName | ||
| const nodeUri = `${baseUri}#${name}` | ||
| const params = new URLSearchParams() | ||
| params.append('uri', nodeUri) | ||
| const response = await this.client.get('/ids_info/node_info', { params }) | ||
| const fields: string[] = [] | ||
| const extractFieldNames = (data: any) => { | ||
| if (Array.isArray(data)) { | ||
| data.forEach((item: any) => { | ||
| if (item.name) { | ||
| fields.push(item.name) | ||
| } | ||
| if (item.children) { | ||
| extractFieldNames(item.children) | ||
| } | ||
| }) | ||
| } else if (data && typeof data === 'object') { | ||
| if (data.children) { | ||
| extractFieldNames(data.children) | ||
| } | ||
| } | ||
| } | ||
| extractFieldNames(response.data) | ||
| console.log(`Found ${fields.length} fields:`, fields) | ||
| return fields | ||
| } catch (error: any) { | ||
| console.error('Failed to find fields:', error) | ||
| return [] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const ibexIdsAPI = new IBEXIdsAPI('/api/ibex') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.