Skip to content
Snippets Groups Projects
remous-results.ts 7.43 KiB
Newer Older
import { cLog, CourbeRemousParams, Result, ResultElement, ParamDefinition, ParamDomainValue, Nub } from "jalhyd";
import { CalculatorResults } from "./calculator-results";
import { VarResults } from "./var-results";
import { ServiceFactory } from "../services/service-factory";
import { FormulaireDefinition } from "../formulaire/definition/form-definition";

export class RemousResults extends CalculatorResults {
    /** pseudo-paramètre varié contenant la liste des abscisses pour lesquelles on a des résultats */
    private _xValues: ParamDefinition;
    /** pas de discrétisation */
    private _Dx: number;

    /** cote de fond amont */
    private _ZF1: number;

    /** cote de fond aval */
    private _ZF2: number;

    /** longueur du bief */
    private _Long: number;

    /** hauteur de berge */
    private _hautBerge: number;
    private _hautNormale: ResultElement;
    private _hautCritique: ResultElement;
    /** présence de données pour la courbe fluviale */
    /** présence de données pour la courbe torrentielle */
    /** présence de données pour le paramètre supplémentaire */
    /** résultats variables pour l'affichage d'une table de résultats numériques */
Mathias Chouet's avatar
Mathias Chouet committed
    /** le paramètre supplémentaire est affiché dans un graphique séparé */
    private _extraChart: boolean;
    /** titre de la colonne du paramètre supplémentaire */
    /** pointer to form that instantiated this object */
    protected _form: FormulaireDefinition;

    /**
     * liste des X,Y (fluvial ou torrentiel)
     */
    private _points: any[];

    constructor(form?: FormulaireDefinition) {
        this._form = form;
francois.grand's avatar
francois.grand committed
        this._hautBerge = undefined;
        this._penteFond = undefined;
        this._hautNormale = undefined;
        this._hautCritique = undefined;
        this._hasFlu = false;
        this._hasTor = false;
        this._extraChart = false;

        // série de valeurs de X
        this._xValues = new ParamDefinition(
            undefined,
            "ABSCISSE",
            ParamDomainValue.POS_NULL
        );
    public set parameters(p: CourbeRemousParams) {
        this._penteFond = nub.getParameter("If").singleValue;
        this._hautBerge = nub.getParameter("YB").singleValue;
        this._Long = nub.getParameter("Long").singleValue;
        this._Dx = nub.getParameter("Dx").singleValue;
        // cote de fond amont
        this._ZF1 = nub.getParameter("ZF1").singleValue;

        // cote de fond aval
        this._ZF2 = nub.getParameter("ZF2").singleValue;
    public get log(): cLog {
    public get varResults(): VarResults {
        return this._varResults;
    public get xValues(): ParamDefinition {
        return this._xValues;
    }

    public get result(): Result {
        return this._result;
    }

    public set result(r: Result) {
        this._result = r;
        // abscisses pour lesquelles on a des résultats
        const abscissae = r.resultElements.map((re) => {
            return re.getValue("X");
        });
        this._xValues.setValues(abscissae);

        this.updatePoints();
    }

    private updatePoints() {
        this._points = this._result.resultElements.map((re) => {
            const X = re.getValue("X");

            // cote de fond
            const k = X / this._Long;
            const Zf = (this._ZF2 - this._ZF1) * k + this._ZF1;

            // cote de l'eau
            let Z = re.getValue("flu");
            if (Z === undefined)
                Z = re.getValue("tor");

            // tirant d'eau
            const Y = Z - Zf;

            return { x: X, y: Y, z: Z };
        this._hasFlu = false;
        this._hasTor = false;
        this._hasExtra = false;

        for (const re of this._result.resultElements) {
            if (!this._hasFlu && re.getValue("flu")) {
mathias.chouet's avatar
mathias.chouet committed
            }
            if (!this._hasTor && re.getValue("tor")) {
mathias.chouet's avatar
mathias.chouet committed
            }
            if (!this._hasExtra && re.getValue(this.extraParamSymbol)) {
mathias.chouet's avatar
mathias.chouet committed
            }

            if (this._hasFlu && this._hasTor && this._hasExtra )
                break; // micro optimisation : pas la peine de continuer à chercher
        this._log.clear();
        this._log.addLog(this._result.globalLog);

        this._varResults = new VarResults(this._form);
        this._varResults.variatedParameters = [ { param: this._xValues, values: this._xValues.paramValues } ];
        this._varResults.result = this._result;
mathias.chouet's avatar
mathias.chouet committed
        const keys = [];
        keys.push("ZW"); // ligne d'eau
        keys.push("Y"); // tirant d'eau
mathias.chouet's avatar
mathias.chouet committed
        if (this._hasFlu) {
mathias.chouet's avatar
mathias.chouet committed
        }
        if (this._hasTor) {
mathias.chouet's avatar
mathias.chouet committed
        }
        if (this._hasExtra) {
mathias.chouet's avatar
mathias.chouet committed
        }
        this._varResults.helpLinks = this.helpLinks;
mathias.chouet's avatar
mathias.chouet committed
        this._varResults.update();
    public get extraParamSymbol(): string {
        return this._extraParamSymbol;
    }

    public set extraParamSymbol(l: string) {
mathias.chouet's avatar
mathias.chouet committed
        if (l !== "") {
            this._extraParamSymbol = l;
        }
    public get Dx(): number {
        return this._Dx;
    }

    public get Long(): number {
        return this._Long;
    }


    public get hautBerge() {
        return this._hautBerge;
    }

    public get penteFond() {
        return this._penteFond;
    }

    public get hautNormale() {
        return this._hautNormale;
    }

    public set hauteurNormale(v: ResultElement) {
        this._hautNormale = v;
    }

    public get hautCritique() {
        return this._hautCritique;
    }

    public set hauteurCritique(v: ResultElement) {
        this._hautCritique = v;
    }

    public get hasExtra() {
        return this._hasExtra;
    }

    public get extraChart() {
        return this._extraChart;
    public set extraChart(b: boolean) {
        this._extraChart = b;
    public get hasResults(): boolean {
mathias.chouet's avatar
mathias.chouet committed
        return this._hautBerge !== undefined ||
            this._penteFond !== undefined ||
            this._hautNormale !== undefined ||
            this._hautCritique !== undefined ||
francois.grand's avatar
francois.grand committed

    /**
     * @return true si il existe au moins une données dans la série fluviale
     */
    public get hasFluData(): boolean {
francois.grand's avatar
francois.grand committed
    }

    /**
     * @return true si il existe au moins une données dans la série torrentielle
     */
    public get hasTorData(): boolean {
francois.grand's avatar
francois.grand committed
    }