From e2f4144ae789839a18508a13a7fbecd5a4480b20 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Mon, 13 May 2019 16:09:56 +0200 Subject: [PATCH] =?UTF-8?q?Composant=20pour=20les=20r=C3=A9sultats=20de=20?= =?UTF-8?q?PAB=20(fixes)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.module.ts | 6 +- .../calculator-results.component.html | 1 + .../calculator-results.component.ts | 10 ++ .../fixedvar-results.component.scss | 21 +++ .../fixedvar-results.component.ts | 22 +-- .../fixedvar-results/var-results.component.ts | 10 +- .../pab-results-table.component.html | 32 ++++ .../pab-results-table.component.scss | 63 +++++++ .../pab-results-table.component.ts | 155 ++++++++++++++++++ .../pab-results/pab-results.component.html | 11 ++ .../pab-results/pab-results.component.ts | 126 ++++++++++++++ .../definition/concrete/form-base.ts | 2 +- .../definition/concrete/form-pab.ts | 6 +- .../concrete/form-parallel-structures.ts | 2 +- .../formulaire/definition/form-compute-pab.ts | 65 ++++++-- .../definition/form-result-fixedvar.ts | 10 +- .../formulaire/definition/form-result-pab.ts | 33 ++++ src/app/results/pab-results.ts | 34 ++++ src/locale/messages.en.json | 7 + src/locale/messages.fr.json | 7 + 20 files changed, 569 insertions(+), 54 deletions(-) create mode 100644 src/app/components/fixedvar-results/fixedvar-results.component.scss create mode 100644 src/app/components/pab-results/pab-results-table.component.html create mode 100644 src/app/components/pab-results/pab-results-table.component.scss create mode 100644 src/app/components/pab-results/pab-results-table.component.ts create mode 100644 src/app/components/pab-results/pab-results.component.html create mode 100644 src/app/components/pab-results/pab-results.component.ts create mode 100644 src/app/formulaire/definition/form-result-pab.ts create mode 100644 src/app/results/pab-results.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 09827b43e..6b7d73fd1 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -63,6 +63,8 @@ import { CalcCanvasComponent } from "./components/canvas/canvas.component"; import { SectionCanvasComponent } from "./components/section-canvas/section-canvas.component"; import { RemousResultsComponent } from "./components/remous-results/remous-results.component"; import { ResultsGraphComponent } from "./components/results-graph/results-graph.component"; +import { PabResultsComponent } from "./components/pab-results/pab-results.component"; +import { PabResultsTableComponent } from "./components/pab-results/pab-results-table.component"; import { GraphTypeSelectComponent } from "./components/results-graph/graph-type.component"; import { LogComponent } from "./components/log/log.component"; import { CalculatorListComponent } from "./components/calculator-list/calculator-list.component"; @@ -72,6 +74,7 @@ import { FixedResultsComponent } from "./components/fixedvar-results/fixed-resul import { VarResultsComponent } from "./components/fixedvar-results/var-results.component"; import { LogEntryComponent } from "./components/log-entry/log-entry.component"; import { ParamLinkComponent } from "./components/param-link/param-link.component"; +import { SelectModelFieldLineComponent } from "./components/select-model-field-line/select-model-field-line.component"; import { DialogConfirmEmptySessionComponent } from "./components/dialog-confirm-empty-session/dialog-confirm-empty-session.component"; import { DialogConfirmCloseCalcComponent } from "./components/dialog-confirm-close-calc/dialog-confirm-close-calc.component"; @@ -89,7 +92,6 @@ import { JalhydModelValidationStepDirective } from "./directives/jalhyd-model-validation.directive"; import { ImmediateErrorStateMatcher } from "./formulaire/immediate-error-state-matcher"; -import { SelectModelFieldLineComponent } from "./components/select-model-field-line/select-model-field-line.component"; const appRoutes: Routes = [ { path: "list", component: CalculatorListComponent }, @@ -168,6 +170,8 @@ const appRoutes: Routes = [ LogComponent, LogEntryComponent, NgParamInputComponent, + PabResultsComponent, + PabResultsTableComponent, ParamComputedComponent, ParamFieldLineComponent, ParamLinkComponent, diff --git a/src/app/components/calculator-results/calculator-results.component.html b/src/app/components/calculator-results/calculator-results.component.html index 03c60dfa0..be99ed81b 100644 --- a/src/app/components/calculator-results/calculator-results.component.html +++ b/src/app/components/calculator-results/calculator-results.component.html @@ -1,5 +1,6 @@ <div> <section-results></section-results> <remous-results></remous-results> + <pab-results></pab-results> <fixedvar-results></fixedvar-results> </div> diff --git a/src/app/components/calculator-results/calculator-results.component.ts b/src/app/components/calculator-results/calculator-results.component.ts index c6489fa69..514a86101 100644 --- a/src/app/components/calculator-results/calculator-results.component.ts +++ b/src/app/components/calculator-results/calculator-results.component.ts @@ -3,6 +3,7 @@ import { Component, ViewChild, Output, EventEmitter, AfterViewChecked } from "@a import { FixedVarResultsComponent } from "../../components/fixedvar-results/fixedvar-results.component"; import { SectionResultsComponent } from "../../components/section-results/section-results.component"; import { RemousResultsComponent } from "../../components/remous-results/remous-results.component"; +import { PabResultsComponent } from "../../components/pab-results/pab-results.component"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; @Component({ @@ -30,6 +31,12 @@ export class CalculatorResultsComponent implements AfterViewChecked { @ViewChild(RemousResultsComponent) private remousResultsComponent: RemousResultsComponent; + /** + * composant d'affichage des résultats des passes à bassins + */ + @ViewChild(PabResultsComponent) + private pabResultsComponent: PabResultsComponent; + /** * événement émis à la fin du dessin de la vue */ @@ -42,10 +49,12 @@ export class CalculatorResultsComponent implements AfterViewChecked { this.fixedVarResultsComponent.results = undefined; this.sectionResultsComponent.results = undefined; this.remousResultsComponent.results = undefined; + this.pabResultsComponent.results = undefined; } else { this.fixedVarResultsComponent.results = f.results; this.sectionResultsComponent.results = f.results; this.remousResultsComponent.results = f.results; + this.pabResultsComponent.results = f.results; } } @@ -53,6 +62,7 @@ export class CalculatorResultsComponent implements AfterViewChecked { this.fixedVarResultsComponent.updateView(); this.sectionResultsComponent.updateView(); this.remousResultsComponent.updateView(); + this.pabResultsComponent.updateView(); } public ngAfterViewChecked() { diff --git a/src/app/components/fixedvar-results/fixedvar-results.component.scss b/src/app/components/fixedvar-results/fixedvar-results.component.scss new file mode 100644 index 000000000..6b464cc79 --- /dev/null +++ b/src/app/components/fixedvar-results/fixedvar-results.component.scss @@ -0,0 +1,21 @@ + +.result_right { + text-align: right; +} + +.result_center { + text-align: center; +} + +.result_id_0 { + background-color: #f0f0f0; +} + +.result_id_1 { + background-color: #ffffff; +} + +.result_id_2 { + font-weight: bolder; + background-color: #00d0ff; +} diff --git a/src/app/components/fixedvar-results/fixedvar-results.component.ts b/src/app/components/fixedvar-results/fixedvar-results.component.ts index 3392fb698..ca402293f 100644 --- a/src/app/components/fixedvar-results/fixedvar-results.component.ts +++ b/src/app/components/fixedvar-results/fixedvar-results.component.ts @@ -1,6 +1,5 @@ import { Component, ViewChild, DoCheck } from "@angular/core"; -import { I18nService } from "../../services/internationalisation/internationalisation.service"; import { LogComponent } from "../../components/log/log.component"; import { FixedResults } from "../../results/fixed-results"; import { VarResults } from "../../results/var-results"; @@ -15,24 +14,8 @@ import { VarResultsComponent } from "./var-results.component"; @Component({ selector: "fixedvar-results", templateUrl: "./fixedvar-results.component.html", - styles: [` - .result_right { - text-align: right; - } - .result_center { - text-align: center; - } - .result_id_0 { - background-color: #f0f0f0; - } - .result_id_1 { - background-color: #ffffff; - } - .result_id_2 { - font-weight: bolder; - background-color: #00d0ff; - } - ` + styleUrls: [ + "./fixedvar-results.component.scss" ] }) export class FixedVarResultsComponent implements DoCheck { @@ -66,7 +49,6 @@ export class FixedVarResultsComponent implements DoCheck { private resultsGraphComponent: ResultsGraphComponent; constructor( - private intlService: I18nService, private appSetupService: ApplicationSetupService, ) { } diff --git a/src/app/components/fixedvar-results/var-results.component.ts b/src/app/components/fixedvar-results/var-results.component.ts index 926e5b2a7..b8185119d 100644 --- a/src/app/components/fixedvar-results/var-results.component.ts +++ b/src/app/components/fixedvar-results/var-results.component.ts @@ -15,13 +15,13 @@ import * as XLSX from "xlsx"; export class VarResultsComponent { /** résultats non mis en forme */ - private _varResults: VarResults; + protected _varResults: VarResults; /** résultats mis en forme */ - private _results: any[]; + protected _results: any[]; /** entêtes des colonnes (param à varier, à calculer + extraResults) */ - private _headers: string[]; + protected _headers: string[]; /** tracks the fullscreen state */ public get isFullscreen() { @@ -31,8 +31,8 @@ export class VarResultsComponent { @ViewChild("tableContainer") table: ElementRef; constructor( - private appSetupService: ApplicationSetupService, - private intlService: I18nService + protected appSetupService: ApplicationSetupService, + protected intlService: I18nService ) { } public set results(r: VarResults) { diff --git a/src/app/components/pab-results/pab-results-table.component.html b/src/app/components/pab-results/pab-results-table.component.html new file mode 100644 index 000000000..bbdbf38db --- /dev/null +++ b/src/app/components/pab-results/pab-results-table.component.html @@ -0,0 +1,32 @@ +<!-- @TODO copied from var-results.component.html > merge ?--> +<div class="pab-results-table-container" #pabResultsTable *ngIf="hasResults" fxLayout="row wrap" fxLayoutAlign="center center"> + <div fxFlex="1 1 100%"> + <div class="pab-results-table-buttons"> + <button mat-icon-button (click)="exportAsSpreadsheet()"> + <mat-icon color="primary" svgIcon="file_excel" class="scaled09"></mat-icon> + </button> + <button mat-icon-button *ngIf="! isFullscreen" (click)="setFullscreen(pabResultsTable)"> + <mat-icon color="primary" class="scaled12">fullscreen</mat-icon> + </button> + <button mat-icon-button *ngIf="isFullscreen" (click)="exitFullscreen()"> + <mat-icon color="primary" class="scaled12">fullscreen_exit</mat-icon> + </button> + </div> + + <div class="pab-results-table-scrollable-container" [ngClass]="{'full-height': isFullscreen}"> + <!-- scrollable --> + <div class="pab-results-table-inner-container" #tableContainer> + + <table mat-table [dataSource]="dataSet"> + <ng-container *ngFor="let h of headers; let i = index" [matColumnDef]="h"> + <th mat-header-cell *matHeaderCellDef>{{ h }}</th> + <td mat-cell *matCellDef="let element">{{ element[i] }}</td> + </ng-container> + + <tr mat-header-row *matHeaderRowDef="headers"></tr> + <tr mat-row *matRowDef="let row; columns: headers;"></tr> + </table> + </div> + </div> + </div> +</div> diff --git a/src/app/components/pab-results/pab-results-table.component.scss b/src/app/components/pab-results/pab-results-table.component.scss new file mode 100644 index 000000000..780da209d --- /dev/null +++ b/src/app/components/pab-results/pab-results-table.component.scss @@ -0,0 +1,63 @@ +:host { + display: block; +} + +.pab-results-table-container { + margin-top: 2em; + background-color: white; +} + +.pab-results-table-buttons { + padding-right: 4px; + padding-top: 4px; + text-align: right; + background-color: white; + + button { + margin-left: 3px; + width: auto; + + mat-icon { + &.scaled12 { + transform: scale(1.2) + } + &.scaled09 { + transform: scale(0.9); + } + } + } +} + +.pab-results-table-scrollable-container { + overflow-x: scroll; + border: solid #ccc 1px; + + &.full-height { + height: calc(100vh - 40px); // rend le mode plein-écran scrollable verticalement, sinon ça dépasse + } +} + +table.mat-table { + + .mat-header-row { + height: 40px; + } + + .mat-row { + height: 32px; + + &:nth-child(odd) { + background-color: #f4f4f4; + } + } + + ::ng-deep .mat-cell { + padding: 5px; + } + + ::ng-deep .mat-header-cell { + font-size: 1em; + color: black; + padding: 5px; + } +} diff --git a/src/app/components/pab-results/pab-results-table.component.ts b/src/app/components/pab-results/pab-results-table.component.ts new file mode 100644 index 000000000..da5e5ca79 --- /dev/null +++ b/src/app/components/pab-results/pab-results-table.component.ts @@ -0,0 +1,155 @@ +import { Component, ViewChild, ElementRef } from "@angular/core"; + +import { PabResults } from "../../results/pab-results"; + +import * as XLSX from "xlsx"; +import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; +import { I18nService } from "../../services/internationalisation/internationalisation.service"; + +@Component({ + selector: "pab-results-table", + templateUrl: "./pab-results-table.component.html", + styleUrls: [ + "./pab-results-table.component.scss" + ] +}) +export class PabResultsTableComponent { + + /** résultats non mis en forme */ + private _pabResults: PabResults; + + /** entêtes des colonnes */ + private _headers: string[]; + + /** résultats mis en forme */ + private _dataSet: any[]; + + /** tracks the fullscreen state */ + public get isFullscreen() { + return (document["fullscreenElement"] !== null); + } + + @ViewChild("tableContainer") table: ElementRef; + + constructor( + protected appSetupService: ApplicationSetupService, + protected intlService: I18nService + ) { } + + public set results(r: PabResults) { + this._pabResults = r; + + // refresh headers here if language changed + this._headers = [ + this.intlService.localizeText("INFO_EXTRARES_LIB_CLOISON"), + this.intlService.localizeText("INFO_EXTRARES_LIB_DH"), + this.intlService.localizeText("INFO_EXTRARES_LIB_ZR"), + this.intlService.localizeText("INFO_EXTRARES_LIB_Q"), + this.intlService.localizeText("INFO_EXTRARES_LIB_Z1_PAB"), + this.intlService.localizeText("INFO_EXTRARES_LIB_PV"), + this.intlService.localizeText("INFO_EXTRARES_LIB_TMOY"), + this.intlService.localizeText("INFO_EXTRARES_LIB_ZRB"), + this.intlService.localizeText("INFO_EXTRARES_LIB_QA") + ]; + + this._dataSet = []; + if (this._pabResults) { + const pr = this._pabResults; + const nDigits = this.appSetupService.displayDigits; + // line 1 + this._dataSet.push([ + "", "", "", "", + this._pabResults.cloisonsResults[0] ? this._pabResults.cloisonsResults[0].vCalc.toFixed(nDigits) : "X", + "", "", "", "" + ]); + + // lines 2 - n-1 + for (let i = 0; i < pr.cloisonsResults.length - 1; i++) { + if (pr.cloisonsResults[i]) { + const ZRAM = pr.cloisonsResults[i].getExtraResult("ZRAM"); + const PV = pr.cloisonsResults[i].getExtraResult("PV"); + const Y = pr.cloisonsResults[i].getExtraResult("Y"); + const ZRB = pr.cloisonsResults[i].getExtraResult("ZRB"); + this._dataSet.push([ + i + 1, + (pr.cloisonsResults[i].vCalc - pr.cloisonsResults[i + 1].vCalc).toFixed(nDigits), + ZRAM ? ZRAM.toFixed(nDigits) : "X", + pr.cloisonsQ[i].toFixed(nDigits), + pr.cloisonsResults[i + 1].vCalc.toFixed(nDigits), + PV ? PV.toFixed(nDigits) : "X", + Y ? Y.toFixed(nDigits) : "X", + ZRB ? ZRB.toFixed(nDigits) : "X", + pr.bassinsQA[i] + ]); + } else { + // @TODO remove dummy data when "pab.children[0] is undefined" bug is resolved + this._dataSet.push([ "1", "X", "X", "X", "X", "X", "X", "X", "X" ]); + } + } + + // line n + const l = pr.cloisonsResults.length; + const nZRAM = pr.cloisonsResults[l - 1].getExtraResult("ZRAM"); + const nPV = pr.cloisonsResults[l - 1].getExtraResult("PV"); + const nY = pr.cloisonsResults[l - 1].getExtraResult("Y"); + const nZRB = pr.cloisonsResults[l - 1].getExtraResult("ZRB"); + this._dataSet.push([ + l, + (pr.cloisonsResults[l - 1].vCalc - pr.cloisonAvalResults.vCalc).toFixed(nDigits), + nZRAM ? nZRAM.toFixed(nDigits) : "X", + pr.cloisonsQ[l - 1].toFixed(nDigits), + pr.cloisonAvalResults.vCalc.toFixed(nDigits), + nPV ? nPV.toFixed(nDigits) : "X", + nY ? nY.toFixed(nDigits) : "X", + nZRB ? nZRB.toFixed(nDigits) : "X", + pr.bassinsQA[l - 1] + ]); + + // downstream line + const caZRAM = pr.cloisonAvalResults.getExtraResult("ZRAM"); + this._dataSet.push([ + this.intlService.localizeText("INFO_EXTRARES_LIB_AVAL"), + (pr.cloisonAvalResults.vCalc - pr.Z2).toFixed(nDigits), + caZRAM ? caZRAM.toFixed(nDigits) : "X", + pr.cloisonAvalQ.toFixed(nDigits), + pr.Z2.toFixed(nDigits), + "", + "", + "", + "" + ]); + } + } + + public get hasResults(): boolean { + return this._pabResults && this._pabResults.hasResults; + } + + public get headers() { + return this._headers; + } + + /** + * Returns a combination of and results and extraResults for mat-table + */ + public get dataSet() { + return this._dataSet; + } + + public setFullscreen(element) { + element.requestFullscreen(); + } + + public exitFullscreen() { + document.exitFullscreen(); + } + + public exportAsSpreadsheet() { + // automagic <table> extraction + const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement); + const wb: XLSX.WorkBook = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, "default"); + // save and download + XLSX.writeFile(wb, "VariableResults.xlsx"); + } +} diff --git a/src/app/components/pab-results/pab-results.component.html b/src/app/components/pab-results/pab-results.component.html new file mode 100644 index 000000000..02aa6f94e --- /dev/null +++ b/src/app/components/pab-results/pab-results.component.html @@ -0,0 +1,11 @@ +<div class="container"> + <!-- journal --> + <log></log> + + <!-- <results-graph *ngIf="showVarResults"></results-graph> --> + + <div> + <!-- tableau de résultats --> + <pab-results-table [results]="pabResults"></pab-results-table> + </div> +</div> diff --git a/src/app/components/pab-results/pab-results.component.ts b/src/app/components/pab-results/pab-results.component.ts new file mode 100644 index 000000000..d787ca36c --- /dev/null +++ b/src/app/components/pab-results/pab-results.component.ts @@ -0,0 +1,126 @@ +import { Component, ViewChild, DoCheck } from "@angular/core"; + +import { LogComponent } from "../../components/log/log.component"; +import { CalculatorResults } from "../../results/calculator-results"; +import { Result, cLog } from "jalhyd"; +import { NgParameter } from "../../formulaire/ngparam"; +import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; +import { PabResultsTableComponent } from "./pab-results-table.component"; +import { PabResults } from "../../results/pab-results"; + +@Component({ + selector: "pab-results", + templateUrl: "./pab-results.component.html", + styleUrls: [ + "../fixedvar-results/fixedvar-results.component.scss" + ] +}) +export class PabResultsComponent implements DoCheck { + + /** résultats non mis en forme */ + private _pabResults: PabResults; + + /** true si les résultats doiventt être remis à jour */ + private _doUpdate = false; + + @ViewChild(PabResultsTableComponent) + private pabResultsTableComponent: PabResultsTableComponent; + + /** composant journal */ + @ViewChild(LogComponent) + private logComponent: LogComponent; + + constructor( + private appSetupService: ApplicationSetupService, + ) { } + + public set results(rs: CalculatorResults[]) { + if (rs.length > 0) { + this._pabResults = rs[0] as PabResults; + } + this.updateView(); + } + + public updateView() { + this.logComponent.log = undefined; + if (this.pabResultsTableComponent) { + this.pabResultsTableComponent.results = undefined; + } + // set _doUpdate flag so that results are rebuilt on the next Angular display cycle + this._doUpdate = false; + if (this._pabResults !== undefined) { + this._doUpdate = this._doUpdate || this._pabResults.hasResults || this._pabResults.hasLog; + } + } + + public ngDoCheck() { + if (this._doUpdate) { + this._doUpdate = !this.updateResults(); + } + } + + private mergeLog(result: Result, log: cLog) { + if (result && result.hasLog) { + if (result.hasGlobalLog) { + log.addLog(result.globalLog); + } else { + log.addLog(result.log); + } + } + } + + private get mergedGlobalLogs(): cLog { + const res = new cLog(); + if (this._pabResults) { + this.mergeLog(this._pabResults.result, res); + } + return res; + } + + /** + * met à jour l'affichage des résultats + * @returns true si les résultats ont pu être mis à jour + */ + private updateResults() { + let pabUpdated: boolean; + if (this.hasResults) { + pabUpdated = this.pabResultsTableComponent !== undefined; + if (pabUpdated) { + this.pabResultsTableComponent.results = this._pabResults; + } + } else { + pabUpdated = true; + } + + const logUpdated = this.logComponent !== undefined; + if (logUpdated) { + this.logComponent.log = this.mergedGlobalLogs; + } + + return pabUpdated && logUpdated; + } + + /** + * affichage de la table des résultats de passe à bassins + */ + public get showPabResults(): boolean { + return this.hasResults; + } + + public get pabResults() { + return this._pabResults; + } + + public formattedLabel(p: NgParameter): string { + return CalculatorResults.paramLabel(p, false); + } + + public formattedValue(p: NgParameter): string { + const nDigits = this.appSetupService.displayDigits; + return p.getValue().toFixed(nDigits); + } + + public get hasResults(): boolean { + return this._pabResults && this._pabResults.hasResults; + } +} diff --git a/src/app/formulaire/definition/concrete/form-base.ts b/src/app/formulaire/definition/concrete/form-base.ts index d033e5076..e54548b98 100644 --- a/src/app/formulaire/definition/concrete/form-base.ts +++ b/src/app/formulaire/definition/concrete/form-base.ts @@ -14,7 +14,7 @@ export class FormulaireBase extends FormulaireDefinition { constructor() { super(); - this._formResult = new FormResultFixedVar(this, false); + this._formResult = new FormResultFixedVar(this); this._formCompute = new FormComputeFixedVar(this, (this._formResult as FormResultFixedVar)); } diff --git a/src/app/formulaire/definition/concrete/form-pab.ts b/src/app/formulaire/definition/concrete/form-pab.ts index 71243ff67..18b63e068 100644 --- a/src/app/formulaire/definition/concrete/form-pab.ts +++ b/src/app/formulaire/definition/concrete/form-pab.ts @@ -1,6 +1,5 @@ import { Nub, Props, Session, PabCloisons, Pab } from "jalhyd"; -import { FormResultFixedVar } from "../form-result-fixedvar"; import { FieldsetContainer } from "../../fieldset-container"; import { FieldSet } from "../../fieldset"; import { SelectField } from "../../select-field"; @@ -9,6 +8,7 @@ import { FieldsetTemplate } from "../../fieldset-template"; import { FormulaireNode } from "../../formulaire-node"; import { FormulaireBase } from "./form-base"; import { FormComputePab } from "../form-compute-pab"; +import { FormResultPab } from "../form-result-pab"; /** * Formulaire pour les passes à bassins, inspiré du formulaire @@ -24,11 +24,11 @@ export class FormulairePab extends FormulaireBase { constructor() { super(); - this._formResult = new FormResultFixedVar(this, false); + this._formResult = new FormResultPab(this); // remove obsolete observer set by super() this.removeObserver(this._formCompute); - this._formCompute = new FormComputePab(this, (this._formResult as FormResultFixedVar)); + this._formCompute = new FormComputePab(this, (this._formResult as FormResultPab)); } public get modeleCloisonsSelectId(): string { diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index bc954c296..ada70cc18 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -19,7 +19,7 @@ export class FormulaireParallelStructure extends FormulaireBase { constructor() { super(); - this._formResult = new FormResultFixedVar(this, false); + this._formResult = new FormResultFixedVar(this); // remove obsolete observer set by super() this.removeObserver(this._formCompute); diff --git a/src/app/formulaire/definition/form-compute-pab.ts b/src/app/formulaire/definition/form-compute-pab.ts index 888019181..a3e1d2d22 100644 --- a/src/app/formulaire/definition/form-compute-pab.ts +++ b/src/app/formulaire/definition/form-compute-pab.ts @@ -1,28 +1,57 @@ -import { ParamDefinition, PabCloisons, Pab } from "jalhyd"; +import { Result, Pab } from "jalhyd"; -import { FormComputeFixedVar } from "./form-compute-fixedvar"; -import { FormResultFixedVar } from "./form-result-fixedvar"; import { FormulaireDefinition } from "./form-definition"; +import { FormResultPab } from "./form-result-pab"; +import { FormCompute } from "./form-compute"; +import { NgParameter, ParamRadioConfig } from "../ngparam"; -export class FormComputePab extends FormComputeFixedVar { +export class FormComputePab extends FormCompute { - constructor(formBase: FormulaireDefinition, formResult: FormResultFixedVar) { + constructor(formBase: FormulaireDefinition, formResult: FormResultPab) { super(formBase, formResult); } - /** - * construit un identifiant de type { uid: "abcdef", symbol: "X" } - * avec "abcdef" l'index du bassin et "X" son paramètre - */ - protected getParameterRefid(p: ParamDefinition): any { - const nub = p.parentComputeNode; - if (nub instanceof PabCloisons) { - return { - uid: nub.uid, - symbol: p.symbol - }; - } else { - return super.getParameterRefid(p); + protected get formResult(): FormResultPab { + return this._formResult as FormResultPab; + } + + protected compute() { + this.runNubCalc(this._formBase.currentNub); + this.reaffectResultComponents(); + } + + protected reaffectResultComponents() { + const pab: Pab = (this._formBase.currentNub as Pab); + const computedParam: NgParameter = this.getComputedParameter(); + + // résultat de calcul de la passe à bassins + const pabr = this.formResult.pabResults; + pabr.calculatedParameter = computedParam; + pabr.result = pab.result; + // résultat de chaque cloison + const cr: Result[] = []; + // valeur de Q pour chaque cloison + const cq: number[] = []; + // valeur de QA pour chaque bassin + const bqa: number[] = []; + console.log("pab.children[0].result >>", pab.children[0].result); + for (const c of pab.children) { + cr.push(c.result); + cq.push(c.prms.Q.v); + bqa.push(c.prms.QA.v); } + pabr.cloisonsResults = cr, + pabr.cloisonsQ = cq, + pabr.bassinsQA = bqa; + // résultat de la cloison aval + pabr.cloisonAvalResults = pab.downWall.result; + // débit de la cloison aval + pabr.cloisonAvalQ = pab.downWall.prms.Q.v; + // cote aval de la passe + pabr.Z2 = pab.prms.Z2.v; + } + + private getComputedParameter(): NgParameter { + return this._formBase.getDisplayedParamFromState(ParamRadioConfig.CAL); } } diff --git a/src/app/formulaire/definition/form-result-fixedvar.ts b/src/app/formulaire/definition/form-result-fixedvar.ts index be7137587..53b9c455c 100644 --- a/src/app/formulaire/definition/form-result-fixedvar.ts +++ b/src/app/formulaire/definition/form-result-fixedvar.ts @@ -1,6 +1,6 @@ import { FixedResults } from "../../results/fixed-results"; import { GraphType, VarResults } from "../../results/var-results"; -import { ParamRadioConfig, NgParameter } from "../ngparam"; +import { ParamRadioConfig } from "../ngparam"; import { FormResult } from "./form-result"; import { FormulaireDefinition } from "./form-definition"; import { CalculatorResults } from "../../results/calculator-results"; @@ -9,12 +9,12 @@ export class FormResultFixedVar extends FormResult { /** * résultats fixes/variables */ - private _fixedResults: FixedResults; - private _varResults: VarResults; + protected _fixedResults: FixedResults; + protected _varResults: VarResults; - private _formBase: FormulaireDefinition; + protected _formBase: FormulaireDefinition; - constructor(base: FormulaireDefinition, private displaySymbol: boolean) { + constructor(base: FormulaireDefinition) { super(); this._formBase = base; this._fixedResults = new FixedResults(); diff --git a/src/app/formulaire/definition/form-result-pab.ts b/src/app/formulaire/definition/form-result-pab.ts new file mode 100644 index 000000000..5adc86f13 --- /dev/null +++ b/src/app/formulaire/definition/form-result-pab.ts @@ -0,0 +1,33 @@ +import { FormulaireDefinition } from "./form-definition"; +import { FormResult } from "./form-result"; +import { CalculatorResults } from "../../results/calculator-results"; +import { PabResults } from "../../results/pab-results"; + +export class FormResultPab extends FormResult { + + protected _formBase: FormulaireDefinition; + + protected _pabResults: PabResults; + + constructor(base: FormulaireDefinition) { + super(); + this._formBase = base; + this._pabResults = new PabResults(); + } + + public get pabResults() { + return this._pabResults; + } + + public resetResults() { + this._pabResults.reset(); + } + + public get results(): CalculatorResults[] { + return [ this._pabResults ]; + } + + public get hasResults(): boolean { + return this._pabResults.hasResults; + } +} diff --git a/src/app/results/pab-results.ts b/src/app/results/pab-results.ts new file mode 100644 index 000000000..c30f8c1ec --- /dev/null +++ b/src/app/results/pab-results.ts @@ -0,0 +1,34 @@ +import { CalculatedParamResults } from "./param-calc-results"; +import { Result } from "jalhyd"; + +export class PabResults extends CalculatedParamResults { + + /** résultats des modules Cloisons avant chaque bassin */ + public cloisonsResults: Result[]; + + /** valeur de Q pour chaque module Cloisons */ + public cloisonsQ: number[]; + + /** valeur de QA pour chaque bassin */ + public bassinsQA: number[]; + + /** résultats du module ParallelStructure pour la cloison aval */ + public cloisonAvalResults: Result; + + /** débit de la cloison aval */ + public cloisonAvalQ: number; + + /** cote aval de l'ensemble de la passe */ + public Z2: number; + + public constructor() { + super(); + this.reset(); + } + + public reset() { + super.reset(); + this.cloisonsResults = undefined; + this.cloisonAvalResults = undefined; + } +} diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 67d14da0e..e7385b44c 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -83,9 +83,12 @@ "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_1": "Partially submerged", "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_2": "Submerged", "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_3": "Zero flow", + "INFO_EXTRARES_LIB_AVAL": "Downstream", "INFO_EXTRARES_LIB_B": "Surface width (m)", + "INFO_EXTRARES_LIB_CLOISON": "Cross wall n°", "INFO_EXTRARES_LIB_CV": "Cv: Velocity coefficient", "INFO_EXTRARES_LIB_CVQT": "CV.QT: Corrected discharge (m³/s)", + "INFO_EXTRARES_LIB_DH": "Fall (m)", "INFO_EXTRARES_LIB_DHR": "DHR : Residual fall (m)", "INFO_EXTRARES_LIB_EC": "EC: Kinetic energy (m)", "INFO_EXTRARES_LIB_ENUM_MACRORUGOFLOWTYPE": "Flow type", @@ -101,11 +104,13 @@ "INFO_EXTRARES_LIB_OUVRAGE_Q_REGIME": "Regime", "INFO_EXTRARES_LIB_P": "Wetted perimeter (m)", "INFO_EXTRARES_LIB_PV": "Volumic dissipated power (W/m³)", + "INFO_EXTRARES_LIB_QA": "Attraction flow (m³/s)", "INFO_EXTRARES_LIB_Q": "Flow (m³/s)", "INFO_EXTRARES_LIB_Q_GUIDETECH": "Technical guide flow (m³/s)", "INFO_EXTRARES_LIB_R": "Hydraulic radius (m)", "INFO_EXTRARES_LIB_S": "Wetted area (m²)", "INFO_EXTRARES_LIB_TAU0": "Tractive force (Pa)", + "INFO_EXTRARES_LIB_TMOY": "Average depth (m)", "INFO_EXTRARES_LIB_TOR": "Supercritical water line", "INFO_EXTRARES_LIB_V": "Average speed (m/s)", "INFO_EXTRARES_LIB_VDEB": "Conveyance speed (m/s)", @@ -116,6 +121,8 @@ "INFO_EXTRARES_LIB_YF": "Subcritical depth (m)", "INFO_EXTRARES_LIB_YN": "Normal depth (m)", "INFO_EXTRARES_LIB_YT": "Supercritical depth (m)", + "INFO_EXTRARES_LIB_Z1_PAB": "Water level (m)", + "INFO_EXTRARES_LIB_ZR": "Bottom elevation (m)", "INFO_EXTRARES_LIB_ZRB": "Downstream basin bottom elevation (m)", "INFO_EXTRARES_LIB_ZF2": "Downstream bottom elevation (m)", "INFO_LECHAPTCALMON_TITRE": "Lechapt-Calmon", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index a7aaa7a93..61856081f 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -83,9 +83,12 @@ "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_1": "Partiellement noyé", "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_2": "Noyé", "INFO_EXTRARES_ENUM_STRUCTUREFLOWREGIME_3": "Débit nul", + "INFO_EXTRARES_LIB_AVAL": "Aval", "INFO_EXTRARES_LIB_B": "Largeur au miroir (m)", + "INFO_EXTRARES_LIB_CLOISON": "Cloison n°", "INFO_EXTRARES_LIB_CV": "Cv: Coefficient de vitesse d'approche", "INFO_EXTRARES_LIB_CVQT": "CV.QT: Débit corrigé (m³/s)", + "INFO_EXTRARES_LIB_DH": "Chute (m)", "INFO_EXTRARES_LIB_DHR": "DHR: Chute résiduelle (m)", "INFO_EXTRARES_LIB_EC": "EC: Énergie cinétique (m)", "INFO_EXTRARES_LIB_ENUM_MACRORUGOFLOWTYPE": "Type d'écoulement", @@ -103,9 +106,11 @@ "INFO_EXTRARES_LIB_PV": "Puissance volumique dissipée (W/m³)", "INFO_EXTRARES_LIB_Q": "Débit (m³/s)", "INFO_EXTRARES_LIB_Q_GUIDETECH": "Débit Guide technique (m³/s)", + "INFO_EXTRARES_LIB_QA": "Débit d'attrait (m³/s)", "INFO_EXTRARES_LIB_R": "Rayon hydraulique (m)", "INFO_EXTRARES_LIB_S": "Surface mouillée (m²)", "INFO_EXTRARES_LIB_TAU0": "Force tractrice (Pa)", + "INFO_EXTRARES_LIB_TMOY": "Tirant d'eau moyen (m)", "INFO_EXTRARES_LIB_TOR": "Ligne d'eau torrentielle", "INFO_EXTRARES_LIB_V": "Vitesse moyenne (m/s)", "INFO_EXTRARES_LIB_VDEB": "Vitesse débitante (m/s)", @@ -116,6 +121,8 @@ "INFO_EXTRARES_LIB_YF": "Tirant d'eau fluvial (m)", "INFO_EXTRARES_LIB_YN": "Tirant d'eau normal (m)", "INFO_EXTRARES_LIB_YT": "Tirant d'eau torrentiel (m)", + "INFO_EXTRARES_LIB_Z1_PAB": "Niveau d'eau (m)", + "INFO_EXTRARES_LIB_ZR": "Cote de radier (m)", "INFO_EXTRARES_LIB_ZRB": "Cote de radier du bassin aval (m)", "INFO_EXTRARES_LIB_ZF2": "Cote de fond aval (m)", "INFO_LECHAPTCALMON_TITRE": "Lechapt-Calmon", -- GitLab