Skip to content

Commit

Permalink
Make max num of dimensions configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dyang415 committed Oct 2, 2023
1 parent 01fc26e commit 8709576
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 13 deletions.
9 changes: 6 additions & 3 deletions backend/app/insight/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ def parse_data(data):
baseline_start, baseline_end, comparison_start, comparison_end, date_column, date_column_type = InsightApi.parse_date_info(data)
group_by_columns = data['groupByColumns']
filters = InsightApi.parse_filters(data)
num_max_dimensions = data['maxNumDimensions']

return (
baseline_start, baseline_end, comparison_start, comparison_end, date_column, date_column_type, group_by_columns, filters
baseline_start, baseline_end, comparison_start, comparison_end, date_column, date_column_type, group_by_columns, filters, num_max_dimensions
)

@staticmethod
Expand Down Expand Up @@ -186,7 +187,8 @@ def get_insight(self):
data = request.get_json()
file_id = data['fileId']
expected_value = data['expectedValue']
(baselineStart, baselineEnd, comparisonStart, comparisonEnd, date_column, date_column_type, group_by_columns, filters) = self.parse_data(data)
(baselineStart, baselineEnd, comparisonStart, comparisonEnd, date_column, date_column_type, group_by_columns, filters,
max_num_dimensions) = self.parse_data(data)

metric_column = data['metricColumn']
metric = self.parse_metrics(metric_column)
Expand All @@ -204,7 +206,8 @@ def get_insight(self):
group_by_columns,
[metric],
expected_value,
filters
filters,
max_num_dimensions
)
return insight_builder.build()
except EmptyDataFrameError:
Expand Down
10 changes: 9 additions & 1 deletion backend/app/insight/services/insight_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self,
metrics: List[Metric],
expected_value: float,
filters: list[Filter] = None,
max_num_dimensions: int = 3
):
self.df = data
self.group_by_columns = group_by_columns
Expand Down Expand Up @@ -65,8 +66,15 @@ def __init__(self,
self.aggregation_expressions = build_aggregation_expressions(self.metrics)
self.overall_aggregated_df = self.gen_agg_df()

if max_num_dimensions > 3:
self.max_num_dimensions = 3
elif max_num_dimensions < 1:
self.max_num_dimensions = 1
else:
self.max_num_dimensions = max_num_dimensions

column_combinations_list = []
for i in range(1, min(3, len(self.group_by_columns)) + 1):
for i in range(1, min(self.max_num_dimensions, len(self.group_by_columns)) + 1):
column_combinations_list.extend(
combinations(self.group_by_columns, i))

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/main-dashboard/MainDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface RouterState {
};
filters: Filter[];
expectedValue: number;
maxNumDimensions: number;
}

export default function MainDashboard() {
Expand All @@ -99,6 +100,7 @@ export default function MainDashboard() {
schema,
rowCountByColumn,
filters,
maxNumDimensions,
} = routerState as RouterState;

const {
Expand Down Expand Up @@ -141,6 +143,7 @@ export default function MainDashboard() {
groupByColumns,
expectedValue,
filters,
maxNumDimensions,
});

dispatch(updateMetrics(metricInsights));
Expand Down Expand Up @@ -266,6 +269,7 @@ export default function MainDashboard() {
targetDirection,
expectedValue,
filters: newFilters,
maxNumDimensions,
},
});
navigate(0);
Expand Down Expand Up @@ -381,6 +385,7 @@ export default function MainDashboard() {
targetDirection,
expectedValue,
filters: newFilters,
maxNumDimensions,
},
});
navigate(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function BigqueryBasedReportConfig({ schema }: Props) {
groupByColumns: string[],
dateRangeData: DateRangeRelatedData,
targetDirection: TargetDirection,
expectedValue: number
expectedValue: number,
maxNumDimensions: number
) => {
navigate("/dashboard", {
state: {
Expand All @@ -41,6 +42,7 @@ export default function BigqueryBasedReportConfig({ schema }: Props) {
targetDirection,
expectedValue,
filters: [],
maxNumDimensions,
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export default function CSVBasedReportConfig({
groupByColumns: string[],
dateRangeData: DateRangeRelatedData,
targetDirection: TargetDirection,
expectedValue: number
expectedValue: number,
maxNumDimensions: number
) => {
navigate("/dashboard", {
state: {
Expand All @@ -204,6 +205,7 @@ export default function CSVBasedReportConfig({
targetDirection,
expectedValue,
filters: [],
maxNumDimensions,
},
});
};
Expand Down
38 changes: 31 additions & 7 deletions frontend/src/components/uploader/report-config/ReportConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
TargetDirection,
} from "../../../types/report-config";
import DatePicker, { DateRangeData } from "../DatePicker";
import { ExpectedChangeInput } from "../ExpectedChangeInput";
import MultiSelector from "../MultiSelector";
import { ExpectedChangeInput } from "../NumberInput";
import SingleSelector from "../SingleSelector";
import MetricConfig from "./MetricConfig";

Expand All @@ -42,7 +42,8 @@ type Props = {
groupByColumns: string[],
dateRangeData: DateRangeRelatedData,
targetDirection: TargetDirection,
expectedValue: number
expectedValue: number,
maxNumDimensions: number
) => Promise<void>;
};

Expand All @@ -62,6 +63,7 @@ function ReportConfig({
const [groupByColumns, setGroupByColumns] = useState<string[]>([]);
const [metricColumn, setMetricColumn] = useState<MetricColumn>();
const [expectedValue, setExpectedValue] = useState<number>();
const [maxNumDimensions, setMaxNumDimensions] = useState<number>(3);
const debugMode = getServerData().settings.showDebugInfo;

const [comparisonDateRangeData, setComparisonDateRangeData] =
Expand Down Expand Up @@ -340,10 +342,31 @@ function ReportConfig({
</Title>
</AccordionHeader>
<AccordionBody className="overflow-auto">
<ExpectedChangeInput
defaultValue={expectedValue}
onValueChange={(v) => setExpectedValue(parseFloat(v) / 100)}
/>
<Flex flexDirection="col" className="gap-y-4">
<ExpectedChangeInput
defaultValue={expectedValue}
onValueChange={(v) => setExpectedValue(parseFloat(v) / 100)}
/>
<SingleSelector
title={
<Text className="pr-4 text-black">
Max number of dimensions
</Text>
}
labels={["1", "2", "3"]}
values={["1", "2", "3"]}
selectedValue={maxNumDimensions.toString()}
onValueChange={(value) => setMaxNumDimensions(parseInt(value))}
instruction={
<Text>
Date range comparison report compares between two date
ranges on the selected metric and aggregated of the selected
group by columns. Currently this is the only report type we
support.
</Text>
}
/>
</Flex>
</AccordionBody>
</Accordion>
</div>
Expand All @@ -367,7 +390,8 @@ function ReportConfig({
rowCountByDateColumn,
},
targetDirection,
expectedValue ?? 0
expectedValue ?? 0,
maxNumDimensions
);
}}
disabled={!canSubmit()}
Expand Down

0 comments on commit 8709576

Please sign in to comment.