Commit 93fa1888 authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch...

Merge branch '260-messages-de-log-maintenir-un-pointeur-vers-le-resultat-afin-de-pouvoir-contextualiser-par-la' into 'master'

Resolve "Messages de log : maintenir un pointeur vers le Resultat afin de pouvoir contextualiser par la suite"

Closes #260

See merge request cassiopee/jalhyd!88
parents f16af7c9 11bf3dbe
import { Session } from "../src/session";
import { ParallelStructure } from "../src/structure/parallel_structure";
import { MessageCode } from "../src/util/message";
describe("cLog −", () => {
it("in ParallelStructure, Structure log message's grand-parent should be the Structure's result, not the ParallelStructure's one", () => {
const sess = `{"header":{"source":"jalhyd","format_version":"1.3","created":"2020-08-11T08:04:59.930Z"},"settings":{"precision":1e-7,"maxIterations":100,"displayPrecision":3},"documentation":"","session":[{"uid":"dnhvbz","props":{"calcType":"ParallelStructure"},"meta":{"title":"Ouvrages"},"children":[{"uid":"aHkzNj","props":{"calcType":"Structure","structureType":"VanneRectangulaire","loiDebit":"RectangularOrificeFree"},"children":[],"parameters":[{"symbol":"ZDV","mode":"SINGLE","value":100},{"symbol":"W","mode":"SINGLE","value":0.5},{"symbol":"L","mode":"SINGLE","value":2},{"symbol":"CdGR","mode":"SINGLE","value":0.6}]}],"parameters":[{"symbol":"Q","mode":"CALCUL"},{"symbol":"Z1","mode":"SINGLE","value":102},{"symbol":"Z2","mode":"SINGLE","value":101.5}]}]}`;
Session.getInstance().clear();
Session.getInstance().unserialise(sess);
const ps = Session.getInstance().findNubByUid("dnhvbz") as ParallelStructure;
ps.CalcSerie();
const s = ps.structures[0];
expect(s.result.log.messages.length).toBe(1, "Kenobi");
expect(s.result.log.messages[0].code).toBe(MessageCode.WARNING_DOWNSTREAM_ELEVATION_POSSIBLE_SUBMERSION);
expect(s.result.log.messages[0].parent).toBe(s.result.log);
expect(s.result.log.messages[0].parent.parent.uid).toBe(s.result.uid);
});
});
......@@ -83,7 +83,6 @@ export class Cloisons extends ParallelStructure {
s.result.resultElement.values.P = pelle;
if (pelle < -1E-7) { // si c'est enfoncé d'un dixième de micron ça va
const m = new Message(MessageCode.WARNING_NEGATIVE_SILL);
m.extraVar.number = String(s.findPositionInParent() + 1); // String to avoid decimals
s.result.resultElement.log.add(m);
// merge in parent for GUI display
this.result.resultElement.log.add(m);
......
......@@ -42,6 +42,7 @@ export class Pab extends Nub {
super(prms, dbg);
this.downWall = downWall;
this._calcType = CalculatorType.Pab;
this._childrenType = "Cloison";
}
public get downWall() {
......
import { CalculatorType } from "../compute-node";
import { ParamCalculability, ParamFamily } from "../param/param-definition";
import { ParamCalculability } from "../param/param-definition";
import { SessionSettings } from "../session_settings";
import { Message, MessageCode } from "../util/message";
import { Result } from "../util/result";
......
import { Message, MessageCode } from "./message";
import { Result } from "./result";
// tslint:disable-next-line:class-name
export class cLog {
/** pointer to parent result */
public parent: Result;
private _messages: Message[] = [];
public constructor(parent?: Result) {
this.parent = parent;
}
/**
* efface tous les messages
*/
......@@ -15,6 +24,11 @@ export class cLog {
* insère un message en fin de liste
*/
public add(m: Message) {
// add pointer to the current log as message's parent, unless the message
// already has a parent, and unless the current log has no pointer to a result
if (m.parent === undefined && this.parent !== undefined) {
m.parent = this;
}
this._messages.push(m);
}
......@@ -23,7 +37,7 @@ export class cLog {
*/
public addLog(l: cLog) {
for (const m of l.messages) {
this._messages.push(m);
this.add(m);
}
}
......@@ -31,6 +45,11 @@ export class cLog {
* insère un message en début de liste
*/
public insert(m: Message) {
// add pointer to the current log as message's parent, unless the message
// already has a parent, and unless the current log has no pointer to a result
if (m.parent === undefined && this.parent !== undefined) {
m.parent = this;
}
this._messages.unshift(m);
}
......@@ -39,7 +58,7 @@ export class cLog {
*/
public insertLog(l: cLog) {
for (let i = l.messages.length - 1; i >= 0; i--) {
this._messages.unshift(l.messages[i]);
this.insert(l.messages[i]);
}
}
......
import { cLog } from "./log";
export enum MessageCode {
/**
* pas de pb !
......@@ -341,7 +343,7 @@ export enum MessageCode {
/** abstract showing number of warning messages encountered in an iterative calculation */
WARNING_WARNINGS_ABSTRACT,
/** Déversoirs: la cote de déversoir de l'ouvrage %number% est en dessous de la cote de fond du lit */
/** Déversoirs: la cote de déversoir est en dessous de la cote de fond du lit */
WARNING_DEVER_ZDV_INF_ZR,
/** La cote de fond aval est plus élevée que la code de l'eau aval */
......@@ -418,7 +420,7 @@ export enum MessageCode {
*/
WARNING_STRUCTUREKIVI_HP_TROP_ELEVE,
/** Cloisons: la pelle de l'ouvrage %number% est en dessous du radier */
/** Cloisons: la pelle de l'ouvrage est en dessous du radier */
WARNING_NEGATIVE_SILL,
/**
......@@ -490,7 +492,13 @@ export enum MessageCode {
WARNING_VALUE_ROUNDED_TO_INTEGER,
/** Cloisons : la cote de radier de l'ouvrage n°%number% est en dessous de la cote de radier amont de la cloison */
WARNING_CLOISONS_ZDV_INF_ZRAM
WARNING_CLOISONS_ZDV_INF_ZRAM,
/** %name% n°%position% : */
INFO_PARENT_PREFIX,
/** downwall : */
INFO_PARENT_PREFIX_DOWNWALL
}
/**
......@@ -513,6 +521,9 @@ export class Message {
*/
private _code: MessageCode;
/** pointer to parent log */
public parent: cLog;
constructor(c: MessageCode, extraVar: { [key: string]: any } = {}) {
this._code = c;
this.extraVar = extraVar;
......
......@@ -29,7 +29,7 @@ export class Result extends JalhydObject {
*/
constructor(v?: number | Message | ResultElement, sourceNub?: Nub, extraValues?: { [key: string]: number }) {
super();
this._globalLog = new cLog();
this._globalLog = new cLog(this);
this._resultElements = [];
this._sourceNub = sourceNub;
// try to store main result symbol
......
......@@ -13,7 +13,7 @@ export class ResultElement {
public log: cLog;
/** pointer to parent result */
public parent: Result;
private _parent: Result;
/**
* result values by symbol; generally contains at least the symbol of the calculated
......@@ -46,6 +46,15 @@ export class ResultElement {
}
}
public get parent(): Result {
return this._parent;
}
public set parent(r: Result) {
this._parent = r;
this.log.parent = this.parent;
}
/**
* @returns value of the calculated parameter (main result); might be undefined,
* for ex. with SectionParametree
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment