Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 28 additions & 6 deletions src/services/virtual-lab/build/me-model/bluepy-emodel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Ws, { BluePyEModelCmd, Cmd } from './websocket';
import Ws, { BluePyEModelCmd, Cmd, ModelOrigin } from './websocket';

import { meModelAnalysisSvc } from '@/config';

Expand All @@ -9,25 +9,47 @@ interface BluePyEModelConfig {
}

export default class BluePyEModelCls {
private modelSelfUrl: string;

private access_token: string;

private config: BluePyEModelConfig;

private ws: Ws;

constructor(modelSelfUrl: string, token: string, config: BluePyEModelConfig = {}) {
this.modelSelfUrl = modelSelfUrl;
this.access_token = token;
this.config = config;

this.ws = new Ws(meModelAnalysisSvc.wsUrl, token, { onMessage: this.onMessage });
this.ws.send(BluePyEModelCmd.SET_MODEL, { model_self_url: modelSelfUrl });

// TODO call runAnalysis directly not via the parents onInit which in turn calls runAnalysis
this.config.onInit?.();
}

runAnalysis() {
this.ws.send(BluePyEModelCmd.RUN_ANALYSIS, {});
this.ws.send(BluePyEModelCmd.RUN_ANALYSIS, {
access_token: this.access_token,
config: {
model_origin: ModelOrigin.NEXUS,
self_url: this.modelSelfUrl,
},
// For Entitycore required params are:
// access_token: this.access_token,
// config: {
// model_origin: ModelOrigin.ENTITYCORE,
// model_id: '<model_id>',
// project_context: {
// project_id: '<project_id>'
// virtual_lab_id: '<virtual_lab_id>',
// }
// },
});
}

private onMessage = (cmd: Cmd) => {
switch (cmd) {
case 'set_model_done':
this.config.onInit?.();
break;
case 'run_analysis_done':
this.config.onAnalysisDone?.();
break;
Expand Down
6 changes: 5 additions & 1 deletion src/services/virtual-lab/build/me-model/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import WsCommon, { OnMessageHandler } from '@/services/ws-common';

export const BluePyEModelCmd = {
// Cmd target: backend
SET_MODEL: 'set_model',
RUN_ANALYSIS: 'run_analysis',
PING: 'ping',
};

export enum ModelOrigin {
NEXUS = 'nexus',
ENTITYCORE = 'entitycore',
}

const PING_INTERVAL = 60_000;

type BluePyEModelCmdKeys = Lowercase<keyof typeof BluePyEModelCmd>;
Expand Down