aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/operations
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-04-07 23:01:46 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-04-07 23:01:46 -0400
commite262d9ac73af5b2cef384468c47d69917e205d44 (patch)
tree4b563896d93febb233e7bffc2a292af4097136b3 /src/client/northstar/operations
parent52ad8b3874419a76e6953c3bd698d9e68a3158a6 (diff)
lots of code cleanup - removed all northstar db stuff. added scriptingBox. renamed things. made collectiontypes strings not numbers.
Diffstat (limited to 'src/client/northstar/operations')
-rw-r--r--src/client/northstar/operations/BaseOperation.ts162
-rw-r--r--src/client/northstar/operations/HistogramOperation.ts158
2 files changed, 0 insertions, 320 deletions
diff --git a/src/client/northstar/operations/BaseOperation.ts b/src/client/northstar/operations/BaseOperation.ts
deleted file mode 100644
index 013f2244e..000000000
--- a/src/client/northstar/operations/BaseOperation.ts
+++ /dev/null
@@ -1,162 +0,0 @@
-import { FilterModel } from '../core/filter/FilterModel';
-import { ErrorResult, Exception, OperationParameters, OperationReference, Result, ResultParameters } from '../model/idea/idea';
-import { action, computed, observable } from "mobx";
-import { Gateway } from '../manager/Gateway';
-
-export abstract class BaseOperation {
- private _interactionTimeoutId: number = 0;
- private static _currentOperations: Map<number, PollPromise> = new Map<number, PollPromise>();
- //public InteractionTimeout: EventDelegate<InteractionTimeoutEventArgs> = new EventDelegate<InteractionTimeoutEventArgs>();
-
- @observable public Error: string = "";
- @observable public OverridingFilters: FilterModel[] = [];
- //@observable
- @observable public Result?: Result = undefined;
- @observable public ComputationStarted: boolean = false;
- public OperationReference?: OperationReference = undefined;
-
- private static _nextId = 0;
- public RequestSalt: string = "";
- public Id: number;
-
- constructor() {
- this.Id = BaseOperation._nextId++;
- }
-
- @computed
- public get FilterString(): string {
- return "";
- }
-
-
- @action
- public SetResult(result: Result): void {
- this.Result = result;
- }
-
- public async Update(): Promise<void> {
-
- try {
- if (BaseOperation._currentOperations.has(this.Id)) {
- BaseOperation._currentOperations.get(this.Id)!.Cancel();
- if (this.OperationReference) {
- Gateway.Instance.PauseOperation(this.OperationReference.toJSON());
- }
- }
-
- const operationParameters = this.CreateOperationParameters();
- if (this.Result) {
- this.Result.progress = 0;
- } // bcz: used to set Result to undefined, but that causes the display to blink
- this.Error = "";
- const salt = Math.random().toString();
- this.RequestSalt = salt;
-
- if (!operationParameters) {
- this.ComputationStarted = false;
- return;
- }
-
- this.ComputationStarted = true;
- //let start = performance.now();
- const promise = Gateway.Instance.StartOperation(operationParameters.toJSON());
- promise.catch(err => {
- action(() => {
- this.Error = err;
- console.error(err);
- });
- });
- const operationReference = await promise;
-
-
- if (operationReference) {
- this.OperationReference = operationReference;
-
- const resultParameters = new ResultParameters();
- resultParameters.operationReference = operationReference;
-
- const pollPromise = new PollPromise(salt, operationReference);
- BaseOperation._currentOperations.set(this.Id, pollPromise);
-
- pollPromise.Start(async () => {
- const result = await Gateway.Instance.GetResult(resultParameters.toJSON());
- if (result instanceof ErrorResult) {
- throw new Error((result).message);
- }
- if (this.RequestSalt === pollPromise.RequestSalt) {
- if (result && (!this.Result || this.Result.progress !== result.progress)) {
- /*if (operationViewModel.Result !== null && operationViewModel.Result !== undefined) {
- let t1 = performance.now();
- console.log((t1 - start) + " milliseconds.");
- start = performance.now();
- }*/
- this.SetResult(result);
- }
-
- if (!result || result.progress! < 1) {
- return true;
- }
- }
- return false;
- }, 100).catch((err: Error) => action(() => {
- this.Error = err.message;
- console.error(err.message);
- })()
- );
- }
- }
- catch (err) {
- console.error(err as Exception);
- // ErrorDialog.Instance.HandleError(err, operationViewModel);
- }
- }
-
- public CreateOperationParameters(): OperationParameters | undefined { return undefined; }
-
- private interactionTimeout() {
- // clearTimeout(this._interactionTimeoutId);
- // this.InteractionTimeout.Fire(new InteractionTimeoutEventArgs(this.TypedViewModel, InteractionTimeoutType.Timeout));
- }
-}
-
-export class PollPromise {
- public RequestSalt: string;
- public OperationReference: OperationReference;
-
- private _notCanceled: boolean = true;
- private _poll: undefined | (() => Promise<boolean>);
- private _delay: number = 0;
-
- public constructor(requestKey: string, operationReference: OperationReference) {
- this.RequestSalt = requestKey;
- this.OperationReference = operationReference;
- }
-
- public Cancel(): void {
- this._notCanceled = false;
- }
-
- public Start(poll: () => Promise<boolean>, delay: number): Promise<void> {
- this._poll = poll;
- this._delay = delay;
- return this.pollRecursive();
- }
-
- private pollRecursive = (): Promise<void> => {
- return Promise.resolve().then(this._poll).then((flag) => {
- this._notCanceled && flag && new Promise((res) => (setTimeout(res, this._delay)))
- .then(this.pollRecursive);
- });
- }
-}
-
-
-export class InteractionTimeoutEventArgs {
- constructor(public Sender: object, public Type: InteractionTimeoutType) {
- }
-}
-
-export enum InteractionTimeoutType {
- Reset = 0,
- Timeout = 1
-}
diff --git a/src/client/northstar/operations/HistogramOperation.ts b/src/client/northstar/operations/HistogramOperation.ts
deleted file mode 100644
index 74e23ea48..000000000
--- a/src/client/northstar/operations/HistogramOperation.ts
+++ /dev/null
@@ -1,158 +0,0 @@
-import { action, computed, observable, trace } from "mobx";
-import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
-import { ColumnAttributeModel } from "../core/attribute/AttributeModel";
-import { AttributeTransformationModel } from "../core/attribute/AttributeTransformationModel";
-import { CalculatedAttributeManager } from "../core/attribute/CalculatedAttributeModel";
-import { FilterModel } from "../core/filter/FilterModel";
-import { FilterOperand } from "../core/filter/FilterOperand";
-import { IBaseFilterConsumer } from "../core/filter/IBaseFilterConsumer";
-import { IBaseFilterProvider } from "../core/filter/IBaseFilterProvider";
-import { HistogramField } from "../dash-fields/HistogramField";
-import { SETTINGS_SAMPLE_SIZE, SETTINGS_X_BINS, SETTINGS_Y_BINS } from "../model/binRanges/VisualBinRangeHelper";
-import { AggregateFunction, AggregateParameters, Attribute, AverageAggregateParameters, Bin, DataType, DoubleValueAggregateResult, HistogramOperationParameters, HistogramResult, QuantitativeBinRange } from "../model/idea/idea";
-import { ModelHelpers } from "../model/ModelHelpers";
-import { ArrayUtil } from "../utils/ArrayUtil";
-import { BaseOperation } from "./BaseOperation";
-import { Doc } from "../../../new_fields/Doc";
-import { Cast, NumCast } from "../../../new_fields/Types";
-
-export class HistogramOperation extends BaseOperation implements IBaseFilterConsumer, IBaseFilterProvider {
- public static Empty = new HistogramOperation("-empty schema-", new AttributeTransformationModel(new ColumnAttributeModel(new Attribute())), new AttributeTransformationModel(new ColumnAttributeModel(new Attribute())), new AttributeTransformationModel(new ColumnAttributeModel(new Attribute())));
- @observable public FilterOperand: FilterOperand = FilterOperand.AND;
- @observable public Links: Doc[] = [];
- @observable public BrushLinks: { l: Doc, b: Doc }[] = [];
- @observable public BrushColors: number[] = [];
- @observable public BarFilterModels: FilterModel[] = [];
-
- @observable public Normalization: number = -1;
- @observable public X: AttributeTransformationModel;
- @observable public Y: AttributeTransformationModel;
- @observable public V: AttributeTransformationModel;
- @observable public SchemaName: string;
- @observable public QRange: QuantitativeBinRange | undefined;
- public get Schema() { return CurrentUserUtils.GetNorthstarSchema(this.SchemaName); }
-
- constructor(schemaName: string, x: AttributeTransformationModel, y: AttributeTransformationModel, v: AttributeTransformationModel, normalized?: number) {
- super();
- this.X = x;
- this.Y = y;
- this.V = v;
- this.Normalization = normalized ? normalized : -1;
- this.SchemaName = schemaName;
- }
-
- public static Duplicate(op: HistogramOperation) {
-
- return new HistogramOperation(op.SchemaName, op.X, op.Y, op.V, op.Normalization);
- }
- public Copy(): HistogramOperation {
- return new HistogramOperation(this.SchemaName, this.X, this.Y, this.V, this.Normalization);
- }
-
- Equals(other: Object): boolean {
- throw new Error("Method not implemented.");
- }
-
-
- public get FilterModels() {
- return this.BarFilterModels;
- }
- @action
- public AddFilterModels(filterModels: FilterModel[]): void {
- filterModels.filter(f => f !== null).forEach(fm => this.BarFilterModels.push(fm));
- }
- @action
- public RemoveFilterModels(filterModels: FilterModel[]): void {
- ArrayUtil.RemoveMany(this.BarFilterModels, filterModels);
- }
-
- @computed
- public get FilterString(): string {
- if (this.OverridingFilters.length > 0) {
- return "(" + this.OverridingFilters.filter(fm => fm !== null).map(fm => fm.ToPythonString()).join(" || ") + ")";
- }
- let filterModels: FilterModel[] = [];
- return FilterModel.GetFilterModelsRecursive(this, new Set<IBaseFilterProvider>(), filterModels, true);
- }
-
- public get BrushString(): string[] {
- let brushes: string[] = [];
- this.BrushLinks.map(brushLink => {
- let brushHistogram = Cast(brushLink.b.data, HistogramField);
- if (brushHistogram) {
- let filterModels: FilterModel[] = [];
- brushes.push(FilterModel.GetFilterModelsRecursive(brushHistogram.HistoOp, new Set<IBaseFilterProvider>(), filterModels, false));
- }
- });
- return brushes;
- }
-
- _stackedFilters: (FilterModel[])[] = [];
- @action
- public DrillDown(up: boolean) {
- if (!up) {
- if (!this.BarFilterModels.length) {
- return;
- }
- this._stackedFilters.push(this.BarFilterModels.map(f => f));
- this.OverridingFilters.length = 0;
- this.OverridingFilters.push(...this._stackedFilters[this._stackedFilters.length - 1]);
- this.BarFilterModels.map(fm => fm).map(fm => this.RemoveFilterModels([fm]));
- //this.updateHistogram();
- } else {
- this.OverridingFilters.length = 0;
- if (this._stackedFilters.length) {
- this.OverridingFilters.push(...this._stackedFilters.pop()!);
- }
- // else
- // this.updateHistogram();
- }
- }
-
- private getAggregateParameters(histoX: AttributeTransformationModel, histoY: AttributeTransformationModel, histoValue: AttributeTransformationModel) {
- let allAttributes = new Array<AttributeTransformationModel>(histoX, histoY, histoValue);
- allAttributes = ArrayUtil.Distinct(allAttributes.filter(a => a.AggregateFunction !== AggregateFunction.None));
-
- let numericDataTypes = [DataType.Int, DataType.Double, DataType.Float];
- let perBinAggregateParameters: AggregateParameters[] = ModelHelpers.GetAggregateParametersWithMargins(this.Schema!.distinctAttributeParameters, allAttributes);
- let globalAggregateParameters: AggregateParameters[] = [];
- [histoX, histoY]
- .filter(a => a.AggregateFunction === AggregateFunction.None && ArrayUtil.Contains(numericDataTypes, a.AttributeModel.DataType))
- .forEach(a => {
- let avg = new AverageAggregateParameters();
- avg.attributeParameters = ModelHelpers.GetAttributeParameters(a.AttributeModel);
- globalAggregateParameters.push(avg);
- });
- return [perBinAggregateParameters, globalAggregateParameters];
- }
-
- public CreateOperationParameters(): HistogramOperationParameters | undefined {
- if (this.X && this.Y && this.V) {
- let [perBinAggregateParameters, globalAggregateParameters] = this.getAggregateParameters(this.X, this.Y, this.V);
- return new HistogramOperationParameters({
- enableBrushComputation: true,
- adapterName: this.SchemaName,
- filter: this.FilterString,
- brushes: this.BrushString,
- binningParameters: [ModelHelpers.GetBinningParameters(this.X, SETTINGS_X_BINS, this.QRange ? this.QRange.minValue : undefined, this.QRange ? this.QRange.maxValue : undefined),
- ModelHelpers.GetBinningParameters(this.Y, SETTINGS_Y_BINS)],
- sampleStreamBlockSize: SETTINGS_SAMPLE_SIZE,
- perBinAggregateParameters: perBinAggregateParameters,
- globalAggregateParameters: globalAggregateParameters,
- sortPerBinAggregateParameter: undefined,
- attributeCalculatedParameters: CalculatedAttributeManager
- .AllCalculatedAttributes.map(a => ModelHelpers.GetAttributeParametersFromAttributeModel(a)),
- degreeOfParallism: 1, // Settings.Instance.DegreeOfParallelism,
- isCachable: false
- });
- }
- }
-
- @action
- public async Update(): Promise<void> {
- this.BrushColors = this.BrushLinks.map(e => NumCast(e.l.backgroundColor));
- return super.Update();
- }
-}
-
-