Skip to content

Commit

Permalink
Adjust front-end after discussion with Sigurd
Browse files Browse the repository at this point in the history
- Remove EnsembleInterface and EnsembleIdentInterface
- Rename `Ensemble` to `RegularEnsemble`and `EnsembleIdent` to `RegularEnsembleIdent`
  • Loading branch information
jorgenherje committed Dec 2, 2024
1 parent b8f0ede commit e8570c3
Show file tree
Hide file tree
Showing 115 changed files with 873 additions and 579 deletions.
23 changes: 9 additions & 14 deletions frontend/src/framework/DeltaEnsemble.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { v4 } from "uuid";

import { DeltaEnsembleIdent } from "./DeltaEnsembleIdent";
import { Ensemble } from "./Ensemble";
import { EnsembleIdent } from "./EnsembleIdent";
import { EnsembleInterface } from "./EnsembleInterface";
import { EnsembleParameters } from "./EnsembleParameters";
import { EnsembleSensitivities } from "./EnsembleSensitivities";
import { RegularEnsemble } from "./RegularEnsemble";
import { RegularEnsembleIdent } from "./RegularEnsembleIdent";

/**
* Delta ensemble class.
Expand All @@ -17,10 +16,10 @@ import { EnsembleSensitivities } from "./EnsembleSensitivities";
* DeltaEnsemble = CompareEnsemble - ReferenceEnsemble
*
*/
export class DeltaEnsemble implements EnsembleInterface {
export class DeltaEnsemble {
private _deltaEnsembleIdent: DeltaEnsembleIdent;
private _compareEnsemble: Ensemble;
private _referenceEnsemble: Ensemble;
private _compareEnsemble: RegularEnsemble;
private _referenceEnsemble: RegularEnsemble;
private _color: string;
private _customName: string | null;

Expand All @@ -29,8 +28,8 @@ export class DeltaEnsemble implements EnsembleInterface {
private _sensitivities: EnsembleSensitivities | null;

constructor(
compareEnsemble: Ensemble,
referenceEnsemble: Ensemble,
compareEnsemble: RegularEnsemble,
referenceEnsemble: RegularEnsemble,
color: string,
customName: string | null = null
) {
Expand Down Expand Up @@ -59,8 +58,6 @@ export class DeltaEnsemble implements EnsembleInterface {
this._sensitivities = null;
}

// *** Interface methods ***

getIdent(): DeltaEnsembleIdent {
return this._deltaEnsembleIdent;
}
Expand Down Expand Up @@ -105,13 +102,11 @@ export class DeltaEnsemble implements EnsembleInterface {
return this._sensitivities;
}

// *** Custom methods ***

getCompareEnsembleIdent(): EnsembleIdent {
getCompareEnsembleIdent(): RegularEnsembleIdent {
return this._compareEnsemble.getIdent();
}

getReferenceEnsembleIdent(): EnsembleIdent {
getReferenceEnsembleIdent(): RegularEnsembleIdent {
return this._referenceEnsemble.getIdent();
}

Expand Down
30 changes: 19 additions & 11 deletions frontend/src/framework/DeltaEnsembleIdent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EnsembleIdent } from "./EnsembleIdent";
import { EnsembleIdentInterface } from "./EnsembleIdentInterface";
import { RegularEnsembleIdent } from "./RegularEnsembleIdent";
import { ensembleIdentRegexStringWithoutAnchors, ensembleIdentUuidRegexString } from "./utils/ensembleIdentUtils";

/**
Expand All @@ -15,13 +14,22 @@ import { ensembleIdentRegexStringWithoutAnchors, ensembleIdentUuidRegexString }
* DeltaEnsemble = CompareEnsemble - ReferenceEnsemble
*
*/
export class DeltaEnsembleIdent implements EnsembleIdentInterface<DeltaEnsembleIdent> {
export class DeltaEnsembleIdent {
private _uuid: string;
private _ensembleName: string;
private _compareEnsembleIdent: EnsembleIdent;
private _referenceEnsembleIdent: EnsembleIdent;
private _compareEnsembleIdent: RegularEnsembleIdent;
private _referenceEnsembleIdent: RegularEnsembleIdent;

constructor(
uuid: string,
compareEnsembleIdent: RegularEnsembleIdent,
referenceEnsembleIdent: RegularEnsembleIdent
) {
const uuidRegex = new RegExp(ensembleIdentUuidRegexString());
if (!uuidRegex.exec(uuid)) {
throw new Error(`Invalid uuid: ${uuid}`);
}

constructor(uuid: string, compareEnsembleIdent: EnsembleIdent, referenceEnsembleIdent: EnsembleIdent) {
this._uuid = uuid;
this._ensembleName = `(${compareEnsembleIdent.getEnsembleName()}) - (${referenceEnsembleIdent.getEnsembleName()})`;
this._compareEnsembleIdent = compareEnsembleIdent;
Expand Down Expand Up @@ -69,8 +77,8 @@ export class DeltaEnsembleIdent implements EnsembleIdentInterface<DeltaEnsembleI

return new DeltaEnsembleIdent(
uuid,
new EnsembleIdent(compareCaseUuid, compareEnsembleName),
new EnsembleIdent(referenceCaseUuid, referenceEnsembleName)
new RegularEnsembleIdent(compareCaseUuid, compareEnsembleName),
new RegularEnsembleIdent(referenceCaseUuid, referenceEnsembleName)
);
}

Expand All @@ -96,11 +104,11 @@ export class DeltaEnsembleIdent implements EnsembleIdentInterface<DeltaEnsembleI
return this._ensembleName;
}

getCompareEnsembleIdent(): EnsembleIdent {
getCompareEnsembleIdent(): RegularEnsembleIdent {
return this._compareEnsembleIdent;
}

getReferenceEnsembleIdent(): EnsembleIdent {
getReferenceEnsembleIdent(): RegularEnsembleIdent {
return this._referenceEnsembleIdent;
}

Expand All @@ -112,7 +120,7 @@ export class DeltaEnsembleIdent implements EnsembleIdentInterface<DeltaEnsembleI
);
}

equals(otherIdent: EnsembleIdentInterface<any> | null): boolean {
equals(otherIdent: any | null): boolean {
if (!otherIdent || !(otherIdent instanceof DeltaEnsembleIdent)) {
return false;
}
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/framework/EnsembleIdentInterface.ts

This file was deleted.

16 changes: 0 additions & 16 deletions frontend/src/framework/EnsembleInterface.ts

This file was deleted.

77 changes: 44 additions & 33 deletions frontend/src/framework/EnsembleSet.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
import { DeltaEnsemble } from "./DeltaEnsemble";
import { DeltaEnsembleIdent } from "./DeltaEnsembleIdent";
import { Ensemble } from "./Ensemble";
import { EnsembleIdent } from "./EnsembleIdent";
import { EnsembleTypeSet } from "./EnsembleTypeSet";
import { RegularEnsemble } from "./RegularEnsemble";
import { RegularEnsembleIdent } from "./RegularEnsembleIdent";

export class EnsembleSet {
private _regularEnsembleSet: EnsembleTypeSet<EnsembleIdent, Ensemble>;
private _deltaEnsembleSet: EnsembleTypeSet<DeltaEnsembleIdent, DeltaEnsemble>;
private _regularEnsembleArray: RegularEnsemble[];
private _deltaEnsembleArray: DeltaEnsemble[];

constructor(ensembles: Ensemble[], deltaEnsembles: DeltaEnsemble[] = []) {
this._regularEnsembleSet = new EnsembleTypeSet<EnsembleIdent, Ensemble>(ensembles);
this._deltaEnsembleSet = new EnsembleTypeSet<DeltaEnsembleIdent, DeltaEnsemble>(deltaEnsembles);
constructor(ensembles: RegularEnsemble[], deltaEnsembles: DeltaEnsemble[] = []) {
this._regularEnsembleArray = ensembles;
this._deltaEnsembleArray = deltaEnsembles;
}

/**
* Returns true if there are any regular ensembles in the set.
* @returns True if there are any regular ensembles in the set.
*/
hasAnyEnsembles(): boolean {
return this._regularEnsembleSet.hasAnyEnsembles();
hasAnyRegularEnsembles(): boolean {
return this._regularEnsembleArray.length > 0;
}

/**
* Returns true if there are any delta ensembles in the set.
* @returns True if there are any delta ensembles in the set.
*/
hasAnyDeltaEnsembles(): boolean {
return this._deltaEnsembleSet.hasAnyEnsembles();
return this._deltaEnsembleArray.length > 0;
}

/**
* Returns true if there are any regular or delta ensembles in the set.
* @returns True if there are any regular or delta ensembles in the set.
*/
hasAnyEnsemblesOrDeltaEnsembles(): boolean {
return this.hasAnyEnsembles() || this.hasAnyDeltaEnsembles();
hasAnyEnsembles(): boolean {
return this.hasAnyRegularEnsembles() || this.hasAnyDeltaEnsembles();
}

/**
* Get an array of all regular ensembles in the set.
* @returns An array of all regular ensembles in the set.
*/
getEnsembleArray(): readonly Ensemble[] {
return this._regularEnsembleSet.getEnsembleArray();
getRegularEnsembleArray(): readonly RegularEnsemble[] {
return this._regularEnsembleArray;
}

/**
* Get an array of all delta ensembles in the set.
* @returns An array of all delta ensembles in the set.
*/
getDeltaEnsembleArray(): readonly DeltaEnsemble[] {
return this._deltaEnsembleSet.getEnsembleArray();
return this._deltaEnsembleArray;
}

/**
* Get an array of all ensembles in the set.
* @returns An array of all ensembles in the set.
*/
getAllEnsembleTypesArray(): readonly (Ensemble | DeltaEnsemble)[] {
return [...this._regularEnsembleSet.getEnsembleArray(), ...this._deltaEnsembleSet.getEnsembleArray()];
getEnsembleArray(): readonly (RegularEnsemble | DeltaEnsemble)[] {
return [...this._regularEnsembleArray, ...this._deltaEnsembleArray];
}

/**
Expand All @@ -67,37 +66,49 @@ export class EnsembleSet {
* @param ensembleIdent - The ensemble ident to check for, can be either a regular or delta ensemble ident.
* @returns True if the ensemble set has the given ensemble ident.
*/
hasEnsemble(ensembleIdent: EnsembleIdent | DeltaEnsembleIdent): boolean {
if (ensembleIdent instanceof EnsembleIdent) {
return this._regularEnsembleSet.findEnsemble(ensembleIdent) !== null;
hasEnsemble(ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent): boolean {
if (ensembleIdent instanceof RegularEnsembleIdent) {
return this.findEnsemble(ensembleIdent) !== null;
}
if (ensembleIdent instanceof DeltaEnsembleIdent) {
return this._deltaEnsembleSet.findEnsemble(ensembleIdent) !== null;
return this.findEnsemble(ensembleIdent) !== null;
}
return false;
}

findEnsemble(ensembleIdent: EnsembleIdent): Ensemble | null;
/**
* Find an ensemble in the set by its ensemble ident.
*
* @param ensembleIdent
* @returns The ensemble if found, otherwise null.
*/
findEnsemble(ensembleIdent: RegularEnsembleIdent): RegularEnsemble | null;
findEnsemble(ensembleIdent: DeltaEnsembleIdent): DeltaEnsemble | null;
findEnsemble(ensembleIdent: EnsembleIdent | DeltaEnsembleIdent): Ensemble | DeltaEnsemble | null;
findEnsemble(ensembleIdent: EnsembleIdent | DeltaEnsembleIdent): Ensemble | DeltaEnsemble | null {
if (ensembleIdent instanceof EnsembleIdent) {
return this._regularEnsembleSet.findEnsemble(ensembleIdent);
findEnsemble(ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent): RegularEnsemble | DeltaEnsemble | null;
findEnsemble(ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent): RegularEnsemble | DeltaEnsemble | null {
if (ensembleIdent instanceof RegularEnsembleIdent) {
return this._regularEnsembleArray.find((ens) => ens.getIdent().equals(ensembleIdent)) ?? null;
}
if (ensembleIdent instanceof DeltaEnsembleIdent) {
return this._deltaEnsembleSet.findEnsemble(ensembleIdent);
return this._deltaEnsembleArray.find((ens) => ens.getIdent().equals(ensembleIdent)) ?? null;
}
return null;
}

findEnsembleByIdentString(ensembleIdentString: string): Ensemble | DeltaEnsemble | null {
if (EnsembleIdent.isValidEnsembleIdentString(ensembleIdentString)) {
const ensembleIdent = EnsembleIdent.fromString(ensembleIdentString);
return this._regularEnsembleSet.findEnsemble(ensembleIdent);
/**
* Find an ensemble in the set by its ensemble ident string.
*
* @param ensembleIdentString - The ensemble ident string to search for.
* @returns The ensemble if found, otherwise null.
*/
findEnsembleByIdentString(ensembleIdentString: string): RegularEnsemble | DeltaEnsemble | null {
if (RegularEnsembleIdent.isValidEnsembleIdentString(ensembleIdentString)) {
const ensembleIdent = RegularEnsembleIdent.fromString(ensembleIdentString);
return this.findEnsemble(ensembleIdent);
}
if (DeltaEnsembleIdent.isValidDeltaEnsembleIdentString(ensembleIdentString)) {
const deltaEnsembleIdent = DeltaEnsembleIdent.fromString(ensembleIdentString);
return this._deltaEnsembleSet.findEnsemble(deltaEnsembleIdent);
return this.findEnsemble(deltaEnsembleIdent);
}
return null;
}
Expand Down
26 changes: 0 additions & 26 deletions frontend/src/framework/EnsembleTypeSet.ts

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/framework/GlobalAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { atom } from "jotai";
import { isEqual } from "lodash";

import { DeltaEnsembleIdent } from "./DeltaEnsembleIdent";
import { EnsembleIdent } from "./EnsembleIdent";
import { RealizationFilterSet } from "./RealizationFilterSet";
import { RegularEnsembleIdent } from "./RegularEnsembleIdent";
import { EnsembleRealizationFilterFunction } from "./WorkbenchSession";
import { atomWithCompare } from "./utils/atomUtils";

Expand All @@ -27,7 +27,7 @@ export const EnsembleRealizationFilterFunctionAtom = atom<EnsembleRealizationFil
return null;
}

return (ensembleIdent: EnsembleIdent | DeltaEnsembleIdent) =>
return (ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent) =>
realizationFilterSet.getRealizationFilterForEnsembleIdent(ensembleIdent).getFilteredRealizations();
});

Expand All @@ -41,7 +41,7 @@ export const ValidEnsembleRealizationsFunctionAtom = atom((get) => {
let validEnsembleRealizationsFunction = get(EnsembleRealizationFilterFunctionAtom);

if (validEnsembleRealizationsFunction === null) {
validEnsembleRealizationsFunction = (ensembleIdent: EnsembleIdent | DeltaEnsembleIdent) => {
validEnsembleRealizationsFunction = (ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent) => {
return ensembleSet.findEnsemble(ensembleIdent)?.getRealizations() ?? [];
};
}
Expand Down
Loading

0 comments on commit e8570c3

Please sign in to comment.