Skip to content

Commit

Permalink
fix(new feature): debug time mode
Browse files Browse the repository at this point in the history
  • Loading branch information
briankpw committed Jun 20, 2019
1 parent 1db882e commit 7ba0e14
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ Pixie Transformer is transforming a Raw/Response JSON Payload into your expected
- Dimension(column: string, category: TYPE, rename?: string, defaultValue?: any, isIncremental: boolean)
- Measurement(row: string, condition: Array<Condition>, dimensionListBind: boolean, float?: number, formula?: string, rename?: string, defaultValue?: any, isIncremental: boolean)
- Condition(key: string, condition: CONDITION, match: string | number, rename?: string, toUpperCase?: boolean)
- Aggregate(data: any, dimension: Dimension, measurement: Array<Measurement>, dimensionList?: Array<Dimension>)
- Sort (sortType: SORT, sortProperty?: any, naturalSort?: boolean)
- Pixie (aggregate?: Aggregate, sort?: Sort, debug?: boolean)

### Enum

Expand Down
4 changes: 3 additions & 1 deletion dist/lib/pixie.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export declare class Pixie {
private _sortProperty;
private _naturalSort;
private _isSorted;
constructor(aggregateBinding?: Aggregate, sortBinding?: Sort);
private _debug;
constructor(aggregateBinding?: Aggregate, sortBinding?: Sort, debug?: boolean);
getPixie(): any;
getPixieSort(): any;
private debugging;
}
28 changes: 24 additions & 4 deletions dist/lib/pixie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
const sort_1 = require("./interface/sort");
const aggregate_1 = require("./interface/aggregate");
class Pixie {
constructor(aggregateBinding, sortBinding) {
constructor(aggregateBinding, sortBinding, debug = false) {
this._measurement = [];
this._dimension = new aggregate_1.Dimension('null', aggregate_1.TYPE.ANY);
this._sortType = sort_1.SORT.NONE;
this._isSorted = false;
this._debug = false;
if (aggregateBinding !== undefined) {
this._data = aggregateBinding.data;
this._measurement = aggregateBinding.measurement;
Expand All @@ -19,18 +20,37 @@ class Pixie {
this._sortProperty = sortBinding.sortProperty;
this._naturalSort = sortBinding.naturalSort;
}
this._debug = debug;
}
getPixie() {
const sortData = this.getPixieSort();
return aggregate_1.Pixing(sortData, this._dimension, this._measurement, this._dimensionList);
this.debugging('getPixie');
const pixieData = aggregate_1.Pixing(sortData, this._dimension, this._measurement, this._dimensionList);
this.debugging('getPixie', false);
return pixieData;
}
getPixieSort() {
this.debugging('getPixieSort');
let sortData;
if (this._isSorted) {
return this._data;
sortData = this._data;
}
else {
this._isSorted = true;
return sort_1.Sorting(this._data, this._sortType, this._sortProperty, this._naturalSort);
sortData = sort_1.Sorting(this._data, this._sortType, this._sortProperty, this._naturalSort);
}
this.debugging('getPixieSort', false);
return sortData;
}
// Debug
debugging(title, start = true) {
if (this._debug) {
if (start) {
console.time(title);
}
else {
console.timeEnd(title);
}
}
}
}
Expand Down
30 changes: 26 additions & 4 deletions lib/pixie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export class Pixie {
private _sortProperty: Array<string> | undefined;
private _naturalSort: boolean | undefined;
private _isSorted: boolean = false;
private _debug: boolean = false;

constructor(aggregateBinding?: Aggregate, sortBinding?: Sort) {
constructor(aggregateBinding?: Aggregate, sortBinding?: Sort, debug: boolean = false) {
if (aggregateBinding !== undefined) {
this._data = aggregateBinding.data;
this._measurement = aggregateBinding.measurement;
Expand All @@ -27,19 +28,40 @@ export class Pixie {
this._sortProperty = sortBinding.sortProperty;
this._naturalSort = sortBinding.naturalSort;
}

this._debug = debug;
}

getPixie() {
const sortData = this.getPixieSort();
return Pixing(sortData, this._dimension, this._measurement, this._dimensionList);

this.debugging('getPixie');
const pixieData = Pixing(sortData, this._dimension, this._measurement, this._dimensionList);
this.debugging('getPixie', false);
return pixieData;
}

getPixieSort() {
this.debugging('getPixieSort');
let sortData;
if (this._isSorted) {
return this._data;
sortData = this._data;
} else {
this._isSorted = true;
return Sorting(this._data, this._sortType, this._sortProperty, this._naturalSort);
sortData = Sorting(this._data, this._sortType, this._sortProperty, this._naturalSort);
}
this.debugging('getPixieSort', false);
return sortData;
}

// Debug
private debugging(title: string, start = true) {
if (this._debug) {
if (start) {
console.time(title);
} else {
console.timeEnd(title);
}
}
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@types/mathjs": "^5.0.0",
"@types/underscore": "^1.8.9",
"mathjs": "^6.0.2",
"mathjs": "^5.10.3",
"redux": "^4.0.1",
"underscore": "^1.9.1"
},
Expand Down

0 comments on commit 7ba0e14

Please sign in to comment.