Skip to content

Commit

Permalink
Add debug control
Browse files Browse the repository at this point in the history
  • Loading branch information
dyang415 committed Sep 29, 2023
1 parent 247a009 commit 6f47a96
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/main-dashboard/MainDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export default function MainDashboard() {
];
}
}

return (
<Sidebar
elements={[
Expand Down
40 changes: 39 additions & 1 deletion frontend/src/components/main-dashboard/SidebarReportConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Button, Flex, Text } from "@tremor/react";
import { Button, Divider, Flex, Text } from "@tremor/react";
import { useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import getSettings from "../../common/server-data/settings";
import { Filter } from "../../common/types";
import { RootState } from "../../store";
import { setShouldUsePScore } from "../../store/comparisonInsight";
import { Schema } from "../../types/data-source";
import { DateRangeRelatedData } from "../../types/report-config";
import {
Expand Down Expand Up @@ -34,6 +38,11 @@ export function SidebarReportConfig({
dateRangeData,
onSubmit,
}: Props) {
const dispatch = useDispatch();
const shouldUsePScore = useSelector(
(state: RootState) => state.comparisonInsight.shouldUsePScore
);

const [localFilters, setLocalFilters] = useState<Filter[]>(filters);
const [localDimensions, setLocalDimensions] = useState<string[]>(dimensions);
const [localBaseDateRangeData, setLocalBaseDateRangeData] =
Expand Down Expand Up @@ -82,6 +91,34 @@ export function SidebarReportConfig({
hasChangeInComparisonDateRange
);
}

function renderDebugControl() {
if (!getSettings().showDebugInfo) {
return null;
}

return (
<>
<Divider className="py-0 my-0" />
<Text color="red">DEBUG CONTROL</Text>
<Flex>
<Text>Use PScore</Text>
<label className="label cursor-pointer content-center">
<input
type="checkbox"
className="toggle"
onChange={() => {
dispatch(setShouldUsePScore(!shouldUsePScore));
}}
checked={shouldUsePScore}
/>
</label>
</Flex>
<Divider className="py-0 my-0" />
</>
);
}

return (
<>
<Flex
Expand Down Expand Up @@ -129,6 +166,7 @@ export function SidebarReportConfig({
}
ref={filtersDropDownRef}
/>
{renderDebugControl()}
<Flex justifyContent="end" className="gap-1">
<Button
disabled={!hasLocalChange() || localDimensions.length === 0}
Expand Down
31 changes: 25 additions & 6 deletions frontend/src/store/comparisonInsight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ComparisonInsightState {
groupRows: boolean;
mode: "impact" | "outlier";
sensitivity: "low" | "medium" | "high";
shouldUsePScore: boolean;
}

const THRESHOLD = {
Expand Down Expand Up @@ -186,7 +187,8 @@ function buildRowStatusMap(
metric: InsightMetric,
groupRows: boolean,
mode: "impact" | "outlier" = "impact",
sensitivity: "low" | "medium" | "high" = "medium"
sensitivity: "low" | "medium" | "high" = "medium",
shouldUsePScore: boolean
): [
{
[key: string]: RowStatus;
Expand All @@ -203,7 +205,8 @@ function buildRowStatusMap(
const changeDev = sliceInfo.changeDev;
return (
mode === "impact" ||
(changeDev > THRESHOLD[sensitivity] && sliceInfo.confidence < 0.05)
(changeDev > THRESHOLD[sensitivity] &&
(!shouldUsePScore || sliceInfo.confidence < 0.05))
);
});

Expand Down Expand Up @@ -423,6 +426,7 @@ const initialState: ComparisonInsightState = {
groupRows: true,
mode: "outlier",
sensitivity: "medium",
shouldUsePScore: true,
};

export const comparisonMetricsSlice = createSlice({
Expand Down Expand Up @@ -454,7 +458,8 @@ export const comparisonMetricsSlice = createSlice({
state.analyzingMetrics,
true,
state.mode,
state.sensitivity
state.sensitivity,
state.shouldUsePScore
);
state.tableRowStatusByDimension = buildRowStatusByDimensionMap(
state.analyzingMetrics
Expand All @@ -470,7 +475,8 @@ export const comparisonMetricsSlice = createSlice({
state.analyzingMetrics,
true,
state.mode,
state.sensitivity
state.sensitivity,
state.shouldUsePScore
);
},
setSensitivity: (
Expand All @@ -482,7 +488,8 @@ export const comparisonMetricsSlice = createSlice({
state.analyzingMetrics,
true,
state.mode,
state.sensitivity
state.sensitivity,
state.shouldUsePScore
);
},
toggleRow: (
Expand Down Expand Up @@ -549,7 +556,18 @@ export const comparisonMetricsSlice = createSlice({
state.analyzingMetrics,
state.groupRows,
state.mode,
state.sensitivity
state.sensitivity,
state.shouldUsePScore
);
},
setShouldUsePScore: (state, action: PayloadAction<boolean>) => {
state.shouldUsePScore = action.payload;
[state.tableRowStatus, state.tableRowCSV] = buildRowStatusMap(
state.analyzingMetrics,
state.groupRows,
state.mode,
state.sensitivity,
state.shouldUsePScore
);
},
},
Expand All @@ -564,6 +582,7 @@ export const {
toggleGroupRows,
setMode,
setSensitivity,
setShouldUsePScore,
} = comparisonMetricsSlice.actions;

export default comparisonMetricsSlice.reducer;

0 comments on commit 6f47a96

Please sign in to comment.