Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metrics filtering for Conditional Grouping #86

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
3 changes: 3 additions & 0 deletions src/src/components/Grouping/Grouping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import './Grouping.scss';
function Grouping({
groupingData,
groupingSelectOptions,
conditionalGroupingOptions,
onGroupingSelectChange,
onGroupingModeChange,
onGroupingPaletteChange,
Expand Down Expand Up @@ -46,6 +47,7 @@ function Grouping({
groupName={groupName as GroupNameEnum}
groupingData={groupingData}
groupingSelectOptions={groupingSelectOptions}
conditionalGroupingOptions={conditionalGroupingOptions}
onSelect={onGroupingSelectChange}
onGroupingModeChange={onGroupingModeChange}
isDisabled={isDisabled}
Expand All @@ -65,6 +67,7 @@ function Grouping({
paletteIndex: groupingData?.paletteIndex,
})}
groupingSelectOptions={groupingSelectOptions}
conditionalGroupingOptions={conditionalGroupingOptions}
onSelect={onGroupingSelectChange}
onGroupingConditionsChange={onGroupingConditionsChange}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/src/components/GroupingItem/GroupingItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function GroupingItem({
onSelect,
onGroupingModeChange,
groupingSelectOptions,
conditionalGroupingOptions,
isDisabled,
}: IGroupingItemProps): React.FunctionComponentElement<React.ReactNode> {
return (
Expand Down Expand Up @@ -70,6 +71,7 @@ function GroupingItem({
inputLabel={inputLabel}
groupingData={groupingData}
groupingSelectOptions={groupingSelectOptions}
conditionalGroupingOptions={conditionalGroupingOptions}
advancedComponent={advancedComponent}
onSelect={onSelect}
onGroupingModeChange={onGroupingModeChange}
Expand Down
1 change: 1 addition & 0 deletions src/src/pages/Metrics/Metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function Metrics(
isDisabled={isProgressBarVisible}
groupingData={props.groupingData}
groupingSelectOptions={props.groupingSelectOptions}
conditionalGroupingOptions={props.conditionalGroupingOptions}
onGroupingSelectChange={props.onGroupingSelectChange}
onGroupingModeChange={props.onGroupingModeChange}
onGroupingPaletteChange={props.onGroupingPaletteChange}
Expand Down
1 change: 1 addition & 0 deletions src/src/pages/Metrics/MetricsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function MetricsContainer(): React.FunctionComponentElement<React.ReactNode> {
chartPanelOffsetHeight={chartPanelOffsetHeight}
selectedRows={metricsData?.selectedRows!}
groupingSelectOptions={metricsData?.groupingSelectOptions!}
conditionalGroupingOptions={metricsData?.conditionalGroupingOptions!}
sortOptions={metricsData?.sortOptions!}
resizeMode={metricsData?.config?.table?.resizeMode!}
columnsWidths={metricsData?.config?.table?.columnsWidths!}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
&__conditionalFilter {
padding: 1rem;
border-bottom: $border-main;

&__icon {
margin-left: 0.5rem;
color: $text-color;
}
}

&__conditionalFilter__p {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useMemo } from 'react';

import { Checkbox, TextField } from '@material-ui/core';
import { Checkbox, TextField, Tooltip } from '@material-ui/core';
import {
CheckBox as CheckBoxIcon,
CheckBoxOutlineBlank,
Expand Down Expand Up @@ -33,7 +33,7 @@ export enum IOperator {
function ChartPopoverAdvanced({
onGroupingConditionsChange,
groupingData,
groupingSelectOptions,
conditionalGroupingOptions,
}: IGroupingPopoverAdvancedProps): React.FunctionComponentElement<React.ReactNode> {
const [inputValue, setInputValue] = useState('');
const [selectedField, setSelectedField] =
Expand Down Expand Up @@ -90,7 +90,7 @@ function ChartPopoverAdvanced({
};

const options = useMemo(() => {
const filteredOptions = groupingSelectOptions?.filter((item) =>
const filteredOptions = conditionalGroupingOptions?.filter((item) =>
item.label.toLowerCase().includes(inputValue.toLowerCase()),
);
return (
Expand All @@ -100,28 +100,40 @@ function ChartPopoverAdvanced({
b.label.toLowerCase().indexOf(inputValue.toLowerCase()),
) || []
);
}, [groupingSelectOptions, inputValue]);
}, [conditionalGroupingOptions, inputValue]);

return (
<ErrorBoundary>
<div className='ChartPopoverAdvanced'>
<div className='ChartPopoverAdvanced__conditionalFilter'>
<Text component='h3' size={12} tint={50}>
group by condition
<Tooltip
title='Conditional filtering for metrics is based on the last value logged.'
placement='top'
>
<div style={{ display: 'inline' }}>
<Icon
name='circle-question'
fontSize={14}
className='ChartPopoverAdvanced__conditionalFilter__icon'
/>
</div>
</Tooltip>
</Text>
<Text
component='p'
size={14}
className='ChartPopoverAdvanced__conditionalFilter__p'
>
Group charts by conditions such as{' '}
Group charts by conditions, e.g.{' '}
<span style={{ fontFamily: 'Courier New' }}>
run.epochs &gt; 30
</span>
.
</Text>
<div className='flex fac'>
{/* Add textbox to allow grouping by condition */}
{/* Textbox for selecting fields */}
<Autocomplete
className='ChartPopoverAdvanced__container__select__fieldName'
openOnFocus
Expand All @@ -147,7 +159,7 @@ function ChartPopoverAdvanced({
}}
className='TextField__OutLined__Small'
variant='outlined'
placeholder='Select fields'
placeholder='Select field'
/>
)}
renderTags={() => null} // No tags for single selection
Expand Down Expand Up @@ -214,7 +226,7 @@ function ChartPopoverAdvanced({
key={index}
className='ChartPopoverAdvanced__conditionalFilter__box flex fac fjb'
>
{/* Show condition and button in same line */}
{/* Show condition and Remove button in same line */}
<Text
size={14}
className='ChartPopoverAdvanced__conditionalFilter__box__p'
Expand Down
1 change: 1 addition & 0 deletions src/src/pages/Params/Params.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const Params = ({
isDisabled={isProgressBarVisible}
groupingData={groupingData}
groupingSelectOptions={groupingSelectOptions}
conditionalGroupingOptions={groupingSelectOptions} // jescalada: TODO: Implement conditional grouping (Params/Scatters)
onGroupingSelectChange={onGroupingSelectChange}
onGroupingModeChange={onGroupingModeChange}
onGroupingPaletteChange={onGroupingPaletteChange}
Expand Down
1 change: 1 addition & 0 deletions src/src/pages/Scatters/Scatters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function Scatters(
isDisabled={isProgressBarVisible}
groupingData={props.groupingData}
groupingSelectOptions={props.groupingSelectOptions}
conditionalGroupingOptions={props.groupingSelectOptions} // jescalada: TODO: Implement conditional grouping (Params/Scatters)
onGroupingSelectChange={props.onGroupingSelectChange}
onGroupingModeChange={props.onGroupingModeChange}
onGroupingPaletteChange={props.onGroupingPaletteChange}
Expand Down
28 changes: 28 additions & 0 deletions src/src/services/models/explorer/createAppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,19 @@ function createAppModel(appConfig: IAppInitialConfig) {
sequenceName: 'metric',
}),
];
// Conditional grouping allows grouping by regular select options and also metrics
const conditionalGroupingOptions = groupingSelectOptions.concat(
_.uniqBy(
data.map((metric) => {
return {
group: 'metric',
label: `metric.${metric?.config?.name}`,
value: `${metric?.config?.name}`,
};
}),
'value',
),
);
const sortOptions = [
...groupingSelectOptions,
{
Expand Down Expand Up @@ -1277,6 +1290,7 @@ function createAppModel(appConfig: IAppInitialConfig) {
tableColumns,
sameValueColumns: tableData.sameValueColumns,
groupingSelectOptions,
conditionalGroupingOptions,
sortOptions,
selectedRows,
});
Expand Down Expand Up @@ -1309,6 +1323,19 @@ function createAppModel(appConfig: IAppInitialConfig) {
sequenceName: 'metric',
}),
];
// Conditional grouping allows grouping by regular select options and also metrics
const conditionalGroupingOptions = groupingSelectOptions.concat(
_.uniqBy(
data.map((metric) => {
return {
group: 'metric',
label: `metric.${metric?.config?.name}`,
value: `${metric?.config?.name}`,
};
}),
'value',
),
);
const sortOptions = [
...groupingSelectOptions,
{
Expand Down Expand Up @@ -1433,6 +1460,7 @@ function createAppModel(appConfig: IAppInitialConfig) {
tableColumns: tableColumns,
sameValueColumns: tableData.sameValueColumns,
groupingSelectOptions,
conditionalGroupingOptions,
sortOptions,
selectedRows,
});
Expand Down
2 changes: 2 additions & 0 deletions src/src/types/components/GroupingPopover/GroupingPopover.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IGroupingPopoverProps {
groupingData: IGroupingConfig;
advancedComponent?: React.FunctionComponentElement<React.ReactNode> | null;
groupingSelectOptions: IGroupingSelectOption[];
conditionalGroupingOptions?: IGroupingSelectOption[];
onSelect: IMetricProps['onGroupingSelectChange'];
onGroupingModeChange: IMetricProps['onGroupingModeChange'];
inputLabel?: string;
Expand All @@ -26,6 +27,7 @@ export interface IGroupingPopoverAdvancedProps {
onGroupingPaletteChange?: IMetricProps['onGroupingPaletteChange'];
onShuffleChange: IMetricProps['onShuffleChange'];
groupingSelectOptions?: IGroupingSelectOption[];
conditionalGroupingOptions?: IGroupingSelectOption[];
onSelect?: IMetricProps['onGroupingSelectChange'];
inputLabel?: string;
onGroupingConditionsChange?: IMetricProps['onGroupingConditionsChange'];
Expand Down
1 change: 1 addition & 0 deletions src/src/types/pages/components/Grouping/Grouping.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IMetricProps } from 'types/pages/metrics/Metrics';
export interface IGroupingProps {
groupingData: IGroupingConfig;
groupingSelectOptions: IGroupingSelectOption[];
conditionalGroupingOptions?: IGroupingSelectOption[];
onGroupingSelectChange: IMetricProps['onGroupingSelectChange'];
onGroupingModeChange: IMetricProps['onGroupingModeChange'];
onGroupingPaletteChange: IMetricProps['onGroupingPaletteChange'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IGroupingItemProps extends IGroupingPopoverProps {
groupingData: IGroupingConfig;
advancedComponent?: React.FunctionComponentElement<React.ReactNode>;
groupingSelectOptions: IGroupingSelectOption[];
conditionalGroupingOptions?: IGroupingSelectOption[];
onReset: () => void;
onVisibilityChange: () => void;
}
1 change: 1 addition & 0 deletions src/src/types/pages/metrics/Metrics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface IMetricProps extends Partial<RouteChildrenProps> {
unselectedColumnState: UnselectedColumnState;
sameValueColumns?: string[] | [];
groupingSelectOptions: IGroupingSelectOption[];
conditionalGroupingOptions: IGroupingSelectOption[];
sortOptions: IGroupingSelectOption[];
requestStatus: RequestStatusEnum;
requestProgress: IRequestProgress;
Expand Down
1 change: 1 addition & 0 deletions src/src/types/services/models/metrics/metricModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface IMetric {
x_axis_iters?: Float64Array;
x_axis_values?: Float64Array;
isHidden: boolean;
lastValue?: number;
}
1 change: 1 addition & 0 deletions src/src/types/services/models/metrics/metricsAppModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface IMetricAppModelState {
params: string[];
notifyData: INotification[];
groupingSelectOptions: IGroupingSelectOption[];
conditionalGroupingOptions: IGroupingSelectOption[];
sortOptions: IGroupingSelectOption[];
selectFormData?: {
options: ISelectOption[];
Expand Down
1 change: 1 addition & 0 deletions src/src/utils/app/generateGroupValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function generateGroupValues(
name: fieldType === 'metric' ? data[i].name : data[i].run.props.name,
tags: data[i].run.params.tags,
experiment: data[i].run.props.experiment?.name,
context: data[i].context,
};

// Get the relevant attribute's value
Expand Down
Loading