Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Jun 25, 2021
1 parent 3ab3cdd commit c41817f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitationsxw
* under the License.
*/
export * from './resample';
export * from './rollingWindow';
export * from './timeCompare';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitationsxw
* under the License.
*/
import { getMetricLabel, ensureIsArray, QueryFormData, QueryObject } from '@superset-ui/core';

export function resampleTransform(formData: QueryFormData, queryObject: QueryObject): QueryObject {
return queryObject;
}

export default {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable camelcase */
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitationsxw
* under the License.
*/
import { ensureIsArray, QueryFormData, QueryObject } from '@superset-ui/core';

function ensureIsInt<T>(value: T, defaultValue: number): number {
return Number.isNaN(parseInt(String(value), 10)) ? defaultValue : parseInt(String(value), 10);
}

export function rollingWindowTransform(
formData: QueryFormData,
queryObject: QueryObject,
): QueryObject {
if (formData.rolling_type === 'None' || !formData.rolling_type) {
return queryObject;
}

const post_processing = ensureIsArray(queryObject.post_processing);
const columns = Object.fromEntries(
formData.metrics?.map(metric => {
if (typeof metric === 'string') {
return [metric, metric];
}
return [metric.label, metric.label];
}) || [],
);
if (formData.rolling_type === 'cumsum') {
// rolling must be the first operation(before pivot or other transforms)
post_processing.unshift({
operation: 'cum',
options: {
operator: 'sum',
columns,
},
});
}

if (['sum', 'mean', 'std'].includes(formData.rolling_type)) {
// same before
post_processing.unshift({
operation: 'rolling',
options: {
rolling_type: formData.rolling_type,
window: ensureIsInt(formData.rolling_periods, 1),
min_periods: ensureIsInt(formData.min_periods, 0),
columns,
},
});
}
return { ...queryObject, post_processing };
}

export default {};
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,6 @@ import { getMetricLabel, ensureIsArray, QueryFormData, QueryObject } from '@supe

const TIME_COMPARISION = '__';

function ensureIsInt<T>(value: T, defaultValue: number): number {
return Number.isNaN(parseInt(String(value), 10)) ? defaultValue : parseInt(String(value), 10);
}

export function rollingWindowTransform(
formData: QueryFormData,
queryObject: QueryObject,
): QueryObject {
if (formData.rolling_type === 'None' || !formData.rolling_type) {
return queryObject;
}

const post_processing = ensureIsArray(queryObject.post_processing);
const columns = Object.fromEntries(
formData.metrics?.map(metric => {
if (typeof metric === 'string') {
return [metric, metric];
}
return [metric.label, metric.label];
}) || [],
);
if (formData.rolling_type === 'cumsum') {
// rolling must be the first operation(before pivot or other transforms)
post_processing.unshift({
operation: 'cum',
options: {
operator: 'sum',
columns,
},
});
}

if (['sum', 'mean', 'std'].includes(formData.rolling_type)) {
// same before
post_processing.unshift({
operation: 'rolling',
options: {
rolling_type: formData.rolling_type,
window: ensureIsInt(formData.rolling_periods, 1),
min_periods: ensureIsInt(formData.min_periods, 0),
columns,
},
});
}
return { ...queryObject, post_processing };
}

export function timeCompareTransform(
formData: QueryFormData,
queryObject: QueryObject,
Expand Down Expand Up @@ -112,7 +65,7 @@ export function timeCompareTransform(
};
}
if (comparisonType === 'values') {
return { ...queryObject, post_processing, time_offset: timeCompare };
return { ...queryObject, post_processing, time_offsets: timeCompare };
}

const timeCompareProcessing = [
Expand All @@ -127,11 +80,7 @@ export function timeCompareTransform(
},
].concat(post_processing);

return { ...queryObject, post_processing: timeCompareProcessing, time_offset: timeCompare };
}

export function resampleTransform(formData: QueryFormData, queryObject: QueryObject): QueryObject {
return queryObject;
return { ...queryObject, post_processing: timeCompareProcessing, time_offsets: timeCompare };
}

export default {};
2 changes: 1 addition & 1 deletion packages/superset-ui-chart-controls/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
export * from './selectOptions';
export * from './D3Formatting';
export * from './expandControlConfig';
export * from './AdvancedAnalyticsTransform';
export * from './advancedAnalytics';
export { default as mainMetric } from './mainMetric';
export { default as columnChoices } from './columnChoices';

0 comments on commit c41817f

Please sign in to comment.