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
41 changes: 41 additions & 0 deletions src/api/core/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ export interface Simulation {
selected_monitoring: string
}

// Learning packages ==============================================

/**
* Inteface to make manipulation of the json file easier
* these are incomplete and do not represent the full structure of the json file
* but contain what is necessary to parse them
*/
export interface VU_MODEL_SETTING_JSON {
type: "json_settings";
name: string;
splashscreen: string;
model_file_path: string;
experiment_name: string;
minimal_players: string;
maximal_players: string;
selected_monitoring?: 'gama_screen';
}

export interface VU_CATALOG_SETTING_JSON {
type: "catalog";
name: string;
splashscreen?: string;
entries: VU_MODEL_SETTING_JSON[] | VU_CATALOG_SETTING_JSON[];
}

// Simplier version used to send useful information only to Monitor clients
export interface MIN_VU_MODEL_SETTING_JSON {
type: string;
name: string;
splashscreen: string;
model_index: number;
}

// Simplier version used to send useful information only to Monitor clients
export interface MIN_VU_CATALOG_SETTING_JSON {
type: string;
name: string;
splashscreen?: string;
entries: MIN_VU_MODEL_SETTING_JSON[]|MIN_VU_CATALOG_SETTING_JSON;
}

// Internal message exchange ==============================================

export interface PlayerState {
Expand Down
4 changes: 2 additions & 2 deletions src/api/monitoring/MonitorServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class MonitorServer {
logger.trace("Sending simulation");
const simulationFromStream = JSON.parse(Buffer.from(message).toString());

this.controller.model_manager.setActiveModelByFilePath(simulationFromStream.simulation.model_file_path);
this.controller.model_manager.setActiveModelByIndex(simulationFromStream.simulation.model_index);
const selectedSimulation: Model = this.controller.model_manager.getActiveModel();
logger.debug("Selected simulation sent to gama: {json}", { json: selectedSimulation.getJsonSettings() });
this.sendMessageByWs({
Expand Down Expand Up @@ -245,7 +245,7 @@ export class MonitorServer {
* @param clientWsId (optional) WS to send the message to
* @return void
*/
sendMessageByWs(message: string, clientWsId?: any): void {
sendMessageByWs(message: any, clientWsId?: any): void {
if (this.wsClients !== undefined) {
this.wsClients.forEach((client) => {
if (clientWsId == undefined || clientWsId == client) {
Expand Down
38 changes: 19 additions & 19 deletions src/api/simulation/Model.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import path from 'path';
import { JsonSettings } from "../core/Constants.ts";
import {VU_MODEL_SETTING_JSON} from "../core/Constants.ts";
import { Logger, getLogger } from '@logtape/logtape';
import fs from "fs";

const logger: Logger = getLogger(["api", "simulation"]);
const logger: Logger = getLogger(["simulation", "Model"]);

class Model {
readonly #jsonSettings: SETTINGS_FILE_JSON;
readonly #modelFilePath: string;
readonly #jsonSettings: VU_MODEL_SETTING_JSON;

/**
* Creates a Model object based on VU founded by the ModelManager
* @param {string} settingsPath - Path to the settings file
* @param {string} jsonSettings - Json content _Stringyfied_ of the settings file
* @param {VU_MODEL_SETTING_JSON} jsonSettings - Json content _Stringyfied_ of the settings file
*/
constructor(settingsPath: string, jsonSettings: string) {
this.#jsonSettings = JSON.parse(jsonSettings);
constructor(settingsPath: string, jsonSettings: VU_MODEL_SETTING_JSON) {
this.#jsonSettings = jsonSettings;

logger.debug("Parsing {json}", { json: this.#jsonSettings });
logger.debug("Parsing new model {json}", { json: this.#jsonSettings.name });

//if the path is relative, we rebuild it using the path of the settings.json it is found in
const modelFilePath = this.#jsonSettings.model_file_path;
if (path.isAbsolute(modelFilePath)) {
this.#modelFilePath = modelFilePath;
} else {
this.#modelFilePath = path.join(path.dirname(settingsPath), this.#jsonSettings.model_file_path);
}
const absoluteModelFilePath = path.isAbsolute(this.#jsonSettings.model_file_path) ? this.#jsonSettings.model_file_path : path.join(path.dirname(settingsPath), this.#jsonSettings.model_file_path);

if (!fs.existsSync(absoluteModelFilePath))
logger.error(`GAML model for VU ${this.#jsonSettings.name} can't be found at ${absoluteModelFilePath}. Please check the path in the settings.json file.`)

this.#jsonSettings.model_file_path = absoluteModelFilePath;
}

// Getters
Expand All @@ -34,7 +34,7 @@ class Model {
* @returns {string} - The path to the model file
*/
getModelFilePath(): string {
return this.#modelFilePath;
return this.#jsonSettings.model_file_path;
}

/**
Expand All @@ -47,9 +47,9 @@ class Model {

/**
* Gets the JSON settings
* @returns {SETTINGS_FILE_JSON} - The JSON settings
* @returns {VU_MODEL_SETTING_JSON} - The JSON settings
*/
getJsonSettings(): SETTINGS_FILE_JSON {
getJsonSettings(): VU_MODEL_SETTING_JSON {
return this.#jsonSettings;
}

Expand All @@ -63,12 +63,12 @@ class Model {
return {
type: "json_simulation_list",
jsonSettings: this.#jsonSettings,
modelFilePath: this.#modelFilePath
modelFilePath: this.#jsonSettings.model_file_path
};
}

toString() {
return this.#modelFilePath;
return this.#jsonSettings.model_file_path;
}


Expand Down
Loading