aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/core
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2019-05-17 21:52:49 -0400
committerBob Zeleznik <zzzman@gmail.com>2019-05-17 21:52:49 -0400
commit618b4a42795b59cde47510b86b6e25dc03e15935 (patch)
treef10a9f093df478db15e94fbf8992a32fe8ba99d0 /src/client/northstar/core
parent19fca408a19c5f7a759ff6c3bfefe27b96ec3563 (diff)
parent4e244951b7b18d7973360f423e8de80c42466228 (diff)
merged
Diffstat (limited to 'src/client/northstar/core')
-rw-r--r--src/client/northstar/core/BaseObject.ts12
-rw-r--r--src/client/northstar/core/attribute/AttributeModel.ts111
-rw-r--r--src/client/northstar/core/attribute/AttributeTransformationModel.ts52
-rw-r--r--src/client/northstar/core/attribute/CalculatedAttributeModel.ts42
-rw-r--r--src/client/northstar/core/brusher/IBaseBrushable.ts13
-rw-r--r--src/client/northstar/core/brusher/IBaseBrusher.ts11
-rw-r--r--src/client/northstar/core/filter/FilterModel.ts83
-rw-r--r--src/client/northstar/core/filter/FilterOperand.ts5
-rw-r--r--src/client/northstar/core/filter/FilterType.ts6
-rw-r--r--src/client/northstar/core/filter/IBaseFilterConsumer.ts12
-rw-r--r--src/client/northstar/core/filter/IBaseFilterProvider.ts8
-rw-r--r--src/client/northstar/core/filter/ValueComparision.ts78
12 files changed, 433 insertions, 0 deletions
diff --git a/src/client/northstar/core/BaseObject.ts b/src/client/northstar/core/BaseObject.ts
new file mode 100644
index 000000000..ed3818071
--- /dev/null
+++ b/src/client/northstar/core/BaseObject.ts
@@ -0,0 +1,12 @@
+import { IEquatable } from '../utils/IEquatable';
+import { IDisposable } from '../utils/IDisposable';
+
+export class BaseObject implements IEquatable, IDisposable {
+
+ public Equals(other: Object): boolean {
+ return this === other;
+ }
+
+ public Dispose(): void {
+ }
+} \ No newline at end of file
diff --git a/src/client/northstar/core/attribute/AttributeModel.ts b/src/client/northstar/core/attribute/AttributeModel.ts
new file mode 100644
index 000000000..c89b1617c
--- /dev/null
+++ b/src/client/northstar/core/attribute/AttributeModel.ts
@@ -0,0 +1,111 @@
+import { Attribute, DataType, VisualizationHint } from '../../model/idea/idea';
+import { BaseObject } from '../BaseObject';
+import { observable } from "mobx";
+
+export abstract class AttributeModel extends BaseObject {
+ public abstract get DisplayName(): string;
+ public abstract get CodeName(): string;
+ public abstract get DataType(): DataType;
+ public abstract get VisualizationHints(): VisualizationHint[];
+}
+
+export class ColumnAttributeModel extends AttributeModel {
+ public Attribute: Attribute;
+
+ constructor(attribute: Attribute) {
+ super();
+ this.Attribute = attribute;
+ }
+
+ public get DataType(): DataType {
+ return this.Attribute.dataType ? this.Attribute.dataType : DataType.Undefined;
+ }
+
+ public get DisplayName(): string {
+ return this.Attribute.displayName ? this.Attribute.displayName.ReplaceAll("_", " ") : "";
+ }
+
+ public get CodeName(): string {
+ return this.Attribute.rawName ? this.Attribute.rawName : "";
+ }
+
+ public get VisualizationHints(): VisualizationHint[] {
+ return this.Attribute.visualizationHints ? this.Attribute.visualizationHints : [];
+ }
+
+ public Equals(other: ColumnAttributeModel): boolean {
+ return this.Attribute.rawName === other.Attribute.rawName;
+ }
+}
+
+export class CodeAttributeModel extends AttributeModel {
+ private _visualizationHints: VisualizationHint[];
+
+ public CodeName: string;
+
+ @observable
+ public Code: string;
+
+ constructor(code: string, codeName: string, displayName: string, visualizationHints: VisualizationHint[]) {
+ super();
+ this.Code = code;
+ this.CodeName = codeName;
+ this.DisplayName = displayName;
+ this._visualizationHints = visualizationHints;
+ }
+
+ public get DataType(): DataType {
+ return DataType.Undefined;
+ }
+
+ @observable
+ public DisplayName: string;
+
+ public get VisualizationHints(): VisualizationHint[] {
+ return this._visualizationHints;
+ }
+
+ public Equals(other: CodeAttributeModel): boolean {
+ return this.CodeName === other.CodeName;
+ }
+
+}
+
+export class BackendAttributeModel extends AttributeModel {
+ private _dataType: DataType;
+ private _displayName: string;
+ private _codeName: string;
+ private _visualizationHints: VisualizationHint[];
+
+ public Id: string;
+
+ constructor(id: string, dataType: DataType, displayName: string, codeName: string, visualizationHints: VisualizationHint[]) {
+ super();
+ this.Id = id;
+ this._dataType = dataType;
+ this._displayName = displayName;
+ this._codeName = codeName;
+ this._visualizationHints = visualizationHints;
+ }
+
+ public get DataType(): DataType {
+ return this._dataType;
+ }
+
+ public get DisplayName(): string {
+ return this._displayName.ReplaceAll("_", " ");
+ }
+
+ public get CodeName(): string {
+ return this._codeName;
+ }
+
+ public get VisualizationHints(): VisualizationHint[] {
+ return this._visualizationHints;
+ }
+
+ public Equals(other: BackendAttributeModel): boolean {
+ return this.Id === other.Id;
+ }
+
+} \ No newline at end of file
diff --git a/src/client/northstar/core/attribute/AttributeTransformationModel.ts b/src/client/northstar/core/attribute/AttributeTransformationModel.ts
new file mode 100644
index 000000000..66485183b
--- /dev/null
+++ b/src/client/northstar/core/attribute/AttributeTransformationModel.ts
@@ -0,0 +1,52 @@
+
+import { computed, observable } from "mobx";
+import { AggregateFunction } from "../../model/idea/idea";
+import { AttributeModel } from "./AttributeModel";
+import { IEquatable } from "../../utils/IEquatable";
+
+export class AttributeTransformationModel implements IEquatable {
+
+ @observable public AggregateFunction: AggregateFunction;
+ @observable public AttributeModel: AttributeModel;
+
+ constructor(attributeModel: AttributeModel, aggregateFunction: AggregateFunction = AggregateFunction.None) {
+ this.AttributeModel = attributeModel;
+ this.AggregateFunction = aggregateFunction;
+ }
+
+ @computed
+ public get PresentedName(): string {
+ var displayName = this.AttributeModel.DisplayName;
+ if (this.AggregateFunction === AggregateFunction.Count) {
+ return "count";
+ }
+ if (this.AggregateFunction === AggregateFunction.Avg) {
+ displayName = "avg(" + displayName + ")";
+ }
+ else if (this.AggregateFunction === AggregateFunction.Max) {
+ displayName = "max(" + displayName + ")";
+ }
+ else if (this.AggregateFunction === AggregateFunction.Min) {
+ displayName = "min(" + displayName + ")";
+ }
+ else if (this.AggregateFunction === AggregateFunction.Sum) {
+ displayName = "sum(" + displayName + ")";
+ }
+ else if (this.AggregateFunction === AggregateFunction.SumE) {
+ displayName = "sumE(" + displayName + ")";
+ }
+
+ return displayName;
+ }
+
+ public clone(): AttributeTransformationModel {
+ var clone = new AttributeTransformationModel(this.AttributeModel);
+ clone.AggregateFunction = this.AggregateFunction;
+ return clone;
+ }
+
+ public Equals(other: AttributeTransformationModel): boolean {
+ return this.AggregateFunction === other.AggregateFunction &&
+ this.AttributeModel.Equals(other.AttributeModel);
+ }
+} \ No newline at end of file
diff --git a/src/client/northstar/core/attribute/CalculatedAttributeModel.ts b/src/client/northstar/core/attribute/CalculatedAttributeModel.ts
new file mode 100644
index 000000000..a197c1305
--- /dev/null
+++ b/src/client/northstar/core/attribute/CalculatedAttributeModel.ts
@@ -0,0 +1,42 @@
+import { BackendAttributeModel, AttributeModel, CodeAttributeModel } from "./AttributeModel";
+import { DataType, VisualizationHint } from '../../model/idea/idea';
+
+export class CalculatedAttributeManager {
+ public static AllCalculatedAttributes: Array<AttributeModel> = new Array<AttributeModel>();
+
+ public static Clear() {
+ this.AllCalculatedAttributes = new Array<AttributeModel>();
+ }
+
+ public static CreateBackendAttributeModel(id: string, dataType: DataType, displayName: string, codeName: string, visualizationHints: VisualizationHint[]): BackendAttributeModel {
+ var filtered = this.AllCalculatedAttributes.filter(am => {
+ if (am instanceof BackendAttributeModel &&
+ am.Id === id) {
+ return true;
+ }
+ return false;
+ });
+ if (filtered.length > 0) {
+ return filtered[0] as BackendAttributeModel;
+ }
+ var newAttr = new BackendAttributeModel(id, dataType, displayName, codeName, visualizationHints);
+ this.AllCalculatedAttributes.push(newAttr);
+ return newAttr;
+ }
+
+ public static CreateCodeAttributeModel(code: string, codeName: string, visualizationHints: VisualizationHint[]): CodeAttributeModel {
+ var filtered = this.AllCalculatedAttributes.filter(am => {
+ if (am instanceof CodeAttributeModel &&
+ am.CodeName === codeName) {
+ return true;
+ }
+ return false;
+ });
+ if (filtered.length > 0) {
+ return filtered[0] as CodeAttributeModel;
+ }
+ var newAttr = new CodeAttributeModel(code, codeName, codeName.ReplaceAll("_", " "), visualizationHints);
+ this.AllCalculatedAttributes.push(newAttr);
+ return newAttr;
+ }
+} \ No newline at end of file
diff --git a/src/client/northstar/core/brusher/IBaseBrushable.ts b/src/client/northstar/core/brusher/IBaseBrushable.ts
new file mode 100644
index 000000000..87f4ba413
--- /dev/null
+++ b/src/client/northstar/core/brusher/IBaseBrushable.ts
@@ -0,0 +1,13 @@
+import { PIXIPoint } from '../../utils/MathUtil';
+import { IEquatable } from '../../utils/IEquatable';
+import { Doc } from '../../../../new_fields/Doc';
+
+export interface IBaseBrushable<T> extends IEquatable {
+ BrusherModels: Array<Doc>;
+ BrushColors: Array<number>;
+ Position: PIXIPoint;
+ Size: PIXIPoint;
+}
+export function instanceOfIBaseBrushable<T>(object: any): object is IBaseBrushable<T> {
+ return 'BrusherModels' in object;
+} \ No newline at end of file
diff --git a/src/client/northstar/core/brusher/IBaseBrusher.ts b/src/client/northstar/core/brusher/IBaseBrusher.ts
new file mode 100644
index 000000000..d2de6ed62
--- /dev/null
+++ b/src/client/northstar/core/brusher/IBaseBrusher.ts
@@ -0,0 +1,11 @@
+import { PIXIPoint } from '../../utils/MathUtil';
+import { IEquatable } from '../../utils/IEquatable';
+
+
+export interface IBaseBrusher<T> extends IEquatable {
+ Position: PIXIPoint;
+ Size: PIXIPoint;
+}
+export function instanceOfIBaseBrusher<T>(object: any): object is IBaseBrusher<T> {
+ return 'BrushableModels' in object;
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/FilterModel.ts b/src/client/northstar/core/filter/FilterModel.ts
new file mode 100644
index 000000000..6ab96b33d
--- /dev/null
+++ b/src/client/northstar/core/filter/FilterModel.ts
@@ -0,0 +1,83 @@
+import { ValueComparison } from "./ValueComparision";
+import { Utils } from "../../utils/Utils";
+import { IBaseFilterProvider } from "./IBaseFilterProvider";
+import { FilterOperand } from "./FilterOperand";
+import { HistogramField } from "../../dash-fields/HistogramField";
+import { Cast, FieldValue } from "../../../../new_fields/Types";
+import { Doc } from "../../../../new_fields/Doc";
+
+export class FilterModel {
+ public ValueComparisons: ValueComparison[];
+ constructor() {
+ this.ValueComparisons = new Array<ValueComparison>();
+ }
+
+ public Equals(other: FilterModel): boolean {
+ if (!Utils.EqualityHelper(this, other)) return false;
+ if (!this.isSame(this.ValueComparisons, (other).ValueComparisons)) return false;
+ return true;
+ }
+
+ private isSame(a: ValueComparison[], b: ValueComparison[]): boolean {
+ if (a.length !== b.length) {
+ return false;
+ }
+ for (let i = 0; i < a.length; i++) {
+ let valueComp = a[i];
+ if (!valueComp.Equals(b[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public ToPythonString(): string {
+ return "(" + this.ValueComparisons.map(vc => vc.ToPythonString()).join("&&") + ")";
+ }
+
+ public static And(filters: string[]): string {
+ let ret = filters.filter(f => f !== "").join(" && ");
+ return ret;
+ }
+ public static GetFilterModelsRecursive(baseOperation: IBaseFilterProvider, visitedFilterProviders: Set<IBaseFilterProvider>, filterModels: FilterModel[], isFirst: boolean): string {
+ let ret = "";
+ visitedFilterProviders.add(baseOperation);
+ let filtered = baseOperation.FilterModels.filter(fm => fm && fm.ValueComparisons.length > 0);
+ if (!isFirst && filtered.length > 0) {
+ filterModels.push(...filtered);
+ ret = "(" + baseOperation.FilterModels.filter(fm => fm !== null).map(fm => fm.ToPythonString()).join(" || ") + ")";
+ }
+ if (Utils.isBaseFilterConsumer(baseOperation) && baseOperation.Links) {
+ let children = new Array<string>();
+ let linkedGraphNodes = baseOperation.Links;
+ linkedGraphNodes.map(linkVm => {
+ let filterDoc = FieldValue(Cast(linkVm.linkedFrom, Doc));
+ if (filterDoc) {
+ let filterHistogram = Cast(filterDoc.data, HistogramField);
+ if (filterHistogram) {
+ if (!visitedFilterProviders.has(filterHistogram.HistoOp)) {
+ let child = FilterModel.GetFilterModelsRecursive(filterHistogram.HistoOp, visitedFilterProviders, filterModels, false);
+ if (child !== "") {
+ // if (linkVm.IsInverted) {
+ // child = "! " + child;
+ // }
+ children.push(child);
+ }
+ }
+ }
+ }
+ });
+
+ let childrenJoined = children.join(baseOperation.FilterOperand === FilterOperand.AND ? " && " : " || ");
+ if (children.length > 0) {
+ if (ret !== "") {
+ ret = "(" + ret + " && (" + childrenJoined + "))";
+ }
+ else {
+ ret = "(" + childrenJoined + ")";
+ }
+ }
+ }
+ return ret;
+ }
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/FilterOperand.ts b/src/client/northstar/core/filter/FilterOperand.ts
new file mode 100644
index 000000000..2e8e8d6a0
--- /dev/null
+++ b/src/client/northstar/core/filter/FilterOperand.ts
@@ -0,0 +1,5 @@
+export enum FilterOperand
+{
+ AND,
+ OR
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/FilterType.ts b/src/client/northstar/core/filter/FilterType.ts
new file mode 100644
index 000000000..9adbc087f
--- /dev/null
+++ b/src/client/northstar/core/filter/FilterType.ts
@@ -0,0 +1,6 @@
+export enum FilterType
+{
+ Filter,
+ Brush,
+ Slice
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/IBaseFilterConsumer.ts b/src/client/northstar/core/filter/IBaseFilterConsumer.ts
new file mode 100644
index 000000000..e7549d113
--- /dev/null
+++ b/src/client/northstar/core/filter/IBaseFilterConsumer.ts
@@ -0,0 +1,12 @@
+import { FilterOperand } from '../filter/FilterOperand';
+import { IEquatable } from '../../utils/IEquatable';
+import { Doc } from '../../../../new_fields/Doc';
+
+export interface IBaseFilterConsumer extends IEquatable {
+ FilterOperand: FilterOperand;
+ Links: Doc[];
+}
+
+export function instanceOfIBaseFilterConsumer(object: any): object is IBaseFilterConsumer {
+ return 'FilterOperand' in object;
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/IBaseFilterProvider.ts b/src/client/northstar/core/filter/IBaseFilterProvider.ts
new file mode 100644
index 000000000..fc3301b11
--- /dev/null
+++ b/src/client/northstar/core/filter/IBaseFilterProvider.ts
@@ -0,0 +1,8 @@
+import { FilterModel } from '../filter/FilterModel';
+
+export interface IBaseFilterProvider {
+ FilterModels: Array<FilterModel>;
+}
+export function instanceOfIBaseFilterProvider(object: any): object is IBaseFilterProvider {
+ return 'FilterModels' in object;
+} \ No newline at end of file
diff --git a/src/client/northstar/core/filter/ValueComparision.ts b/src/client/northstar/core/filter/ValueComparision.ts
new file mode 100644
index 000000000..65687a82b
--- /dev/null
+++ b/src/client/northstar/core/filter/ValueComparision.ts
@@ -0,0 +1,78 @@
+import { Predicate } from '../../model/idea/idea';
+import { Utils } from '../../utils/Utils';
+import { AttributeModel } from '../attribute/AttributeModel';
+
+export class ValueComparison {
+
+ public attributeModel: AttributeModel;
+ public Value: any;
+ public Predicate: Predicate;
+
+ public constructor(attributeModel: AttributeModel, predicate: Predicate, value: any) {
+ this.attributeModel = attributeModel;
+ this.Value = value;
+ this.Predicate = predicate;
+ }
+
+ public Equals(other: Object): boolean {
+ if (!Utils.EqualityHelper(this, other)) {
+ return false;
+ }
+ if (this.Predicate !== (other as ValueComparison).Predicate) {
+ return false;
+ }
+ let isComplex = (typeof this.Value === "object");
+ if (!isComplex && this.Value !== (other as ValueComparison).Value) {
+ return false;
+ }
+ if (isComplex && !this.Value.Equals((other as ValueComparison).Value)) {
+ return false;
+ }
+ return true;
+ }
+
+ public ToPythonString(): string {
+ var op = "";
+ switch (this.Predicate) {
+ case Predicate.EQUALS:
+ op = "==";
+ break;
+ case Predicate.GREATER_THAN:
+ op = ">";
+ break;
+ case Predicate.GREATER_THAN_EQUAL:
+ op = ">=";
+ break;
+ case Predicate.LESS_THAN:
+ op = "<";
+ break;
+ case Predicate.LESS_THAN_EQUAL:
+ op = "<=";
+ break;
+ default:
+ op = "==";
+ break;
+ }
+
+ var val = this.Value.toString();
+ if (typeof this.Value === 'string' || this.Value instanceof String) {
+ val = "\"" + val + "\"";
+ }
+ var ret = " ";
+ var rawName = this.attributeModel.CodeName;
+ switch (this.Predicate) {
+ case Predicate.STARTS_WITH:
+ ret += rawName + " != null && " + rawName + ".StartsWith(" + val + ") ";
+ return ret;
+ case Predicate.ENDS_WITH:
+ ret += rawName + " != null && " + rawName + ".EndsWith(" + val + ") ";
+ return ret;
+ case Predicate.CONTAINS:
+ ret += rawName + " != null && " + rawName + ".Contains(" + val + ") ";
+ return ret;
+ default:
+ ret += rawName + " " + op + " " + val + " ";
+ return ret;
+ }
+ }
+} \ No newline at end of file