diff --git a/src/app/components/pb-results/pb-results-table.component.ts b/src/app/components/pb-results/pb-results-table.component.ts index c5d8dff4d32791788ce5c62a4e40b1a6acce13da..6838becaccafc979566c3cc9f95831100edd164a 100644 --- a/src/app/components/pb-results/pb-results-table.component.ts +++ b/src/app/components/pb-results/pb-results-table.component.ts @@ -1,4 +1,4 @@ -import { Component, ViewChild, ElementRef, Input } from "@angular/core"; +import { Component, ViewChild, ElementRef, Input, OnChanges } from "@angular/core"; import { PreBarrage, PbBassin } from "jalhyd"; @@ -15,7 +15,7 @@ import { PrebarrageResults } from "../../results/prebarrage-results"; "./pb-results-table.component.scss" ] }) -export class PbResultsTableComponent extends ResultsComponentDirective { +export class PbResultsTableComponent extends ResultsComponentDirective implements OnChanges { /** résultats non mis en forme */ private _pbResults: PrebarrageResults; @@ -26,6 +26,10 @@ export class PbResultsTableComponent extends ResultsComponentDirective { /** résultats mis en forme */ private _dataSet: any[]; + /** index de l'élément de résultat à afficher (modifié par le sélecteur de conditions limites) */ + @Input() + public variableIndex = 0; + @ViewChild("tableContainer") table: ElementRef; @@ -38,19 +42,19 @@ export class PbResultsTableComponent extends ResultsComponentDirective { @Input() public set results(r: PrebarrageResults) { this._pbResults = r; + } + public ngOnChanges() { + console.log(">>>>>>> on changes ! drawing pb results table", this.variableIndex); this._dataSet = []; if ( this._pbResults && this._pbResults.bassinsResults && this._pbResults.bassinsResults.length > 0 - && ! this._pbResults.hasOnlyErrors() + && !this._pbResults.hasOnlyErrors() ) { const pr = this._pbResults; const pb = pr.result.sourceNub as PreBarrage; - // when a parameter is variating, index of the variating parameter - // values to build the data from - const vi = pr.variableIndex; // @TODO results.size ? To extend values lists… @@ -58,22 +62,23 @@ export class PbResultsTableComponent extends ResultsComponentDirective { this._headers = pr.headers; // upstream line - if (pr.result.resultElements[vi].vCalc) { // le calcul peut avoir échoué + if (pr.result.resultElements[this.variableIndex]?.vCalc) { // le calcul peut avoir échoué this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AMONT"), "", "", - getIthValue(pb.prms.Z1, vi, this._pbResults.size), + getIthValue(pb.prms.Z1, this.variableIndex, this._pbResults.size), "", "", - getIthValue(pb.prms.Q, vi, this._pbResults.size), + getIthValue(pb.prms.Q, this.variableIndex, this._pbResults.size), ]); } // basins 1 - n for (let i = 0; i < pr.bassinsResults.length; i++) { if ( - Object.keys(pr.bassinsResults[i].resultElements[vi].values).length > 0 // no vCalc in this case + pr.bassinsResults[i].resultElements[this.variableIndex] !== undefined + && Object.keys(pr.bassinsResults[i].resultElements[this.variableIndex].values).length > 0 // no vCalc in this case ) { - const rb = pr.bassinsResults[i].resultElements[vi].values; + const rb = pr.bassinsResults[i].resultElements[this.variableIndex].values; const basin = pr.bassinsResults[i].sourceNub as PbBassin; this._dataSet.push([ i + 1, // n° cloison @@ -88,13 +93,13 @@ export class PbResultsTableComponent extends ResultsComponentDirective { } // downstream line - if (pr.result.resultElements[vi].vCalc) { // le calcul peut avoir échoué + if (pr.result.resultElements[this.variableIndex]?.vCalc) { // le calcul peut avoir échoué this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AVAL"), "", "", - getIthValue(pb.prms.Z2, vi, this._pbResults.size), + getIthValue(pb.prms.Z2, this.variableIndex, this._pbResults.size), "", "", - getIthValue(pb.prms.Q, vi, this._pbResults.size), + getIthValue(pb.prms.Q, this.variableIndex, this._pbResults.size), ]); } } diff --git a/src/app/components/pb-results/pb-results.component.html b/src/app/components/pb-results/pb-results.component.html index ae300910591b90d0c0ca1b78533013200d91d379..8aacd4e2044030857949a5632144565eb4b92c9b 100644 --- a/src/app/components/pb-results/pb-results.component.html +++ b/src/app/components/pb-results/pb-results.component.html @@ -1,13 +1,14 @@ <div class="container"> + <log [logTitle]="uitextGeneralLogTitle" [log]=globalLog>log général</log> - <variable-results-selector [results]=pbResults> + <variable-results-selector [results]=pbResults [variatedParameters]=pbResults?.variatedParameters> </variable-results-selector> <log [log]=iterationLog></log> <!-- tableau de résultats des bassins --> - <pb-results-table *ngIf="hasBasinResults" [results]=pbResults></pb-results-table> + <pb-results-table *ngIf="hasBasinResults" [results]=pbResults [variableIndex]=pbResults?.variableIndex></pb-results-table> <!-- table des résultats fixés --> <pb-cloison-results *ngIf="hasWallResults" [results]=pbResults.cloisonResults></pb-cloison-results> diff --git a/src/app/components/pb-results/pb-results.component.ts b/src/app/components/pb-results/pb-results.component.ts index b502c4e40fe2335c1688ddc7028aa7112bc105c6..e4eb8b3642a19fcd2e7d05410b6b355f6280713a 100644 --- a/src/app/components/pb-results/pb-results.component.ts +++ b/src/app/components/pb-results/pb-results.component.ts @@ -4,7 +4,7 @@ import { CalculatorResults } from "../../results/calculator-results"; import { PrebarrageResults } from "../../results/prebarrage-results"; import { I18nService } from "../../services/internationalisation.service"; -import { cLog } from "jalhyd"; +import { cLog, Message, MessageCode, MessageSeverity, PbCloison, PreBarrage, Result } from "jalhyd"; @Component({ selector: "pb-results", @@ -51,7 +51,7 @@ export class PbResultsComponent { return this._pbResults && this._pbResults.hasWallResults; } - /* private mergeGlobalLog(result: Result, log: cLog) { + private mergeGlobalLog(result: Result, log: cLog) { if (result) { if (result.hasGlobalLog()) { log.addLog(result.globalLog); @@ -63,18 +63,18 @@ export class PbResultsComponent { } } } - } */ + } /** * Returns the number of errors, warnings, infos among children logs */ - /* private logStats(): any { + private logStats(): any { const ret = { info: 0, warning: 0, error: 0 }; - if (this._pbResults.result && this._pbResults.result.hasLog()) { + if (this._pbResults.result?.hasLog()) { for (const re of this._pbResults.result.resultElements) { if (re.hasLog()) { for (const m of re.log.messages) { @@ -94,9 +94,10 @@ export class PbResultsComponent { } } } - for (const cr of this._pbResults.cloisonsResults) { - if (cr && cr.hasLog()) { - for (const re of cr.resultElements) { + const pb = this._pbResults.result.sourceNub as PreBarrage; + for (const pbc of pb.children) { // bassins et cloisons + if (pbc.result !== undefined) { + for (const re of pbc.result.resultElements) { if (re.hasLog()) { for (const m of re.log.messages) { const s = m.getSeverity(); @@ -116,28 +117,8 @@ export class PbResultsComponent { } } } - if (this._pbResults.cloisonAvalResults && this._pbResults.cloisonAvalResults.hasLog()) { - for (const re of this._pbResults.cloisonAvalResults.resultElements) { - if (re.hasLog()) { - for (const m of re.log.messages) { - const s = m.getSeverity(); - switch (s) { - case MessageSeverity.INFO: - ret.info ++; - break; - case MessageSeverity.WARNING: - ret.warning ++; - break; - case MessageSeverity.ERROR: - ret.error ++; - break; - } - } - } - } - } return ret; - } */ + } /* * Retourne les logs à afficher dans le composant de log global, au dessus @@ -146,9 +127,15 @@ export class PbResultsComponent { */ public get globalLog(): cLog { const l = new cLog(); - /* if (this._pbResults && this.pbResults.variatedParameters.length > 0) { + /* console.log( + `>> Global Log >> this._pbResults: ${this._pbResults !== undefined}` + + `, vpl: ${this?._pbResults?.variatedParameters?.length}` + + `, hasLog: ${this?._pbResults?.hasLog}` + ); */ + if (this._pbResults && this.pbResults.variatedParameters.length > 0) { this.mergeGlobalLog(this._pbResults.result, l); - // un problème avec la PAB en général / les cloisons, à une étape quelconque ? + // console.log(">>>> after merge, messages length=", l.messages.length); + // un problème avec le PB en général / les cloisons / les bassins, à une étape quelconque ? if ( (this.pbResults.hasLog) && l.messages.length === 0 // existing global messages make generic message below useless @@ -159,9 +146,8 @@ export class PbResultsComponent { m.extraVar.warning = "" + logStats.warning; m.extraVar.error = "" + logStats.error; l.add(m); - // l.add(new Message(MessageCode.WARNING_PROBLEMS_ENCOUNTERED)); } - } // sinon pas de log global (aucun paramètre ne varie) */ + } // sinon pas de log global (aucun paramètre ne varie) return l; } @@ -172,42 +158,39 @@ export class PbResultsComponent { */ public get iterationLog(): cLog { const l = new cLog(); - /* if (this._pabResults) { - if (this.pabResults.variatedParameters.length > 0) { + if (this._pbResults?.result) { + const pb = this._pbResults.result.sourceNub as PreBarrage; + if (this._pbResults.variatedParameters.length > 0) { // A. si un paramètre varie - const vi = this._pabResults.variableIndex; - // log de la PAB pour l'itération en cours + const vi = this._pbResults.variableIndex; + // log du PB pour l'itération en cours if ( - this._pabResults.result - && this._pabResults.result.hasResultElements() - && this._pabResults.result.resultElements[vi] - && this._pabResults.result.resultElements[vi].hasLog() + this._pbResults.result + && this._pbResults.result.hasResultElements() + && this._pbResults.result.resultElements[vi] + && this._pbResults.result.resultElements[vi]?.hasLog() ) { - l.addLog(this._pabResults.result.resultElements[vi].log); + l.addLog(this._pbResults.result.resultElements[vi].log); } // logs des enfants pour l'itération en cours - for (const cr of this._pabResults.cloisonsResults) { - if (cr && cr.hasResultElements() && cr.resultElements[vi].hasLog()) { - l.addLog(cr.resultElements[vi].log); + for (const pbc of pb.children) { + if (pbc?.result?.hasResultElements() && pbc.result.resultElements[vi]?.hasLog()) { + l.addLog(pbc.result.resultElements[vi].log); } } - if (this._pabResults.cloisonAvalResults && this._pabResults.cloisonAvalResults.resultElements[vi].hasLog()) { - l.addLog(this._pabResults.cloisonAvalResults.resultElements[vi].log); - } } else { // B. si aucun paramètre ne varie - this.mergeGlobalLog(this._pabResults.result, l); // faut bien mettre le log global quelque part + this.mergeGlobalLog(this._pbResults.result, l); // faut bien mettre le log global quelque part + console.log("!!! ITERATION LOG !!! avant", l.messages.length); // logs des enfants - for (const cr of this._pabResults.cloisonsResults) { - if (cr && cr.hasResultElements() && cr.resultElement.hasLog()) { - l.addLog(cr.resultElement.log); + for (const pbc of pb.children) { + if (pbc?.result?.hasResultElements() && pbc.result.resultElement?.hasLog()) { + l.addLog(pbc.result.resultElement.log); } } - if (this._pabResults.cloisonAvalResults && this._pabResults.cloisonAvalResults.resultElement.hasLog()) { - l.addLog(this._pabResults.cloisonAvalResults.resultElement.log); - } + console.log("!!! ITERATION LOG !!! après", l.messages.length); } - } */ + } return l; } diff --git a/src/app/components/pb-schema/pb-schema.component.scss b/src/app/components/pb-schema/pb-schema.component.scss index 72baa1eddf75dd87f56fcb64057f22af2bab8d93..9f4393f827da23efd5e24bfe66cae8c3b2ca5dd4 100644 --- a/src/app/components/pb-schema/pb-schema.component.scss +++ b/src/app/components/pb-schema/pb-schema.component.scss @@ -57,8 +57,23 @@ mat-card-content { margin-top: .5em; margin-bottom: .5em; text-align: center; + overflow-x: scroll; } -#debug { - display: none; +#schema::ng-deep #graphDiv { + + .node.wall, .node.basin { + + .label div { + font-size: 12px; + } + + .label div::first-line { + font-size: 16px; + } + } } + +/* #debug { + display: none; +} */ diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index bf924160d42a8a0514d317029e9be76189ff11c8..faaec518822edfc64eb566aaeddf284a7d82ed1c 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -15,6 +15,9 @@ import { DialogNewPbCloisonComponent } from "../dialog-new-pb-cloison/dialog-new import { GenericCalculatorComponent } from "../generic-calculator/calculator.component"; import { AppComponent } from "../../app.component"; +import { fv } from "app/util"; +import { FormulairePrebarrage } from 'app/formulaire/definition/form-prebarrage'; + /** * The interactive schema for calculator type "PreBarrage" (component) */ @@ -77,7 +80,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni mermaid.initialize({ flowchart: { curve: "basis", - useMaxWidth: true + // useMaxWidth: true } }); this.nativeElement = this.schema.nativeElement; @@ -152,12 +155,13 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni // styles def.push("classDef wall fill:#e8e8e8,stroke-width:0;"); def.push("classDef basin fill:#e0f3fb,stroke:#003A80;"); // irstea-ocean 50 / 500 + def.push("classDef basin::first-line color:green,font-size:0.5em;"); def.push("classDef node-highlighted fill:#4DBBE9;"); // irstea-ocean (material "accent"), 300 const sortedWalls: PbCloison[] = []; for (const c of this.model.children) { if (c instanceof PbBassin) { - def.push(`${c.uid}("${this.itemDescription(c)}")`); // rounded edges + def.push(`${c.uid}("${this.itemDescriptionWithResultData(c)}")`); // rounded edges def.push(`class ${c.uid} basin;`); } else if (c instanceof PbCloison) { // store, to draw later @@ -180,7 +184,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } this.existingWalls[basinsPair]++; // draw wall Node - def.push(`${c.uid}["${this.itemDescription(c)}"]`); // square edges + def.push(`${c.uid}["${this.itemDescriptionWithResultData(c)}"]`); // square edges def.push(`class ${c.uid} wall;`); // draw "arrow" with 2 lines def.push(`${upstreamBasinId}---${c.uid}-->${downstreamBasinId}`); @@ -267,6 +271,38 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni return desc; } + /** + * Lorsque la passe est calculée, ajoute aux nœuds du schéma les valeurs de : + * - PV et YMOY pour les bassins + * - DH et Q pour les cloisons + */ + private itemDescriptionWithResultData(item: PbCloison | PbBassin): string { + let iDesc: string; + if (item !== undefined) { + iDesc = this.itemDescription(item); + if (item.result?.ok) { + // when a parameter is variating, index of the variating parameter + // values to build the data from + const form = this.calculatorComponent.formulaire as FormulairePrebarrage; + console.log(">> found form", form.constructor.name); + console.log(">>> found idx", form?.pbResults?.variableIndex); + const idx = form.pbResults.variableIndex; + iDesc += "<br>"; + if (item instanceof PbCloison) { + iDesc += "Q = " + fv(item.prms.Q.v); + // @TODO chute + /* iDesc += "\n"; + iDesc += item.prms.DH.v; */ + } else if (item instanceof PbBassin) { + iDesc += "PV = " + fv(item.result.resultElement.values.PV); + iDesc += "<br>"; + iDesc += "YMOY = " + fv(item.result.resultElement.values.YMOY); + } + } + } + return iDesc; + } + /** Returns a short description of the given item: wall or basin */ private itemDescription(item: PbCloison | PbBassin): string { let desc = ""; diff --git a/src/app/components/variable-results-selector/variable-results-selector.component.ts b/src/app/components/variable-results-selector/variable-results-selector.component.ts index 68491335a515f172f709427ac6ebcd02762e6218..011925c8ba4c1710de49dc04b23aaab65ea60622 100644 --- a/src/app/components/variable-results-selector/variable-results-selector.component.ts +++ b/src/app/components/variable-results-selector/variable-results-selector.component.ts @@ -1,4 +1,4 @@ -import { Component, Output, EventEmitter, Input, OnChanges } from "@angular/core"; +import { Component, Input, OnChanges } from "@angular/core"; import { I18nService } from "../../services/internationalisation.service"; import { fv, longestVarParam } from "../../util"; diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index ef81a7f793ef6315b3e7a26d2ded26f6df56461e..d03decf7873833038bb2b83bddb77ef25962ad8b 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -228,6 +228,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this._pbResults.cloisonResults.size = lvp.size; } + this.pbResults.result = pb.result; // résultats selon l'objet sélectionné sur le schéma if (this._selectedItem !== undefined && this._selectedItem instanceof PbCloison) { // afficher les résultats de cloison @@ -242,7 +243,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } else { // afficher les résultats des bassins // résultat général du Nub (amont, aval, débit) - this.pbResults.result = pb.result; this.pbResults.calculatedParameter = computedParam; // résultat de chaque bassin for (const b of pb.bassins) { diff --git a/src/app/results/prebarrage-results.ts b/src/app/results/prebarrage-results.ts index 4fba21da8c30fd2a986df5baca2952f216567967..794d0c6b7721dd15797e2d4802c8ff865acc5732 100644 --- a/src/app/results/prebarrage-results.ts +++ b/src/app/results/prebarrage-results.ts @@ -1,4 +1,4 @@ -import { Result } from "jalhyd"; +import { PreBarrage, Result } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; import { MultiDimensionResults } from "./multidimension-results"; @@ -78,18 +78,22 @@ export class PrebarrageResults extends MultiDimensionResults { } /** - * Returns true if at least one log message is present in the PAB result or any + * Returns true if at least one log message is present in the PB result or any * of the children results */ public get hasLog(): boolean { - if (this.bassinsResults) { - for (const cr of this.bassinsResults) { - if (cr && cr.hasLog()) { + if (this.result !== undefined) { + if (this.result.hasLog()) { + return true; + } + const pb = this.result.sourceNub as PreBarrage; + for (const pbc of pb.children) { + if (pbc && pbc.result.hasLog()) { return true; } } } - return (this.cloisonResults && this.cloisonResults.result && this.cloisonResults.result.hasLog()); + return false; } public get hasResults(): boolean {