Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 4 additions & 69 deletions frontend/src/lib/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { error } from '@sveltejs/kit';
import type { FeatureResponse, JoinTimeSeriesResponse } from '$lib/types/Model/Model';
import type {
Join,
GroupBy,
Model,
StagingQuery,
IJoinDriftRequestArgs,
IJoinDriftResponseArgs,
ITileSummarySeries,
IJoinSummaryRequestArgs
IJoinSummaryRequestArgs,
IJoinDriftResponse
} from '$lib/types/codegen';
import { ConfType, DriftMetric } from '$lib/types/codegen';
import type { ConfListResponse } from '$lib/types/codegen/ConfListResponse';
Expand Down Expand Up @@ -68,70 +67,6 @@ export class Api {
return this.#send<ConfListResponse>(`search?${params.toString()}`);
}

async getJoinTimeseries({
joinId,
startTs,
endTs,
metricType = 'drift',
metrics = 'null',
offset = '10h',
algorithm = 'psi'
}: {
joinId: string;
startTs: number;
endTs: number;
metricType?: string;
metrics?: string;
offset?: string;
algorithm?: string;
}) {
const params = new URLSearchParams({
startTs: startTs.toString(),
endTs: endTs.toString(),
metricType,
metrics,
offset,
algorithm
});

return this.#send<JoinTimeSeriesResponse>(`join/${joinId}/timeseries?${params.toString()}`);
}

async getFeatureTimeseries({
joinId,
featureName,
startTs,
endTs,
metricType = 'drift',
metrics = 'null',
offset = '10h',
algorithm = 'psi',
granularity = 'aggregates'
}: {
joinId: string;
featureName: string;
startTs: number;
endTs: number;
metricType?: string;
metrics?: string;
offset?: string;
algorithm?: string;
granularity?: string;
}) {
const params = new URLSearchParams({
startTs: startTs.toString(),
endTs: endTs.toString(),
metricType,
metrics,
offset,
algorithm,
granularity
});
return this.#send<FeatureResponse>(
`join/${joinId}/feature/${featureName}/timeseries?${params.toString()}`
);
}

async getConfList(type: ConfType): Promise<ConfListResponse> {
const params = new URLSearchParams({
confType: ConfType[type]
Expand Down Expand Up @@ -168,7 +103,7 @@ export class Api {
offset,
algorithm: DriftMetric[algorithm]
});
return this.#send<IJoinDriftResponseArgs>(`join/${name}/drift?${params.toString()}`);
return this.#send<IJoinDriftResponse>(`join/${name}/drift?${params.toString()}`);
}

async getColumnDrift({
Expand All @@ -185,7 +120,7 @@ export class Api {
offset,
algorithm: DriftMetric[algorithm]
});
return this.#send<IJoinDriftResponseArgs>(
return this.#send<IJoinDriftResponse>(
`join/${name}/column/${columnName}/drift?${params.toString()}`
);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/ChartControls.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import ResetZoomButton from '$lib/components/ResetZoomButton.svelte';
import MetricTypeToggle from '$lib/components/MetricTypeToggle.svelte';
import DriftMetricToggle from '$lib/components/DriftMetricToggle.svelte';
import DateRangeSelector from '$lib/components/DateRangeSelector.svelte';
import ActionButtons from '$lib/components/ActionButtons.svelte';
import * as Alert from '$lib/components/ui/alert/index.js';
Expand Down Expand Up @@ -46,7 +46,7 @@
{/if}
<DateRangeSelector />
{#if context === 'drift'}
<MetricTypeToggle />
<DriftMetricToggle />
{/if}
</div>

Expand Down
26 changes: 26 additions & 0 deletions frontend/src/lib/components/DriftMetricToggle.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
import { queryParameters } from 'sveltekit-search-params';

import { Button } from '$lib/components/ui/button';
import { DRIFT_METRIC_LABELS, getDriftMetricParamsConfig } from '$lib/util/drift-metric';
import { enumValues } from '@layerstack/utils';
import { DriftMetric } from '$lib/types/codegen';

const params = queryParameters(getDriftMetricParamsConfig(), {
pushHistory: false,
showDefaults: false
});
</script>

<div class="flex space-x-[1px]">
{#each enumValues(DriftMetric) as value}
<Button
variant={params.metric === value ? 'default' : 'secondary'}
size="sm"
on:click={() => (params.metric = value)}
class="first:rounded-r-none last:rounded-l-none [&:not(:first-child):not(:last-child)]:rounded-none"
>
{DRIFT_METRIC_LABELS[value as DriftMetric]}
</Button>
{/each}
</div>
28 changes: 0 additions & 28 deletions frontend/src/lib/components/MetricTypeToggle.svelte

This file was deleted.

25 changes: 15 additions & 10 deletions frontend/src/lib/components/charts/FeaturesLineChart.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts">
import type { ComponentProps } from 'svelte';
import { accessor, Circle, findRelatedData, Line, LineChart, Tooltip } from 'layerchart';
import { scaleOrdinal } from 'd3';
import { scaleOrdinal, zip } from 'd3';
import { Int64 } from '@creditkarma/thrift-server-core';

import { colors, lineChartProps, tooltipProps, type DateValue } from './common';
import type { TimeSeriesItem } from '$lib/types/Model/Model';
import type { ITileDriftSeries } from '$src/lib/types/codegen';
import { formatDate, formatValue } from '$lib/util/format';
import { Badge } from '../ui/badge';
import { isMacOS } from '$src/lib/util/browser';
Expand All @@ -14,7 +15,7 @@
type BrushProps = Exclude<LineChartProps['brush'], undefined | boolean>;

type Props = {
data: { feature: string; points: TimeSeriesItem[] }[];
data: ITileDriftSeries[];
markPoint?: DateValue;
onitemclick?: (item: {
series: NonNullable<LineChartProps['series']>[number];
Expand All @@ -26,23 +27,27 @@

let { data, markPoint, onitemclick, onbrushend, ...restProps }: Props = $props();

const features = $derived([...new Set(data.map((d) => d.feature))]);
const colorScale = $derived(scaleOrdinal<string>().domain(features).range(colors));
const columns = $derived([...new Set(data.map((d) => d.key?.column ?? 'Unknown'))]);
const colorScale = $derived(scaleOrdinal<string>().domain(columns).range(colors));
</script>

<LineChart
x="date"
y="value"
series={data.map((d) => {
const timestamps = d.timestamps ?? [];
const column = d.key?.column ?? 'Unknown';
// `percentileDriftSeries` = numeric column, `histogramDriftSeries` = categorical column
const values = d.percentileDriftSeries ?? d.histogramDriftSeries ?? [];
return {
key: d.feature,
data: d.points.map((p) => {
key: column,
data: zip<Int64 | number>(timestamps, values).map(([ts, value]) => {
return {
date: new Date(p.ts),
value: p.value === NULL_VALUE ? null : p.value
date: new Date(ts as number),
value: value === NULL_VALUE ? null : value
};
}),
color: colorScale(d.feature)
color: colorScale(column)
};
})}
padding={{ left: 24, bottom: 48 }}
Expand Down
31 changes: 17 additions & 14 deletions frontend/src/lib/components/charts/PercentileLineChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import merge from 'lodash/merge';
import { lineChartProps } from './common';
import type { TimeSeriesItem } from '$lib/types/Model/Model';
import type { ITileSummarySeries } from '$src/lib/types/codegen';
import { zip } from 'd3';
import { Int64 } from '@creditkarma/thrift-server-core';
import { NULL_VALUE } from '$src/lib/constants/common';
type LineChartProps = ComponentProps<typeof LineChart>;
type BrushProps = Exclude<LineChartProps['brush'], undefined | boolean>;
type Props = {
data: TimeSeriesItem[];
data: ITileSummarySeries;
onbrushend?: BrushProps['onbrushend'];
} & Omit<LineChartProps, 'data'>;
Expand All @@ -21,21 +24,21 @@
x="date"
y="value"
series={[
{ label: 'p95', color: '#4B92FF' },
{ label: 'p50', color: '#7DFFB3' },
{ label: 'p5', color: '#FDDD61' }
{ label: 'p95', color: '#4B92FF', index: 19 },
{ label: 'p50', color: '#7DFFB3', index: 10 },
{ label: 'p5', color: '#FDDD61', index: 1 }
Comment on lines +27 to +29
Copy link
Contributor Author

@sean-zlai sean-zlai Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ken-zlai once we return a limited number of percentiles, this should be the only place we need to update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! That PR is here, waiting for approval rn #346

].map((c) => {
const timestamps = data.timestamps ?? [];
const values = data.percentiles?.[c.index] ?? [];

return {
key: c.label,
data:
data
?.filter((d) => d.label === c.label)
.map((d) => {
return {
date: new Date(d.ts),
value: d.value
};
}) ?? [],
data: zip<Int64 | number>(timestamps, values).map(([ts, value]) => {
return {
date: new Date(ts as number),
value: value === NULL_VALUE ? null : value
};
}),
color: c.color
};
})}
Expand Down
35 changes: 0 additions & 35 deletions frontend/src/lib/types/MetricType/MetricType.ts

This file was deleted.

67 changes: 0 additions & 67 deletions frontend/src/lib/types/Model/Model.ts

This file was deleted.

Loading