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

Easier access to results / extraResults values list

Showing with 65 additions and 10 deletions
+65 -10
...@@ -100,9 +100,6 @@ export class Result extends JalhydObject implements INamedIterableValues { ...@@ -100,9 +100,6 @@ export class Result extends JalhydObject implements INamedIterableValues {
return this.resultElement.vCalc; return this.resultElement.vCalc;
} }
/**
* @return le résultat de calcul du 1er ResultElement
*/
set vCalc(r: number) { set vCalc(r: number) {
this.resultElement.vCalc = r; this.resultElement.vCalc = r;
} }
...@@ -176,6 +173,7 @@ export class Result extends JalhydObject implements INamedIterableValues { ...@@ -176,6 +173,7 @@ export class Result extends JalhydObject implements INamedIterableValues {
return Object.keys(r).length; return Object.keys(r).length;
} }
// WTF
public getExtraResult(name: string): any { public getExtraResult(name: string): any {
const res = []; const res = [];
for (const r of this._resultElements) { for (const r of this._resultElements) {
...@@ -195,11 +193,35 @@ export class Result extends JalhydObject implements INamedIterableValues { ...@@ -195,11 +193,35 @@ export class Result extends JalhydObject implements INamedIterableValues {
default: default:
throw new Error( throw new Error(
"Result.getExtraResult() : il existe plusieurs ResultElement avec" + "Result.getExtraResult() : il existe plusieurs ResultElement avec" +
" un extratresult dont le nom est '" + name + "'", " un extraResult dont le nom est '" + name + "'",
); );
} }
} }
/**
* Returns the list of calculated values for the parameter in CALC mode;
* if no parameter is variated, the list will contain only 1 value
*/
public getCalculatedValues(): number[] {
return this.resultElements.map((re) => {
return re.vCalc;
});
}
/**
* Returns the list of extra results values for the given symbol;
* if no parameter is variated, the list will contain only 1 value
*/
public getExtraResults(symbol: string): number[] {
const extraRes: number[] = [];
const ier = this.getIterableExtraResults(symbol);
ier.initValuesIterator(false);
for (const er of ier) {
extraRes.push(er);
}
return extraRes;
}
/** /**
* ajoute un message au journal * ajoute un message au journal
*/ */
...@@ -292,11 +314,9 @@ export class Result extends JalhydObject implements INamedIterableValues { ...@@ -292,11 +314,9 @@ export class Result extends JalhydObject implements INamedIterableValues {
res.addValue(er); res.addValue(er);
} }
} }
if (found) { if (found) {
return res; return res;
} }
return undefined; return undefined;
} }
......
...@@ -86,16 +86,38 @@ export class LinkedValue { ...@@ -86,16 +86,38 @@ export class LinkedValue {
/** /**
* Returs the ParamValues for the linked Parameter if any, or a * Returs the ParamValues for the linked Parameter if any, or a
* pseudo ParamValues object if the targetted element is a Result * fake ParamValues object if the targetted element is a Result
* or ExtraResults * or ExtraResults
*/ */
public getParamValues(): ParamValues { public getParamValues(): ParamValues {
let ret: ParamValues;
if (this.isParameter()) { if (this.isParameter()) {
return (this.element as ParamDefinition).paramValues; // simple proxy
ret = (this.element as ParamDefinition).paramValues;
} else if (this.isExtraResult()) {
// already computed ?
if (this.nub.result) {
// handmade fake param values
ret = new ParamValues(); // @TODO extend class ?
// console.log("setting fake PV for linked ER", this.symbol,
// this.nub.result, this.nub.result.extraResults);
if (this.nub.resultHasMultipleValues()) {
const multipleExtraRes = this.nub.result.getExtraResults(this.symbol);
ret.setValues(multipleExtraRes);
} else {
const singleExtraRes = this.nub.result.getExtraResult(this.symbol);
ret.setSingleValue(singleExtraRes);
}
} else {
// not computed yet @TODO return undefined instead of throwing error ?
throw new Error("LinkedValue.getParamValues() - result not yet available");
}
} else { } else {
// @TODO implement throw new Error("LinkedValue.getParamValues() - cannot determine nature of target");
throw new Error("not implemented - get pseudo ParamValues for ExtraResults");
} }
return ret;
} }
/** /**
...@@ -111,6 +133,19 @@ export class LinkedValue { ...@@ -111,6 +133,19 @@ export class LinkedValue {
return this.getParamValues().currentValue; return this.getParamValues().currentValue;
} }
/**
* Returns the current values array of this.paramValues; throws an error if
* this.paramValues is not defined
*/
public getValues(): number[] {
if (! this.getParamValues().isDefined) {
const e = new Message(MessageCode.ERROR_PARAMDEF_LINKED_VALUE_UNDEFINED);
e.extraVar.symbol = this.symbol;
throw e;
}
return this.getParamValues().valueList;
}
/** /**
* Returns true if * Returns true if
* - a parameter is targetted and it has multiple values * - a parameter is targetted and it has multiple values
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment