From 2212c3bd7bd30e6762c13e68c4bfd3563f250137 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Fri, 10 Jul 2020 14:38:25 +0200 Subject: [PATCH] Prebarrage: reorganize results component --- angular.json | 1 + ...ialog-generate-par-simulation.component.ts | 3 +- .../fixed-results.component.html | 1 - .../fixed-results.component.ts | 8 +- .../fixedvar-results.component.ts | 4 - .../fixedvar-results/results.component.ts | 6 ++ .../fixedvar-results/var-results.component.ts | 6 +- .../calculator.component.ts | 5 +- .../macrorugo-compound-results.component.ts | 8 +- .../pab-profile-chart.component.ts | 8 +- .../pab-results/pab-results.component.ts | 9 +-- .../pb-results/pb-results-table.component.ts | 12 +-- .../pb-results/pb-results.component.html | 6 +- .../pb-results/pb-results.component.ts | 73 ++++++++++++------ .../pb-schema/pb-schema.component.ts | 37 ++++----- .../variable-results-selector.component.ts | 38 ++++++++-- .../definition/form-courbe-remous.ts | 2 +- .../formulaire/definition/form-definition.ts | 18 ++--- .../formulaire/definition/form-fixedvar.ts | 6 +- .../definition/form-macrorugo-compound.ts | 4 +- src/app/formulaire/definition/form-pab.ts | 8 +- .../formulaire/definition/form-prebarrage.ts | 76 +++++++++++++------ .../definition/form-section-parametree.ts | 6 +- src/app/formulaire/elements/ngparam.ts | 4 - src/app/formulaire/elements/pb-schema.ts | 3 + src/app/results/multidimension-results.ts | 5 +- src/app/results/plottable-data.ts | 4 +- .../plottable-macrorugo-compound-results.ts | 6 +- src/app/results/plottable-pab-results.ts | 6 +- src/app/results/prebarrage-results.ts | 31 ++++++-- src/app/results/remous-results.ts | 12 ++- src/app/results/var-results.ts | 58 +++++++------- src/app/services/formulaire.service.ts | 4 +- .../services/internationalisation.service.ts | 12 ++- src/app/util.ts | 21 ----- src/locale/messages.en.json | 7 +- src/locale/messages.fr.json | 7 +- 37 files changed, 300 insertions(+), 225 deletions(-) diff --git a/angular.json b/angular.json index 9ff58982c..0f22c724b 100644 --- a/angular.json +++ b/angular.json @@ -54,6 +54,7 @@ "showCircularDependencies": false, "allowedCommonJsDependencies": [ "chartjs-plugin-zoom", + "angular2-chartjs/dist/chart.component", "angular2-chartjs/dist/chart.module", "angular2-hotkeys.js", "base-64", diff --git a/src/app/components/dialog-generate-par-simulation/dialog-generate-par-simulation.component.ts b/src/app/components/dialog-generate-par-simulation/dialog-generate-par-simulation.component.ts index ff941247e..1432867c0 100644 --- a/src/app/components/dialog-generate-par-simulation/dialog-generate-par-simulation.component.ts +++ b/src/app/components/dialog-generate-par-simulation/dialog-generate-par-simulation.component.ts @@ -3,8 +3,7 @@ import { Inject, Component } from "@angular/core"; import { I18nService } from "../../services/internationalisation.service"; import { MultiDimensionResults } from "../../results/multidimension-results"; - -import { fv, longestVarNgParam } from "../../util"; +import { longestVarParam, fv } from "../../util"; @Component({ selector: "dialog-generate-par-simulation", diff --git a/src/app/components/fixedvar-results/fixed-results.component.html b/src/app/components/fixedvar-results/fixed-results.component.html index 849bf9d4e..cfd30782d 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.html +++ b/src/app/components/fixedvar-results/fixed-results.component.html @@ -1,5 +1,4 @@ <div class="fixed-results-container" *ngIf="hasFixedParameters"> - <div class="fixed-results-buttons"> <button mat-icon-button (click)="exportAsSpreadsheet()" [title]="uitextExportAsSpreadsheet"> <mat-icon color="primary">file_download</mat-icon> diff --git a/src/app/components/fixedvar-results/fixed-results.component.ts b/src/app/components/fixedvar-results/fixed-results.component.ts index 32660b368..7607bb47e 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.ts +++ b/src/app/components/fixedvar-results/fixed-results.component.ts @@ -63,10 +63,6 @@ export class FixedResultsComponent extends ResultsComponentDirective { return this._fixedResults && this._fixedResults.fixedParameters.length > 0; } - public formattedLabel(p: NgParameter): string { - return CalculatorResults.paramLabel(p, false); - } - /** * Returns a set of parameters and results for mat-table */ @@ -114,7 +110,7 @@ export class FixedResultsComponent extends ResultsComponentDirective { if (sn.parent) { ct = sn.parent.calcType; } - let unit; + let unit: string; // is k the calculated parameter ? If so, extract its unit try { const p = res.sourceNub.getParameter(k); @@ -232,7 +228,7 @@ export class FixedResultsComponent extends ResultsComponentDirective { if (sn.parent) { ct = sn.parent.calcType; } - let unit; + let unit: string; // is k the calculated parameter ? If so, extract its unit try { const p = res.sourceNub.getParameter(k); diff --git a/src/app/components/fixedvar-results/fixedvar-results.component.ts b/src/app/components/fixedvar-results/fixedvar-results.component.ts index 84d2cda25..eb491d2d9 100644 --- a/src/app/components/fixedvar-results/fixedvar-results.component.ts +++ b/src/app/components/fixedvar-results/fixedvar-results.component.ts @@ -187,10 +187,6 @@ export class FixedVarResultsComponent extends ResultsComponentDirective implemen return this._fixedResults; } - public formattedLabel(p: NgParameter): string { - return CalculatorResults.paramLabel(p, false); - } - public get varResults() { return this._varResults; } diff --git a/src/app/components/fixedvar-results/results.component.ts b/src/app/components/fixedvar-results/results.component.ts index 00d4f84e3..eda93d7c3 100644 --- a/src/app/components/fixedvar-results/results.component.ts +++ b/src/app/components/fixedvar-results/results.component.ts @@ -4,6 +4,8 @@ import { Screenfull } from "screenfull"; // @see https://github.com/sindresorhus import { NgParameter } from "../../formulaire/elements/ngparam"; import { ServiceFactory } from "../../services/service-factory"; import { fv } from "../../util"; +import { CalculatorResults } from "../../results/calculator-results"; + import { Directive } from "@angular/core"; /** @@ -80,6 +82,10 @@ export class ResultsComponentDirective { ]; } + public formattedLabel(p: NgParameter): string { + return CalculatorResults.paramLabel(p, false); + } + /** * Formats (rounds) the given number (or the value of the given parameter) with the * number of decimals specified in app preferences; if given number is too low and diff --git a/src/app/components/fixedvar-results/var-results.component.ts b/src/app/components/fixedvar-results/var-results.component.ts index b5a66d774..d1ba56c32 100644 --- a/src/app/components/fixedvar-results/var-results.component.ts +++ b/src/app/components/fixedvar-results/var-results.component.ts @@ -8,7 +8,7 @@ import { I18nService } from "../../services/internationalisation.service"; import { ResultsComponentDirective } from "./results.component"; import { DialogLogEntriesDetailsComponent } from "../dialog-log-entries-details/dialog-log-entries-details.component"; import { AppComponent } from "../../app.component"; -import { longestVarNgParam } from "../../../app/util"; +import { longestVarParam } from "../../../app/util"; @Component({ selector: "var-results", @@ -68,12 +68,12 @@ export class VarResultsComponent extends ResultsComponentDirective { // C. pre-extract variable parameters values const varValues = []; // find longest list - const lvp = longestVarNgParam(this._varResults.variatedParameters); + const lvp = longestVarParam(this._varResults.variatedParameters); this.size = lvp.size; // get extended values lists for each variable parameter for (const v of this._varResults.variatedParameters) { const vv = []; - const iter = v.getExtendedValuesIterator(this.size); + const iter = v.param.getExtendedValuesIterator(this.size); while (iter.hasNext) { const nv = iter.next(); vv.push(this.formattedValue(nv.value)); diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index c5fa86367..93b0569ee 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -19,7 +19,8 @@ import { Par, ParSimulationParams, ParSimulation, - Espece + Espece, + VariatedDetails } from "jalhyd"; import { generateValuesCombination } from "../../util"; @@ -961,7 +962,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const pcal = parCalage.prms; let pres: { [key: string]: number } = parCalage.result.values; - const varParams: NgParameter[] = this._formulaire.getVariatedParameters(); + const varParams: VariatedDetails[] = this._formulaire.getVariatedParameters(); if (varParams.length > 0) { // open popup to choose combination of varying parameters const mdParResults = new MultiDimensionResults(); diff --git a/src/app/components/macrorugo-compound-results/macrorugo-compound-results.component.ts b/src/app/components/macrorugo-compound-results/macrorugo-compound-results.component.ts index e15ade96c..d2d932838 100644 --- a/src/app/components/macrorugo-compound-results/macrorugo-compound-results.component.ts +++ b/src/app/components/macrorugo-compound-results/macrorugo-compound-results.component.ts @@ -15,6 +15,7 @@ import { VariableResultsSelectorComponent } from "../variable-results-selector/v import { MacrorugoCompoundResultsTableComponent } from "./macrorugo-compound-results-table.component"; import { MacrorugoCompoundResults } from "../../results/macrorugo-compound-results"; import { PlottableMacrorugoCompoundResults } from "../../results/plottable-macrorugo-compound-results"; +import { ResultsComponentDirective } from "../fixedvar-results/results.component"; @Component({ selector: "macrorugo-compound-results", @@ -23,7 +24,7 @@ import { PlottableMacrorugoCompoundResults } from "../../results/plottable-macro "./macrorugo-compound-results.component.scss" ] }) -export class MacrorugoCompoundResultsComponent implements DoCheck { +export class MacrorugoCompoundResultsComponent extends ResultsComponentDirective implements DoCheck { /** résultats non mis en forme */ private _mrcResults: MacrorugoCompoundResults; @@ -53,6 +54,7 @@ export class MacrorugoCompoundResultsComponent implements DoCheck { private appSetupService: ApplicationSetupService, private i18nService: I18nService, ) { + super(); this._plottableResults = new PlottableMacrorugoCompoundResults(); } @@ -280,10 +282,6 @@ export class MacrorugoCompoundResultsComponent implements DoCheck { return this._mrcResults; } - public formattedLabel(p: NgParameter): string { - return CalculatorResults.paramLabel(p, false); - } - public formattedValue(p: NgParameter): string { const nDigits = this.appSetupService.displayPrecision; return p.getValue().toFixed(nDigits); diff --git a/src/app/components/pab-profile-chart/pab-profile-chart.component.ts b/src/app/components/pab-profile-chart/pab-profile-chart.component.ts index 4b47585b7..ce34f4dae 100644 --- a/src/app/components/pab-profile-chart/pab-profile-chart.component.ts +++ b/src/app/components/pab-profile-chart/pab-profile-chart.component.ts @@ -6,7 +6,7 @@ import { I18nService } from "../../services/internationalisation.service"; import { ResultsComponentDirective } from "../fixedvar-results/results.component"; import { PabResults } from "../../results/pab-results"; import { IYSeries } from "../../results/y-series"; -import { fv, longestVarNgParam } from "../../util"; +import { fv, longestVarParam } from "../../util"; import { AppComponent } from "../../app.component"; import { CloisonAval, Cloisons, LoiDebit } from "jalhyd"; @@ -132,12 +132,12 @@ export class PabProfileChartComponent extends ResultsComponentDirective { if (this._results) { this.varValues = []; // find longest list - const lvp = longestVarNgParam(this._results.variatedParameters); + const lvp = longestVarParam(this._results.variatedParameters); this.size = lvp.size; // get extended values lists for each variable parameter for (const v of this._results.variatedParameters) { const vv = []; - const iter = v.getExtendedValuesIterator(this.size); + const iter = v.param.getExtendedValuesIterator(this.size); while (iter.hasNext) { const nv = iter.next(); vv.push(fv(nv.value)); @@ -458,7 +458,7 @@ export class PabProfileChartComponent extends ResultsComponentDirective { i++; let value = "0"; value = vv[n]; - return `${vp.symbol} = ${value}`; + return `${vp.param.symbol} = ${value}`; }).join(", "); } } diff --git a/src/app/components/pab-results/pab-results.component.ts b/src/app/components/pab-results/pab-results.component.ts index 79551c24d..309a6647a 100644 --- a/src/app/components/pab-results/pab-results.component.ts +++ b/src/app/components/pab-results/pab-results.component.ts @@ -4,7 +4,6 @@ import { Result, cLog, Message, MessageCode, MessageSeverity } from "jalhyd"; import { LogComponent } from "../../components/log/log.component"; import { CalculatorResults } from "../../results/calculator-results"; -import { NgParameter } from "../../formulaire/elements/ngparam"; import { PabResultsTableComponent } from "./pab-results-table.component"; import { PabResults } from "../../results/pab-results"; import { VariableResultsSelectorComponent } from "../variable-results-selector/variable-results-selector.component"; @@ -13,6 +12,7 @@ import { PlottablePabResults } from "../../results/plottable-pab-results"; import { ResultsChartComponent } from "../results-chart/results-chart.component"; import { I18nService } from "../../services/internationalisation.service"; import { PabProfileChartComponent } from "../pab-profile-chart/pab-profile-chart.component"; +import { ResultsComponentDirective } from "../fixedvar-results/results.component"; @Component({ selector: "pab-results", @@ -21,7 +21,7 @@ import { PabProfileChartComponent } from "../pab-profile-chart/pab-profile-chart "./pab-results.component.scss" ] }) -export class PabResultsComponent implements DoCheck { +export class PabResultsComponent extends ResultsComponentDirective implements DoCheck { /** résultats non mis en forme */ private _pabResults: PabResults; @@ -53,6 +53,7 @@ export class PabResultsComponent implements DoCheck { constructor( private i18nService: I18nService, ) { + super(); this._plottableResults = new PlottablePabResults(); } @@ -316,10 +317,6 @@ export class PabResultsComponent implements DoCheck { return this._pabResults; } - public formattedLabel(p: NgParameter): string { - return CalculatorResults.paramLabel(p, false); - } - public get hasResults(): boolean { return this._pabResults && this._pabResults.hasResults; } 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 792286c8e..c064fabb9 100644 --- a/src/app/components/pb-results/pb-results-table.component.ts +++ b/src/app/components/pb-results/pb-results-table.component.ts @@ -41,13 +41,13 @@ export class PbResultsTableComponent extends ResultsComponentDirective { * @param p parameter * @param i index */ - protected getIthValue(p: ParamDefinition, i: number): string { + protected getIthValue(p: ParamDefinition, i: number, extendTo: number): string { let value: number; if (p.hasMultipleValues) { if (p.valueMode === ParamValueMode.CALCUL) { value = p.parentNub.result.resultElements[i].vCalc; } else { - value = p.getInferredValuesList()[i]; + value = p.getInferredValuesList(extendTo)[i]; } } else { value = p.V; @@ -81,9 +81,9 @@ export class PbResultsTableComponent extends ResultsComponentDirective { this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AMONT"), "", "", - this.getIthValue(pb.prms.Z1, vi), + this.getIthValue(pb.prms.Z1, vi, this._pbResults.size), "", "", - this.getIthValue(pb.prms.Q, vi), + this.getIthValue(pb.prms.Q, vi, this._pbResults.size), ]); } @@ -111,9 +111,9 @@ export class PbResultsTableComponent extends ResultsComponentDirective { this._dataSet.push([ this.intlService.localizeText("INFO_LIB_AVAL"), "", "", - this.getIthValue(pb.prms.Z2, vi), + this.getIthValue(pb.prms.Z2, vi, this._pbResults.size), "", "", - this.getIthValue(pb.prms.Q, vi), + this.getIthValue(pb.prms.Q, vi, 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 db8aa6d91..a4a603342 100644 --- a/src/app/components/pb-results/pb-results.component.html +++ b/src/app/components/pb-results/pb-results.component.html @@ -1,5 +1,4 @@ <div class="container"> - <log #generalLog [logTitle]="uitextGeneralLogTitle">log général</log> <variable-results-selector [results]="pbResults" (indexChange)="variableIndexChanged()"> @@ -8,7 +7,10 @@ <log #iterationLog></log> <!-- tableau de résultats des bassins --> - <pb-results-table *ngIf="showBasinsResults" [results]="pbResults"></pb-results-table> + <pb-results-table *ngIf="hasBasinResults" [results]="pbResults"></pb-results-table> + + <!-- table des résultats fixés --> + <fixed-results *ngIf="hasWallResults" [results]="pbResults.cloisonResults"></fixed-results> <!-- <quicknav *ngIf="hasDisplayableResults" [items]="[ 'input', 'results', 'charts' ]" [currentItem]="'charts'" [align]="'left'"></quicknav> --> diff --git a/src/app/components/pb-results/pb-results.component.ts b/src/app/components/pb-results/pb-results.component.ts index ed974c71b..6623a32ac 100644 --- a/src/app/components/pb-results/pb-results.component.ts +++ b/src/app/components/pb-results/pb-results.component.ts @@ -1,16 +1,16 @@ import { Component, ViewChild, DoCheck } from "@angular/core"; -import { Result, cLog, Message, MessageCode, MessageSeverity } from "jalhyd"; - import { LogComponent } from "../log/log.component"; import { CalculatorResults } from "../../results/calculator-results"; import { PbResultsTableComponent } from "./pb-results-table.component"; import { PrebarrageResults } from "../../results/prebarrage-results"; import { VariableResultsSelectorComponent } from "../variable-results-selector/variable-results-selector.component"; import { I18nService } from "../../services/internationalisation.service"; -import { PabProfileChartComponent } from "../pab-profile-chart/pab-profile-chart.component"; +import { FixedResultsComponent } from "../fixedvar-results/fixed-results.component"; import { FixedResults } from "../../results/fixed-results"; +import { Result } from "jalhyd"; + @Component({ selector: "pb-results", templateUrl: "./pb-results.component.html", @@ -32,6 +32,9 @@ export class PbResultsComponent implements DoCheck { @ViewChild(VariableResultsSelectorComponent) private variableResultsSelectorComponent: VariableResultsSelectorComponent; + @ViewChild(FixedResultsComponent) + private fixedResultsComponent: FixedResultsComponent; + @ViewChild("generalLog") private generalLogComponent: LogComponent; @@ -59,23 +62,19 @@ export class PbResultsComponent implements DoCheck { return this._pbResults; } + // true if any result is present public get hasResults(): boolean { return this._pbResults && this._pbResults.hasResults; } - public get showBasinsResults(): boolean { - let ret = this._pbResults && this._pbResults.hasResults; - if ( - this._pbResults - && this._pbResults.variatedParameters - && this._pbResults.variatedParameters.length > 0 - ) { - ret = ret - && this._pbResults.variableIndex !== undefined - && this._pbResults.result.resultElements[this._pbResults.variableIndex] !== undefined - && this._pbResults.result.resultElements[this._pbResults.variableIndex].ok; - } - return ret; + // true if basin results are present + public get hasBasinResults(): boolean { + return this._pbResults && this._pbResults.hasBasinResults; + } + + // true if wall results are present + public get hasWallResults(): boolean { + return this._pbResults && this._pbResults.hasWallResults; } /** @@ -100,6 +99,9 @@ export class PbResultsComponent implements DoCheck { if (this.variableResultsSelectorComponent) { this.variableResultsSelectorComponent.results = undefined; } + if (this.fixedResultsComponent) { + this.fixedResultsComponent.results = undefined; + } /* if (this.profileChartComponent) { this.profileChartComponent.results = undefined; } */ @@ -281,9 +283,10 @@ export class PbResultsComponent implements DoCheck { * @returns true si les résultats ont pu être mis à jour */ private updateResults() { - let pabUpdated: boolean; + let pbTableUpdated: boolean; let profileChartUpdated: boolean; let selectorUpdated: boolean; + let fixedResultsUpdated: boolean; // results or not, there might be a log const logUpdated = (this.iterationLogComponent !== undefined || this.generalLogComponent !== undefined); // gne ? @@ -293,27 +296,49 @@ export class PbResultsComponent implements DoCheck { this.generalLogComponent.log = this.globalLog; */ } + // show selector as long as any result is present if (this.hasResults) { - pabUpdated = this.pbResultsTableComponent !== undefined; - if (pabUpdated) { - this.pbResultsTableComponent.results = this._pbResults; - } selectorUpdated = this.variableResultsSelectorComponent !== undefined; if (selectorUpdated) { this.variableResultsSelectorComponent.results = this._pbResults; } + } else { + selectorUpdated = true; + } + if (this.hasBasinResults) { + pbTableUpdated = this.pbResultsTableComponent !== undefined; + if (pbTableUpdated) { + this.pbResultsTableComponent.results = this._pbResults; + } /* profileChartUpdated = this.profileChartComponent !== undefined; if (profileChartUpdated) { this.profileChartComponent.results = this._pbResults; this.profileChartComponent.updateView(); } */ } else { - pabUpdated = true; + pbTableUpdated = true; profileChartUpdated = true; - selectorUpdated = true; + } + if (this.hasWallResults) { + fixedResultsUpdated = this.fixedResultsComponent !== undefined; + if (fixedResultsUpdated) { + // trick to show only the result of a given iteration, without + // modifying FixedResultsComponent + const iterationResult = new FixedResults(); + for (const fp of this._pbResults.cloisonResults.fixedParameters) { + iterationResult.addFixedParameter(fp); + } + iterationResult.result = new Result( + this._pbResults.cloisonResults.result.resultElements[this._pbResults.variableIndex], + this._pbResults.cloisonResults.result.sourceNub + ); + this.fixedResultsComponent.results = iterationResult; + } + } else { + fixedResultsUpdated = true; } - return pabUpdated && logUpdated && profileChartUpdated && selectorUpdated; + return pbTableUpdated && logUpdated && profileChartUpdated && selectorUpdated && fixedResultsUpdated; } public get uitextGeneralLogTitle(): string { diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 63e6d00f4..735e7dea7 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -60,9 +60,6 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** Records existing walls as they are built, to detect if multiple walls connect the same pair of basins */ private existingWalls: { [key: string]: number }; - /** Stores appropriate number suffix for a given wall uid (related to existingWalls above) */ - private wallsSuffixes: { [key: string]: number }; - public constructor( @Inject(forwardRef(() => GenericCalculatorComponent)) private calculatorComponent: GenericCalculatorComponent, private i18nService: I18nService, @@ -144,7 +141,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni */ private graphDefinition() { this.existingWalls = {}; - this.wallsSuffixes = {}; + this.pbSchema.wallsSuffixes = {}; const def: string[] = [ "graph TB" ]; // river upstream / downstream @@ -159,7 +156,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni const sortedWalls: PbCloison[] = []; for (const c of this.model.children) { if (c instanceof PbBassin) { - def.push(`${c.uid}("${this.itemDesription(c)}")`); // rounded edges + def.push(`${c.uid}("${this.itemDescription(c)}")`); // rounded edges def.push(`class ${c.uid} basin;`); } else if (c instanceof PbCloison) { // store, to draw later @@ -178,11 +175,11 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } // affect suffix if needed if (this.existingWalls[basinsPair] > 0) { - this.wallsSuffixes[c.uid] = this.existingWalls[basinsPair]; + this.pbSchema.wallsSuffixes[c.uid] = this.existingWalls[basinsPair]; } this.existingWalls[basinsPair]++; // draw wall Node - def.push(`${c.uid}["${this.itemDesription(c)}"]`); // square edges + def.push(`${c.uid}["${this.itemDescription(c)}"]`); // square edges def.push(`class ${c.uid} wall;`); // draw "arrow" with 2 lines def.push(`${upstreamBasinId}---${c.uid}-->${downstreamBasinId}`); @@ -259,7 +256,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } public get prefixedItemDescription(): string { - let desc = this.itemDesription(this._selectedItem); + let desc = this.itemDescription(this._selectedItem); if (this._selectedItem instanceof PbCloison) { desc = this.i18nService.localizeText("INFO_PB_CLOISON") + " " + desc; } @@ -270,23 +267,17 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } /** Returns a short description of the given item: wall or basin */ - private itemDesription(item: PbCloison | PbBassin): string { + private itemDescription(item: PbCloison | PbBassin): string { let desc = ""; - if (item instanceof PbCloison) { - const upstreamBasinName = item.bassinAmont === undefined - ? this.i18nService.localizeText("INFO_LIB_AMONT") - : "B" + (this.model.findBasinPosition(item.bassinAmont.uid) + 1); - const downstreamBasinName = item.bassinAval === undefined - ? this.i18nService.localizeText("INFO_LIB_AVAL") - : "B" + (this.model.findBasinPosition(item.bassinAval.uid) + 1); - desc = upstreamBasinName + "-" + downstreamBasinName; - // if a similar wall already exists, suffix ! - if (item.uid in this.wallsSuffixes) { - desc += " (" + this.wallsSuffixes[item.uid] + ")"; + if (item !== undefined) { + desc = this.i18nService.localizeMessage(item.description); + if (item instanceof PbCloison) { + // there might be multiple walls between the same pair of basins + if (item.uid in this.pbSchema.wallsSuffixes) { + desc += " (" + this.pbSchema.wallsSuffixes[item.uid] + ")"; + } } - } else if (item instanceof PbBassin) { - desc = this.i18nService.localizeText("INFO_PB_BASSIN_N") + (this.model.findBasinPosition(item.uid) + 1); - } // else undefined + } return 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 af8dfe927..ff36f82b1 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,8 +1,11 @@ import { Component, Output, EventEmitter } from "@angular/core"; import { I18nService } from "../../services/internationalisation.service"; -import { fv, longestVarNgParam } from "../../util"; +import { fv, longestVarParam } from "../../util"; import { MultiDimensionResults } from "../../results/multidimension-results"; +import { PrebarrageResults } from "../../results/prebarrage-results"; + +import { CalculatorType, PbCloison, Structure } from "jalhyd"; @Component({ selector: "variable-results-selector", @@ -40,12 +43,12 @@ export class VariableResultsSelectorComponent { // pre-extract variable parameters values this.varValues = []; // find longest list - const lvp = longestVarNgParam(this._results.variatedParameters); + const lvp = longestVarParam(this._results.variatedParameters); this.size = lvp.size; // get extended values lists for each variable parameter for (const v of this._results.variatedParameters) { const vv = []; - const iter = v.getExtendedValuesIterator(this.size); + const iter = v.param.getExtendedValuesIterator(this.size); while (iter.hasNext) { const nv = iter.next(); vv.push(fv(nv.value)); @@ -76,14 +79,33 @@ export class VariableResultsSelectorComponent { for (let i = 0; i < this.varValues.length; i++) { const vv = this.varValues[i]; const vp = this._results.variatedParameters[i]; - let symbol = vp.symbol; + let symbol = vp.param.symbol; // is vp a parameter of a child Nub ? if ( - vp.paramDefinition.parentNub - && vp.paramDefinition.parentNub !== vp.paramDefinition.originNub + vp.param.parentNub + && vp.param.parentNub !== vp.param.originNub ) { - const pos = vp.paramDefinition.parentNub.findPositionInParent() + 1; - symbol = this.intlService.localizeText("INFO_LIB_RADIER_N_COURT") + pos + "_" + symbol; + let childPrefix: string; + // prefix the label depending on (grand)children type + switch (vp.param.originNub.calcType) { + case CalculatorType.PreBarrage: + const struct = vp.param.parentNub as Structure; + const pbRes = this._results as PrebarrageResults; + const wall = struct.parent as PbCloison; + const posS = struct.findPositionInParent() + 1; + childPrefix = this.intlService.localizeMessage(wall.description); + // there might be multiple walls between the same pair of basins + if (wall.uid in pbRes.wallsSuffixes) { + childPrefix += " (" + pbRes.wallsSuffixes[wall.uid] + ")"; + } + childPrefix += "_" + this.intlService.localizeText("INFO_LIB_STRUCTURE_N_COURT") + posS; + break; + case CalculatorType.MacroRugoCompound: + const posMR = vp.param.parentNub.findPositionInParent() + 1; + childPrefix = this.intlService.localizeText("INFO_LIB_RADIER_N_COURT") + posMR; + break; + } + symbol = childPrefix + "_" + symbol; } kv.push(`${symbol} = ${vv[index]}`); } diff --git a/src/app/formulaire/definition/form-courbe-remous.ts b/src/app/formulaire/definition/form-courbe-remous.ts index 844a2c2c8..304fef0ba 100644 --- a/src/app/formulaire/definition/form-courbe-remous.ts +++ b/src/app/formulaire/definition/form-courbe-remous.ts @@ -15,7 +15,7 @@ export class FormulaireCourbeRemous extends FormulaireSection { constructor() { super(); - this._remousResults = new RemousResults(); + this._remousResults = new RemousResults(this); this._props["varCalc"] = ""; // important } diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index f77f1d6d0..424c4cf41 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -8,7 +8,8 @@ import { SectionNub, acSection, ParamDefinition, - Result + Result, + VariatedDetails } from "jalhyd"; import { FormulaireElement } from "../elements/formulaire-element"; @@ -517,18 +518,9 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs return ngparam; } - public getVariatedParameters(): NgParameter[] { - let res: NgParameter[] = []; - // find variated local parameters - res = this.getDisplayedParamListFromState(ParamRadioConfig.VAR); - // add variated linked parameters - const pms = this.getDisplayedParamListFromState(ParamRadioConfig.LINK); - for (const p of pms) { - if (p.paramDefinition.hasMultipleValues) { - res.push(p); - } - } - return res; + /** find variated (possibly linked) parameters from model, and get their values at the same time */ + public getVariatedParameters(): VariatedDetails[] { + return this._currentNub.findVariatedParams(); } /** diff --git a/src/app/formulaire/definition/form-fixedvar.ts b/src/app/formulaire/definition/form-fixedvar.ts index b376cfa7c..a23e5a623 100644 --- a/src/app/formulaire/definition/form-fixedvar.ts +++ b/src/app/formulaire/definition/form-fixedvar.ts @@ -7,8 +7,8 @@ import { ParamRadioConfig, NgParameter } from "../elements/ngparam"; import { FieldSet } from "../elements/fieldset"; import { FormulaireNode } from "../elements/formulaire-node"; -import { Nub, IObservable } from "jalhyd"; import { SelectFieldCustom } from "../elements/select-field-custom"; +import { Nub, IObservable, VariatedDetails } from "jalhyd"; export class FormulaireFixedVar extends FormulaireDefinition { @@ -24,7 +24,7 @@ export class FormulaireFixedVar extends FormulaireDefinition { constructor(parent?: FormulaireNode) { super(parent); this._fixedResults = new FixedResults(); - this._varResults = new VarResults(); + this._varResults = new VarResults(this); } public get fixedResults() { @@ -122,7 +122,7 @@ export class FormulaireFixedVar extends FormulaireDefinition { const computedParam: NgParameter = this.getComputedParameter(); this.resetFormResults(); // to avoid adding fixed parameters more than once (see below) this.addFixedParameters(); - const varParams: NgParameter[] = this.getVariatedParameters(); + const varParams: VariatedDetails[] = this.getVariatedParameters(); if (varParams.length === 0) { // pas de paramètre à varier diff --git a/src/app/formulaire/definition/form-macrorugo-compound.ts b/src/app/formulaire/definition/form-macrorugo-compound.ts index f04e6ccfe..a8cbc7ac6 100644 --- a/src/app/formulaire/definition/form-macrorugo-compound.ts +++ b/src/app/formulaire/definition/form-macrorugo-compound.ts @@ -1,4 +1,4 @@ -import { IObservable, Nub, MacrorugoCompound, Result, MRCInclination } from "jalhyd"; +import { IObservable, Nub, MacrorugoCompound, Result, MRCInclination, VariatedDetails } from "jalhyd"; import { FieldSet } from "../elements/fieldset"; import { FieldsetContainer } from "../elements/fieldset-container"; @@ -116,7 +116,7 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset { protected reaffectResultComponents() { const mrc: MacrorugoCompound = (this.currentNub as MacrorugoCompound); const computedParam: NgParameter = this.getComputedParameter(); - const varParams: NgParameter[] = this.getVariatedParameters(); + const varParams: VariatedDetails[] = this.getVariatedParameters(); // résultat de calcul de la passe à macrorugo complexe const mrcr = this.mrcResults; diff --git a/src/app/formulaire/definition/form-pab.ts b/src/app/formulaire/definition/form-pab.ts index 593aa219a..d88ae7826 100644 --- a/src/app/formulaire/definition/form-pab.ts +++ b/src/app/formulaire/definition/form-pab.ts @@ -1,9 +1,9 @@ -import { Pab, Result } from "jalhyd"; +import { Pab, Result, VariatedDetails } from "jalhyd"; import { FormulaireDefinition } from "./form-definition"; import { PabResults } from "../../results/pab-results"; import { NgParameter } from "../elements/ngparam"; -import { longestVarNgParam } from "../../util"; +import { longestVarParam } from "../../util"; import { CalculatorResults } from "../../results/calculator-results"; /** @@ -35,7 +35,7 @@ export class FormulairePab extends FormulaireDefinition { protected reaffectResultComponents() { const pab: Pab = (this.currentNub as Pab); const computedParam: NgParameter = this.getComputedParameter(); - const varParams: NgParameter[] = this.getVariatedParameters(); + const varParams: VariatedDetails[] = this.getVariatedParameters(); // résultat de calcul de la passe à bassins const pabr = this.pabResults; @@ -55,7 +55,7 @@ export class FormulairePab extends FormulaireDefinition { pabr.Z2 = []; if (varParams.length > 0) { // find longest list - const lvp = longestVarNgParam(varParams); + const lvp = longestVarParam(varParams); const longest = lvp.size; // get extended values lists for Z2 if (pab.prms.Z2.hasMultipleValues) { diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index a3dcb71e8..43f7900af 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -1,4 +1,4 @@ -import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage } from "jalhyd"; +import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage, VariatedDetails, ParamDefinition, ParamDomainValue } from "jalhyd"; import { FormulaireFixedVar } from "./form-fixedvar"; import { PbSchema } from "../elements/pb-schema"; @@ -8,7 +8,8 @@ import { FormulairePbCloison } from "./form-pb-cloison"; import { FieldsetContainer } from "../elements/fieldset-container"; import { CalculatorResults } from "../../results/calculator-results"; import { PrebarrageResults } from "../../results/prebarrage-results"; -import { NgParameter } from "../elements/ngparam"; +import { NgParameter, ParamRadioConfig } from "../elements/ngparam"; +import { longestVarParam } from "../../util"; /** * Formulaire pour les PréBarrage @@ -50,7 +51,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { public get results(): CalculatorResults[] { // ensure help links are propagated this._pbResults.helpLinks = this.helpLinks; - return [ this.fixedResults, this._pbResults ]; + return [ this._pbResults ]; } public get hasResults(): boolean { @@ -191,7 +192,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar { public update(sender: IObservable, data: any) { super.update(sender, data); if (sender instanceof FormulairePbCloison) { - // console.log("HOH PUTAIN CE BIG QUATTRO HOYOYOYOYOY", this.kids[0].constructor.name); if (data.action === "updateBasin") { this.refreshSchema(data.value); } @@ -202,8 +202,8 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.runNubCalc(this.currentNub); this.refreshFieldsets(); // important: before reaffectResultComponents() or it will break results components localization // reset variable index to avoid trying to access an index > 0 when nothing varies - const pabr = this.pbResults; - pabr.variableIndex = 0; + const pbr = this.pbResults; + pbr.variableIndex = 0; this.reaffectResultComponents(); } @@ -211,30 +211,52 @@ export class FormulairePrebarrage extends FormulaireFixedVar { protected reaffectResultComponents() { const pb: PreBarrage = (this.currentNub as PreBarrage); const computedParam: NgParameter = this.getComputedParameter(); - const varParams: NgParameter[] = this.getVariatedParameters(); + + // cacher les résultats + this.pbResults.reset(); + this.addFixedParameters(); // pour le sélecteur d'itérations + const varParams: VariatedDetails[] = this.getVariatedParameters(); if (varParams) { this.pbResults.variatedParameters = varParams; + const lvp = longestVarParam(this._pbResults.variatedParameters); + this._pbResults.size = lvp.size; } - // cacher les résultats de la cloison - this.fixedResults.reset(); - this.addFixedParameters(); - // résultats selon l'objet sélectionné sur le schéma if (this._selectedItem !== undefined && this._selectedItem instanceof PbCloison) { - // cacher les résultats de bassins - this.pbResults.reset(); - // afficher les résultats de cloison - this.fixedResults.result = this._selectedItem.result; + this.pbResults.cloisonResults.result = this._selectedItem.result; if (computedParam !== undefined) { - this.fixedResults.calculatedParameter = computedParam; + this.pbResults.cloisonResults.calculatedParameter = computedParam; } + // transmission des suffixes de cloisons calculés par l'algo de tri de PbSchemaComponent, + // pour le sélecteur de conditions limites + const pbs = this.kids[0] as PbSchema; + this.pbResults.wallsSuffixes = pbs.wallsSuffixes; + // astuce clodo : si un paramètre d'un ouvrage de cette cloison varie, on + // l'ajoute sous forme de faux paramètre fixe + /* for (const s of this._selectedItem.structures) { + for (const p of s.parameterIterator) { + if (p.hasMultipleValues) { + this._pbResults.cloisonResults.addFixedParameter( + new NgParameter( + new ParamDefinition( + undefined, + p.symbol, + ParamDomainValue.ANY, + p.unit, + p.getInferredValuesList(this.pbResults.size)[this.pbResults.variableIndex] + ), + this + ) + ); + } + } + } */ } else { // afficher les résultats des bassins - this.pbResults.reset(); // résultat général du Nub (amont, aval, débit) this.pbResults.result = pb.result; this.pbResults.calculatedParameter = computedParam; @@ -245,16 +267,20 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } } - /** - * réinitialisation du formulaire suite à un changement d'une valeur, d'une option, ... : - * effacement des résultats, application des dépendances, ... - */ - /* public reset() { - this.resetResults(); - } */ + public addFixedParameters() { + // @TODO lire dans le modèle ! + for (const p of this.getDisplayedParamListFromState(ParamRadioConfig.FIX)) { + this._pbResults.cloisonResults.addFixedParameter(p); + } + + for (const p of this.getDisplayedParamListFromState(ParamRadioConfig.LINK)) { + if (!p.paramDefinition.hasMultipleValues) { + this._pbResults.cloisonResults.addFixedParameter(p); + } + } + } public resetFormResults() { - this._fixedResults.reset(); this._pbResults.reset(); } diff --git a/src/app/formulaire/definition/form-section-parametree.ts b/src/app/formulaire/definition/form-section-parametree.ts index f4d2319fd..b1d6dcf4a 100644 --- a/src/app/formulaire/definition/form-section-parametree.ts +++ b/src/app/formulaire/definition/form-section-parametree.ts @@ -32,7 +32,7 @@ export class FormulaireSectionParametree extends FormulaireSection { const sect: acSection = sectNub.section; this._sectionResults.section = sect; - const varParams = this.getSectionVariatedParameters(); + const varParams = this.getVariatedParameters(); if (varParams.length > 0) { // résultats variés avec tous les résultats complémentaires this._varResults.variatedParameters = varParams; @@ -71,8 +71,4 @@ export class FormulaireSectionParametree extends FormulaireSection { res.push(this._sectionResults); return res; } - - public getSectionVariatedParameters(): NgParameter[] { - return this.getDisplayedParamListFromState(ParamRadioConfig.VAR); - } } diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index 967680825..7943071ed 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -319,10 +319,6 @@ export class NgParameter extends InputField implements Observer { } } - public getExtendedValuesIterator(size: number): INumberIterator { - return this._paramDef.getExtendedValuesIterator(size); - } - /** * notification envoyée après la modification de la valeur du paramètre */ diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index 7ec01a39c..278b7fe39 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -11,6 +11,9 @@ import { FormulairePrebarrage } from "../definition/form-prebarrage"; */ export class PbSchema extends FormulaireElement { + /** Stores appropriate number suffix for a given wall uid (related to existingWalls above) */ + public wallsSuffixes: { [key: string]: number }; + public parseConfig(json: {}) { this._confId = json["id"]; } diff --git a/src/app/results/multidimension-results.ts b/src/app/results/multidimension-results.ts index 4b2aee2ed..c3669acfd 100644 --- a/src/app/results/multidimension-results.ts +++ b/src/app/results/multidimension-results.ts @@ -1,11 +1,12 @@ import { CalculatedParamResults } from "./param-calc-results"; -import { NgParameter } from "../formulaire/elements/ngparam"; + +import { VariatedDetails } from "jalhyd"; export class MultiDimensionResults extends CalculatedParamResults { /** paramètres variés */ - public variatedParameters: NgParameter[]; + public variatedParameters: VariatedDetails[]; /** index de la valeur du paramètre varié à afficher dans les résultats */ public variableIndex = 0; diff --git a/src/app/results/plottable-data.ts b/src/app/results/plottable-data.ts index 35da1e4d9..bae4f7709 100644 --- a/src/app/results/plottable-data.ts +++ b/src/app/results/plottable-data.ts @@ -1,5 +1,7 @@ import { ChartType } from "./chart-type"; +import { ParamDefinition } from "jalhyd"; + /** * Une interface pour nourrir un ResultsChartComponent */ @@ -20,7 +22,7 @@ export interface PlottableData { * Returns the translated name of the given symbol (usually a result or child result) * if available, with its unit, but without the symbol itself */ - expandLabelFromSymbol(symbol: string): string; + expandLabelFromSymbol(p: ParamDefinition): string; /** * Returns a list of plottable parameters / result elements, that can be defined diff --git a/src/app/results/plottable-macrorugo-compound-results.ts b/src/app/results/plottable-macrorugo-compound-results.ts index 82601908c..caf34a119 100644 --- a/src/app/results/plottable-macrorugo-compound-results.ts +++ b/src/app/results/plottable-macrorugo-compound-results.ts @@ -2,6 +2,8 @@ import { PlottableData } from "./plottable-data"; import { ChartType } from "./chart-type"; import { MacrorugoCompoundResults } from "./macrorugo-compound-results"; +import { ParamDefinition } from "jalhyd"; + export class PlottableMacrorugoCompoundResults implements PlottableData { public graphType: ChartType = ChartType.Scatter; @@ -32,8 +34,8 @@ export class PlottableMacrorugoCompoundResults implements PlottableData { return this.mrcResults.headers[this.mrcResults.columns.indexOf(symbol)]; } - public expandLabelFromSymbol(symbol: string): string { - return symbol; + public expandLabelFromSymbol(p: ParamDefinition): string { + return p.symbol; } /** diff --git a/src/app/results/plottable-pab-results.ts b/src/app/results/plottable-pab-results.ts index 0d45afb05..56ee01671 100644 --- a/src/app/results/plottable-pab-results.ts +++ b/src/app/results/plottable-pab-results.ts @@ -3,6 +3,8 @@ import { PabResults } from "./pab-results"; import { ChartType } from "./chart-type"; import { ServiceFactory } from "../services/service-factory"; +import { ParamDefinition } from "jalhyd"; + export class PlottablePabResults implements PlottableData { public graphType: ChartType = ChartType.Scatter; @@ -37,8 +39,8 @@ export class PlottablePabResults implements PlottableData { } } - public expandLabelFromSymbol(symbol: string): string { - return symbol; + public expandLabelFromSymbol(p: ParamDefinition): string { + return p.symbol; } /** diff --git a/src/app/results/prebarrage-results.ts b/src/app/results/prebarrage-results.ts index cea988714..fb92d9fb6 100644 --- a/src/app/results/prebarrage-results.ts +++ b/src/app/results/prebarrage-results.ts @@ -2,18 +2,29 @@ import { Result } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; import { MultiDimensionResults } from "./multidimension-results"; +import { FixedResults } from "./fixed-results"; export class PrebarrageResults extends MultiDimensionResults { /** résultats des bassins, dans l'ordre */ public bassinsResults: Result[]; + /** résultat de la cloison actuellement sélectionnée (nourrit le FixedResultsComponent) */ + public cloisonResults: FixedResults; + /** symboles des colonnes de résultat */ protected _columns: string[]; + /** size of the longest variating parameter */ + public size: number; + + /** Stores appropriate number suffix for a given wall uid (copied from PbSchema) */ + public wallsSuffixes: { [key: string]: number }; + public constructor() { super(); this.reset(); + this.size = 1; // boulette-proufe // standard headers this._columns = [ "BASSIN", @@ -49,6 +60,7 @@ export class PrebarrageResults extends MultiDimensionResults { public reset() { super.reset(); this.bassinsResults = []; + this.cloisonResults = new FixedResults(); this.result = undefined; } @@ -64,19 +76,26 @@ export class PrebarrageResults extends MultiDimensionResults { } } } - return (this.result && this.result.hasLog()); + return (this.cloisonResults && this.cloisonResults.result && this.cloisonResults.result.hasLog()); } - // do not test result.ok else log messages will prevent partial results from being displayed public get hasResults(): boolean { - return this.result !== undefined && ! this.result.hasOnlyErrors; + return this.hasBasinResults || this.hasWallResults; + } + + public get hasBasinResults(): boolean { + return this.bassinsResults.length > 0 && this.bassinsResults[0] && ! this.bassinsResults[0].hasOnlyErrors; + } + + public get hasWallResults(): boolean { + return this.cloisonResults && this.cloisonResults.result && ! this.cloisonResults.result.hasOnlyErrors; } /** retourne true si au moins un calcul a échoué (le log a un code négatif) */ public hasError(): boolean { let err = false; // log principal - err = (err || this.result.hasErrorMessages()); + err = (err || (this.cloisonResults && this.cloisonResults && this.cloisonResults.result.hasErrorMessages())); // logs des bassins for (const c of this.bassinsResults) { err = (err || c.hasErrorMessages()); @@ -87,7 +106,7 @@ export class PrebarrageResults extends MultiDimensionResults { /** retourne true si le calcul à l'itération i a échoué */ public iterationHasError(i: number): boolean { - let err = this.result.resultElements[i].hasErrorMessages(); + let err = this.cloisonResults && this.cloisonResults.result && this.cloisonResults.result.resultElements[i].hasErrorMessages(); // logs des bassins for (const c of this.bassinsResults) { err = (err || c.resultElements[i].hasErrorMessages()); @@ -100,7 +119,7 @@ export class PrebarrageResults extends MultiDimensionResults { public hasOnlyErrors(): boolean { let err = true; // log principal - err = (err && this.result.hasOnlyErrors); + err = (err && this.cloisonResults && this.cloisonResults.result && this.cloisonResults.result.hasOnlyErrors); // logs des bassins for (const c of this.bassinsResults) { err = (err && c.hasOnlyErrors); diff --git a/src/app/results/remous-results.ts b/src/app/results/remous-results.ts index c6c9e3b8a..dedfd9a6f 100644 --- a/src/app/results/remous-results.ts +++ b/src/app/results/remous-results.ts @@ -2,8 +2,8 @@ import { cLog, CourbeRemousParams, Result, ResultElement, ParamDefinition, Param import { CalculatorResults } from "./calculator-results"; import { VarResults } from "./var-results"; -import { NgParameter } from "../formulaire/elements/ngparam"; import { ServiceFactory } from "../services/service-factory"; +import { FormulaireDefinition } from "../formulaire/definition/form-definition"; export class RemousResults extends CalculatorResults { @@ -51,8 +51,12 @@ export class RemousResults extends CalculatorResults { /** journal de calcul */ private _log: cLog; - constructor() { + /** pointer to form that instantiated this object */ + protected _form: FormulaireDefinition; + + constructor(form?: FormulaireDefinition) { super(); + this._form = form; this.reset(); } @@ -132,8 +136,8 @@ export class RemousResults extends CalculatorResults { this._log.clear(); this._log.addLog(this._result.globalLog); - this._varResults = new VarResults(); - this._varResults.variatedParameters = [ new NgParameter(this._xValues, undefined) ]; + this._varResults = new VarResults(this._form); + this._varResults.variatedParameters = [ { param: this._xValues, values: this._xValues.paramValues } ]; this._varResults.result = this._result; const keys = []; keys.push("Y"); // ligne d'eau diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts index 6e73b5d03..918d70845 100644 --- a/src/app/results/var-results.ts +++ b/src/app/results/var-results.ts @@ -1,20 +1,19 @@ -import { CalculatorResults } from "./calculator-results"; import { CalculatedParamResults } from "./param-calc-results"; -import { NgParameter } from "../formulaire/elements/ngparam"; -import { ResultElement, ParamFamily, capitalize, Nub } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; import { PlottableData } from "./plottable-data"; import { ChartType } from "./chart-type"; +import { longestVarParam } from "../util"; +import { FormulaireDefinition } from "../formulaire/definition/form-definition"; import { sprintf } from "sprintf-js"; -import { longestVarNgParam } from "../util"; +import { ResultElement, ParamFamily, capitalize, Nub, VariatedDetails, ParamDefinition, ParamDomain, ParamDomainValue } from "jalhyd"; export class VarResults extends CalculatedParamResults implements PlottableData { /** * paramètres variés */ - private _variatedParams: NgParameter[]; + private _variatedParams: VariatedDetails[]; /** * titre des colonnes des résultats variés @@ -36,6 +35,9 @@ export class VarResults extends CalculatedParamResults implements PlottableData */ protected _graphType: ChartType = ChartType.Scatter; + /** pointer to form that instantiated this object */ + protected _form: FormulaireDefinition; + /** * variated parameter or result displayed as chart's X-axis */ @@ -56,8 +58,9 @@ export class VarResults extends CalculatedParamResults implements PlottableData */ private _yValues: number[] = []; - constructor() { + constructor(form?: FormulaireDefinition) { super(); + this._form = form; this.reset(); } @@ -70,11 +73,11 @@ export class VarResults extends CalculatedParamResults implements PlottableData this.longest = 0; } - public get variatedParameters(): NgParameter[] { + public get variatedParameters(): VariatedDetails[] { return this._variatedParams; } - public set variatedParameters(p: NgParameter[]) { + public set variatedParameters(p: VariatedDetails[]) { this._variatedParams = p; } @@ -110,19 +113,19 @@ export class VarResults extends CalculatedParamResults implements PlottableData } // 2. variated param ? for (let i = 0; i < this.variatedParameters.length; i++) { - if (this._variatedParams[i].symbol === symbol) { + if (this._variatedParams[i].param.symbol === symbol) { return this.variableParamHeaders[i]; } } // 3. Result element / child result - return this.expandLabelFromSymbol(symbol); + return this.expandLabelFromSymbol(new ParamDefinition(undefined, symbol, ParamDomainValue.ANY)); } /** * Returns the translated name of the given symbol (usually a result or child result) with * its unit, but without the symbol itself */ - public expandLabelFromSymbol(symbol: string): string { + public expandLabelFromSymbol(p: ParamDefinition): string { let ret = ""; // calculator type for translation const sn = this.result.sourceNub; @@ -131,7 +134,8 @@ export class VarResults extends CalculatedParamResults implements PlottableData ct = sn.parent.calcType; } // detect children results - const match = /^([0-9]+)_(.+)$/.exec(symbol); + const match = /^([0-9]+)_(.+)$/.exec(p.symbol); + let symbol = p.symbol; if (match !== null) { const pos = +match[1]; // only parent translation file is loaded; look for children translations in it // ct = sn.getChildren()[pos].calcType; @@ -160,16 +164,16 @@ export class VarResults extends CalculatedParamResults implements PlottableData // are we looking for a child variated param ? if (isChildResult !== null) { const children = this.result.sourceNub.getChildren(); - const parameterNub = vp.paramDefinition.parentNub; + const parameterNub = vp.param.parentNub; if (children.includes(parameterNub)) { // current var param is a child param ! const pos = parameterNub.findPositionInParent(); - isTheGoodChild = (pos === +isChildResult[1] && vp.symbol === isChildResult[2]); + isTheGoodChild = (pos === +isChildResult[1] && vp.param.symbol === isChildResult[2]); } } // in any case - if (isTheGoodChild || vp.symbol === symbol) { + if (isTheGoodChild || vp.param.symbol === symbol) { found = true; - const iter = vp.getExtendedValuesIterator(this.size); + const iter = vp.param.getExtendedValuesIterator(this.size); for (const v of iter) { series.push(v); } @@ -259,13 +263,13 @@ export class VarResults extends CalculatedParamResults implements PlottableData // variating parameters for (const v of this._variatedParams) { // exclude pseudo-family "ANY" - const fam = v.paramDefinition.family; + const fam = v.param.family; if (fam !== undefined && fam !== ParamFamily.ANY) { const f = ParamFamily[fam]; if (! (f in families)) { families[f] = []; } - families[f].push(v.symbol); + families[f].push(v.param.symbol); } } // results @@ -309,15 +313,15 @@ export class VarResults extends CalculatedParamResults implements PlottableData */ public getVariatingParametersSymbols(): string[] { if (this.result && this.result.sourceNub) { - return this._variatedParams.map(vp => this.getVariatingParameterSymbol(vp, this.result.sourceNub)); + return this._variatedParams.map(vp => this.getVariatingParameterSymbol(vp.param, this.result.sourceNub)); } else { return []; } } - public getVariatingParameterSymbol(vp: NgParameter, sourceNub: Nub): string { + public getVariatingParameterSymbol(vp: ParamDefinition, sourceNub: Nub): string { // detect if variated param is a children param - const parameterNub = vp.paramDefinition.parentNub; + const parameterNub = vp.parentNub; const children = sourceNub.getChildren(); let symb = vp.symbol; if (children.includes(parameterNub)) { @@ -329,13 +333,13 @@ export class VarResults extends CalculatedParamResults implements PlottableData public update() { // refresh param headers this._variableParamHeaders = this._variatedParams.map((v) => { - let h = CalculatorResults.paramLabel(v, true, this.result.sourceNub); - h += this.getHelpLink(v.symbol); + let h = this.expandLabelFromSymbol(v.param); + h += this.getHelpLink(v.param.symbol); return h; }); // liste la plus longue - const lvp = longestVarNgParam(this._variatedParams); + const lvp = longestVarParam(this._variatedParams); this.size = lvp.size; this.longest = lvp.index; @@ -358,7 +362,7 @@ export class VarResults extends CalculatedParamResults implements PlottableData } this.chartY = defaultY; if (this.chartX === undefined || ! this.getAvailableXAxis().includes(this.chartX)) { - this.chartX = this.getVariatingParameterSymbol(this.variatedParameters[this.longest], this.result.sourceNub); + this.chartX = this.getVariatingParameterSymbol(this.variatedParameters[this.longest].param, this.result.sourceNub); } // calculator type for translation @@ -405,10 +409,10 @@ export class VarResults extends CalculatedParamResults implements PlottableData */ public resetDefaultAxisIfNeeded() { if (! this.getAvailableXAxis().includes(this.chartX)) { - this.chartX = this.variatedParameters[0].symbol; + this.chartX = this.variatedParameters[0].param.symbol; } if (! this.getAvailableYAxis().includes(this.chartY)) { - this.chartY = this.variatedParameters[0].symbol; + this.chartY = this.variatedParameters[0].param.symbol; } } } diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index ccd973610..7b494b9dd 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -203,7 +203,9 @@ export class FormulaireService extends Observable { if (idx !== -1) { symbolBase = symbolBase.substring(idx + 2); } - let unit; + let unit: string; + // unit of a parameter is supposed to be read from JaLHyd ParadDefinition and passed + // through "forceUnit"; keys like "UNIT_*" in the config file are for extra results if (forceUnit) { unit = forceUnit; } else { diff --git a/src/app/services/internationalisation.service.ts b/src/app/services/internationalisation.service.ts index 4d1dabf05..683f84565 100644 --- a/src/app/services/internationalisation.service.ts +++ b/src/app/services/internationalisation.service.ts @@ -240,7 +240,7 @@ export class I18nService extends Observable implements Observer { // replace MSG_* with the translation of * ; allows // to inject any text translation in a message - m = m.replace(/MSG_([^ ,;\.]+)/g, (match, p1) => { + m = m.replace(/MSG_([^ ,;\.-]+)/g, (match, p1) => { return this.localizeText(p1); }); @@ -305,13 +305,17 @@ export class I18nService extends Observable implements Observer { } /** - * Returns the localized name for the children type of the current Nub + * Returns the localized name for the children type of the current Nub; "short" and "plural" + * options are mutually exclusive * @param plural if true, will return plural name + * @param short if true, will return short name */ - public childName(nub: Nub, plural: boolean = false) { + public childName(nub: Nub, plural: boolean = false, short: boolean = false) { const type: string = nub.childrenType; let k = "INFO_CHILD_TYPE_" + type.toUpperCase(); - if (plural) { + if (short) { + k += "_SHORT"; + } else if (plural) { k += "_PLUR"; } return this.localizeText(k); diff --git a/src/app/util.ts b/src/app/util.ts index 48b0981cc..ecb8604a8 100644 --- a/src/app/util.ts +++ b/src/app/util.ts @@ -42,27 +42,6 @@ export function decodeHtml(html: string): string { return txt.value; } -/** - * Given a list of variated NgParameter, returns the parameter having the most - * values, its index in the list, and the number of values it contains - * @param varParams - */ -export function longestVarNgParam(varParams: NgParameter[]): { param: NgParameter, index: number, size: number } { - const variated: VariatedDetails[] = []; - for (const vp of varParams) { - variated.push({ - param: vp.paramDefinition, - values: vp.paramDefinition.paramValues - }); - } - const { param, index, size } = longestVarParam(variated); - return { - param: varParams[index], - index, - size - }; -} - /** * Given a list of variated ParamDefinition, returns the parameter having the most * values, its index in the list, and the number of values it contains diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index c2c32a603..8e52e8a9f 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -207,10 +207,13 @@ "INFO_CHILD_TYPE_CLOISON_PLUR": "walls", "INFO_CHILD_TYPE_OUVRAGE": "device", "INFO_CHILD_TYPE_OUVRAGE_PLUR": "devices", + "INFO_CHILD_TYPE_OUVRAGE_SHORT": "D", "INFO_CHILD_TYPE_MACRORUGO": "apron", "INFO_CHILD_TYPE_MACRORUGO_PLUR": "aprons", + "INFO_CHILD_TYPE_MACRORUGO_SHORT": "A", "INFO_CHILD_TYPE_PUISSANCE": "power", "INFO_CHILD_TYPE_PUISSANCE_PLUR": "powers", + "INFO_CHILD_TYPE_PUISSANCE_SHORT": "P", "INFO_DIALOG_PARSIM_DESC": "Choose a combination of values to generate the simulation", "INFO_FIELDSET_ADD": "Add", "INFO_FIELDSET_COPY": "Copy", @@ -517,6 +520,8 @@ "INFO_PARAMFIELD_VARIATED": "Variated", "INFO_PARAMMODE_LIST": "Values list", "INFO_PARAMMODE_MINMAX": "Min/max", + "INFO_PB_BASSIN_DESCRIPTION": "B%order%", + "INFO_PB_CLOISON_DESCRIPTION": "%ub%-%db%", "INFO_PB_ADD_BASIN": "Add new basin", "INFO_PB_ADD_WALL": "Add new wall", "INFO_PB_BASSIN_N": "Basin #", @@ -543,7 +548,7 @@ "INFO_REMOUS_LARGEUR_BERGE": "Width at embankment level = %B% m", "INFO_REMOUS_RESSAUT_DEHORS": "Hydraulic jump detected %sens% abscissa %x% m", "INFO_REMOUS_RESSAUT_HYDRO": "Hydraulic jump detected between abscissa %xmin% and %xmax% m", - "INFO_REMOUSRESULTS_ABSCISSE": "Abscissa (m)", + "INFO_REMOUSRESULTS_ABSCISSE": "Abscissa", "INFO_REMOUSRESULTS_BERGE": "Embankment", "INFO_REMOUSRESULTS_FOND": "Bottom", "INFO_REMOUSRESULTS_TIRANT": "Draft (m)", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 1dd7eb5cd..b15fb7935 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -207,10 +207,13 @@ "INFO_CHILD_TYPE_CLOISON_PLUR": "cloisons", "INFO_CHILD_TYPE_OUVRAGE": "ouvrage", "INFO_CHILD_TYPE_OUVRAGE_PLUR": "ouvrages", + "INFO_CHILD_TYPE_OUVRAGE_SHORT": "O", "INFO_CHILD_TYPE_MACRORUGO": "radier", "INFO_CHILD_TYPE_MACRORUGO_PLUR": "radiers", + "INFO_CHILD_TYPE_MACRORUGO_SHORT": "R", "INFO_CHILD_TYPE_PUISSANCE": "puissance", "INFO_CHILD_TYPE_PUISSANCE_PLUR": "puissances", + "INFO_CHILD_TYPE_PUISSANCE_SHORT": "P", "INFO_DIALOG_PARSIM_DESC": "Choisir une combinaison de valeurs pour générer la simulation", "INFO_FIELDSET_ADD": "Ajouter", "INFO_FIELDSET_COPY": "Copier", @@ -518,6 +521,8 @@ "INFO_PARAMFIELD_VARIATED": "Varié", "INFO_PARAMMODE_LIST": "Liste de valeurs", "INFO_PARAMMODE_MINMAX": "Min/max", + "INFO_PB_BASSIN_DESCRIPTION": "B%order%", + "INFO_PB_CLOISON_DESCRIPTION": "%ub%-%db%", "INFO_PB_ADD_BASIN": "Ajouter un bassin", "INFO_PB_ADD_WALL": "Ajouter une cloison", "INFO_PB_BASSIN_N": "Bassin n°", @@ -544,7 +549,7 @@ "INFO_REMOUS_LARGEUR_BERGE": "Largeur au niveau des berges = %B% m", "INFO_REMOUS_RESSAUT_DEHORS": "Ressaut hydraulique détecté à l'%sens% de l'abscisse %x% m", "INFO_REMOUS_RESSAUT_HYDRO": "Ressaut hydraulique détecté entre les abscisses %xmin% et %xmax% m", - "INFO_REMOUSRESULTS_ABSCISSE": "Abscisse (m)", + "INFO_REMOUSRESULTS_ABSCISSE": "Abscisse", "INFO_REMOUSRESULTS_BERGE": "Berge", "INFO_REMOUSRESULTS_FOND": "Fond", "INFO_REMOUSRESULTS_TIRANT": "Tirant d'eau (m)", -- GitLab