Commit a5270de4 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

ParallelStructures : stop copying structures extra results into parent result

Showing with 19 additions and 65 deletions
+19 -65
...@@ -88,7 +88,7 @@ describe("Class Cloisons: ", () => { ...@@ -88,7 +88,7 @@ describe("Class Cloisons: ", () => {
expect(res.vCalc).toBeCloseTo(0.773, 2); expect(res.vCalc).toBeCloseTo(0.773, 2);
expect(res.extraResults.PV).toBeCloseTo(150.1, 1); expect(res.extraResults.PV).toBeCloseTo(150.1, 1);
expect(res.extraResults.ZRMB).toBeCloseTo(76.54, 2); expect(res.extraResults.ZRMB).toBeCloseTo(76.54, 2);
expect(res.extraResults["ouvrage[0].ZDV"]).toBeCloseTo(76.67, 2); expect(modelCloisons.structures[0].result.extraResults.ZDV).toBeCloseTo(76.67, 2);
}); });
}); });
......
...@@ -230,7 +230,7 @@ describe("Class Pab: ", () => { ...@@ -230,7 +230,7 @@ describe("Class Pab: ", () => {
pab.CalcSerie(); pab.CalcSerie();
// for ex. Cloisons n°1 // for ex. Cloisons n°1
expect(pab.children[0].result.resultElements.length).toBe(3); expect(pab.children[0].result.resultElements.length).toBe(3);
expect(Object.keys(pab.children[0].result.resultElements[1].realExtraResults).length).toBe(12); expect(Object.keys(pab.children[0].result.resultElements[1].realExtraResults).length).toBe(8);
}); });
}); });
......
...@@ -139,9 +139,8 @@ export function testParallelStructures(o: { ps: ParallelStructure, ld: number[] ...@@ -139,9 +139,8 @@ export function testParallelStructures(o: { ps: ParallelStructure, ld: number[]
}); });
// Tests sur les résultats complémentaires // Tests sur les résultats complémentaires
it(`Calc(Q).extraResults[${i}.Q] should return o.ps.structures[${i}].Calc("Q").vCalc`, () => { it(`Calc(Q).extraResults[${i}.Q] should return o.ps.structures[${i}].Calc("Q").vCalc`, () => {
expect( o.ps.Calc("Q");
o.ps.Calc("Q").extraResults[`ouvrage[${i}].Q`] expect(o.ps.structures[i].result.resultElement.extraResults.Q).toBe(
).toBe(
o.ps.structures[i].Calc("Q").vCalc o.ps.structures[i].Calc("Q").vCalc
); );
}); });
......
...@@ -61,23 +61,23 @@ function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: numb ...@@ -61,23 +61,23 @@ function itParallelStructure(structIndex: number, sVarCalc: string, rVcalc: numb
if (Q !== undefined) { if (Q !== undefined) {
const pstructLocal = createEnv(); const pstructLocal = createEnv();
for (let i = 0; i < pstructLocal.structures.length; i++) { for (let i = 0; i < pstructLocal.structures.length; i++) {
it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q] should be ${Q}`, () => { it(`Calc(${JSON.stringify(sVarCalc)}) ouvrage[${i}].Q should be ${Q}`, () => {
const VC2: any = getVarCalc(pstruct, structIndex, sVarCalc); const VC2: any = getVarCalc(pstruct, structIndex, sVarCalc);
expect( pstruct.Calc(VC2);
pstruct.Calc(VC2).resultElement.extraResults[`ouvrage[${i}].Q`] const val = pstruct.structures[i].result.resultElement.extraResults.Q;
).toBeCloseTo(Q, Math.max(0, precDigits - 1)); expect(val).toBeCloseTo(Q, Math.max(0, precDigits - 1));
}); });
it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Mode] should be 0`, () => { it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Mode] should be 0`, () => {
const VC3 = getVarCalc(pstruct, structIndex, sVarCalc); const VC3 = getVarCalc(pstruct, structIndex, sVarCalc);
expect( pstruct.Calc(VC3);
pstruct.Calc(VC3).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowMode`] const val = pstruct.structures[i].result.resultElement.extraResults.ENUM_StructureFlowMode;
).toEqual(0); expect(val).toEqual(0);
}); });
it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Regime] should be 0`, () => { it(`Calc(${JSON.stringify(sVarCalc)}) ExtraResult[ouvrage[${i}].Q_Regime] should be 0`, () => {
const VC4 = getVarCalc(pstruct, structIndex, sVarCalc); const VC4 = getVarCalc(pstruct, structIndex, sVarCalc);
expect( pstruct.Calc(VC4);
pstruct.Calc(VC4).resultElement.extraResults[`ouvrage[${i}].Q_ENUM_StructureFlowRegime`] const val = pstruct.structures[i].result.resultElement.extraResults.ENUM_StructureFlowRegime;
).toEqual(0); expect(val).toEqual(0);
}); });
} }
} }
......
/**
* IMPORTANT !
* Décommenter temporairement la ligne suivante (import { } from "./mock_jasmine")
* Pour exécuter ce code dans le débugger.
* Faire de même avec le fichier test_func.ts
*/
// import { describe, expect, it, xdescribe, xit } from "../mock_jasmine";
/* import { ResultElement } from "../../src/util/resultelement";
describe("Class Result: ", () => {
describe("Method AddResulToExtra", () => {
const resEle: ResultElement = new ResultElement(1);
const resEleToAdd: ResultElement = new ResultElement(2);
const resEleRef: ResultElement = new ResultElement(1);
resEleRef.extraResults = { R: 2 };
it("Result should be integrated in extraResult", () => {
resEle.AddResultElementToExtra(resEleToAdd, "R");
expect(resEle).toEqual(resEleRef);
});
});
}); */
...@@ -73,9 +73,9 @@ export class Cloisons extends ParallelStructure { ...@@ -73,9 +73,9 @@ export class Cloisons extends ParallelStructure {
r.extraResults.ZRAM = this.prms.ZRAM.v; r.extraResults.ZRAM = this.prms.ZRAM.v;
// Ajout de ZDV pour les seuils // Ajout de ZDV pour les seuils
for (let i = 0; i < this.structures.length; i++) { for (const s of this.structures) {
if (this.structures[i].prms.h1.visible) { if (s.prms.h1.visible) {
r.resultElement.addExtraResult(`ouvrage[${i}].ZDV`, this.prms.Z1.v - this.structures[i].prms.h1.v); s.result.resultElement.addExtraResult("ZDV", this.prms.Z1.v - s.prms.h1.v);
} }
} }
......
...@@ -207,7 +207,7 @@ export class Session { ...@@ -207,7 +207,7 @@ export class Session {
} }
/** /**
* Creates a Nub from a JSON representation and adds it tot he current session; returns * Creates a Nub from a JSON representation and adds it to the current session; returns
* a pointer to the Nub and its JSON metadata * a pointer to the Nub and its JSON metadata
* @param serialised JSON representation of a single Nub * @param serialised JSON representation of a single Nub
* @param register if false, new Nub will just be returned and won't be registered into the session * @param register if false, new Nub will just be returned and won't be registered into the session
......
...@@ -92,7 +92,7 @@ export class ParallelStructure extends Nub { ...@@ -92,7 +92,7 @@ export class ParallelStructure extends Nub {
if (i !== iExcept) { if (i !== iExcept) {
const res: Result = this._children[i].Calc("Q"); const res: Result = this._children[i].Calc("Q");
// @TODO vérifier que ça marche sans la ligne ci-dessous // @TODO vérifier que ça marche sans la ligne ci-dessous
calcRes.resultElement.AddResultElementToExtra(res.resultElement, `ouvrage[${i}].Q`); // calcRes.resultElement.AddResultElementToExtra(res.resultElement, `ouvrage[${i}].Q`);
qTot += res.vCalc; qTot += res.vCalc;
} }
} }
......
...@@ -154,27 +154,6 @@ export class ResultElement { ...@@ -154,27 +154,6 @@ export class ResultElement {
public getExtraResult(name: string): any { public getExtraResult(name: string): any {
return this.getValue(name); return this.getValue(name);
} }
/**
* Add a ResultElement object into extraResult.
* The added ResultElement contains the Value of the ResultElement and the extraResults
* which are added using varCalc as prefix (i.e. [varCalc]_[key])
* Log messages are also copied to ResultElement
* @param resultElementToAdd Result object to add
* @param varCalc Name of the variable calculated used as key in extraResult
*/
public AddResultElementToExtra(resultElementToAdd: ResultElement, varCalc: string) {
// Add ResultElement into extraResult
this.extraResults[varCalc] = resultElementToAdd.vCalc;
// Add extraResults
for (const extraResKey in resultElementToAdd.realExtraResults) {
if (resultElementToAdd.extraResults.hasOwnProperty(extraResKey)) {
const newExtraKey: string = varCalc + "_" + extraResKey;
this.extraResults[newExtraKey] = resultElementToAdd.extraResults[extraResKey];
}
}
// Add Logs
this.log.addLog(resultElementToAdd.log);
}
// ------------ retrocompat @TODO remove ------------------------ // ------------ retrocompat @TODO remove ------------------------
public toString(): string { public toString(): string {
......
Supports Markdown
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