Skip to content

Commit

Permalink
add a button to prefill doordash and insurance data
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyl committed Sep 19, 2023
1 parent 083e1f5 commit fa3f674
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function BigqueryBasedReportConfig({ schema }: Props) {
schema={schema}
dataSourceType="bigquery"
rowCountByColumn={rowCountByColumn}
prefill={() => {}}
onSubmit={onSubmit}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "../../../types/report-config";
import ReportConfig from "./ReportConfig";

const sampleDataPrefills: PrefillConfig = {
const commercePrefills: PrefillConfig = {
metricColumn: {
aggregationOption: "nunique",
singularMetric: {
Expand Down Expand Up @@ -39,6 +39,87 @@ const sampleDataPrefills: PrefillConfig = {
},
};

const doorDashPrefills: PrefillConfig = {
metricColumn: {
aggregationOption: "ratio",
ratioMetric: {
metricName: "cancelation_rate",
numerator: {
aggregationMethod: "nunique",
columnName: "order_id",
filter: {
column: "order_status",
value: "canceled",
}
},
denominator: {
aggregationMethod: "nunique",
columnName: "order_id",
},
},
},
dateColumn: 'order_date',
groupByColumns: [
"order_canceled_by",
"age_group",
"has_dash_pass",
"city",
"state",
"gender",
"merchant",
"store",
"vertical",
"tip_percentage",
"channel",
"hour_of_the_day",
"promo_code",
"payment_method"
],
baseDateRange: {
from: createNewDateWithBrowserTimeZone("2023-08-14"),
to: createNewDateWithBrowserTimeZone("2023-08-20"),
},
comparisonDateRange: {
from: createNewDateWithBrowserTimeZone("2023-08-21"),
to: createNewDateWithBrowserTimeZone("2023-08-27"),
},
}

const insurancePrefills: PrefillConfig = {
metricColumn: {
aggregationOption: "sum",
singularMetric: {
columnName: "total_claim_amount",
}
},
groupByColumns: [
"age_group",
"insured_gender",
"insured_education_level",
"insured_occupation",
"insured_hobbies",
"insured_relationship",
"auto_make",
"auto_year",
"incident_type",
"incident_severity",
"incident_state",
"incident_city",
"property_damage",
"police_report_available",
"authorities_contacted"
],
dateColumn: 'incident_date',
baseDateRange: {
from: createNewDateWithBrowserTimeZone("2023-07-04"),
to: createNewDateWithBrowserTimeZone("2023-07-31"),
},
comparisonDateRange: {
from: createNewDateWithBrowserTimeZone("2023-08-01"),
to: createNewDateWithBrowserTimeZone("2023-08-28"),
},
}

interface Props {
schema: CSVSchema;
prefillWithSampleData: boolean;
Expand All @@ -56,6 +137,21 @@ export default function CSVBasedReportConfig({
const [rowCountByColumn, setRowCountByColumn] = useState<{
[key: string]: number;
}>({});
const [prefillConfig, setPrefillConfig] = useState<PrefillConfig | undefined>(undefined);

const prefill = (sample: "doordash" | "insurance") => {
if (sample === "doordash") {
setPrefillConfig(doorDashPrefills);
} else if (sample === "insurance") {
setPrefillConfig(insurancePrefills);
}
}

useEffect(() => {
if (prefillWithSampleData) {
setPrefillConfig(commercePrefills);
}
}, [prefillWithSampleData]);

useEffect(() => {
async function calculateCountByDateAndColumn() {
Expand Down Expand Up @@ -118,7 +214,8 @@ export default function CSVBasedReportConfig({
dataSourceType="csv"
rowCountByColumn={rowCountByColumn}
rowCountByDateColumn={rowCountByDateAndColumn}
prefilledConfigs={prefillWithSampleData ? sampleDataPrefills : undefined}
prefilledConfigs={prefillConfig}
prefill={prefill}
onSubmit={onSubmit}
/>
);
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/uploader/report-config/ReportConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Title,
} from "@tremor/react";
import { useEffect, useState } from "react";
import { getServerData } from "../../../common/server-data/server-data-loader";
import { useTracking } from "../../../common/tracking";
import { DataSourceType, Schema } from "../../../types/data-source";
import {
Expand All @@ -33,6 +34,7 @@ type Props = {
rowCountByColumn: RowCountByColumn;
rowCountByDateColumn?: RowCountByDateAndColumn;
prefilledConfigs?: PrefillConfig;
prefill: (sample: "doordash" | "insurance") => void;
onSubmit: (
dateColumn: string,
dateColumnType: string,
Expand All @@ -51,6 +53,7 @@ function ReportConfig({
rowCountByColumn,
rowCountByDateColumn,
prefilledConfigs,
prefill,
onSubmit,
}: Props) {
const { trackEvent } = useTracking();
Expand All @@ -60,6 +63,7 @@ function ReportConfig({
const [groupByColumns, setGroupByColumns] = useState<string[]>([]);
const [metricColumn, setMetricColumn] = useState<MetricColumn>();
const [expectedValue, setExpectedValue] = useState<number>();
const debugMode = getServerData().settings.showDebugInfo;

const [comparisonDateRangeData, setComparisonDateRangeData] =
useState<DateRangeData>({
Expand Down Expand Up @@ -222,6 +226,24 @@ function ReportConfig({
return (
<Card className="max-w-6xl mx-auto">
<Title>Report Config</Title>
{
debugMode && (
<Flex
flexDirection="row"
justifyContent="center"
alignItems="start"
className="gap-y-2 p-2 gap-4"
>
<Button className="mb-4" onClick={() => { prefill("doordash") }} >
Doordash
</Button>

<Button className="mb-4" onClick={() => { prefill("insurance") }} >
Insurance
</Button>
</Flex>
)}

<Divider />
<div className="flex flex-col gap-4">
<SingleSelector
Expand Down

0 comments on commit fa3f674

Please sign in to comment.