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

Refactor getDataFromColumnPath logic #2971

Merged
merged 5 commits into from
Dec 20, 2022
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
18 changes: 6 additions & 12 deletions extension/src/experiments/model/quickPicks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QuickPickItemKind } from 'vscode'
import omit from 'lodash.omit'
import { ExperimentWithCheckpoints } from '.'
import { MAX_SELECTED_EXPERIMENTS } from './status'
import { getDataFromColumnPath } from './util'
import { getDataFromColumnPaths } from './util'
import { definedAndNonEmpty } from '../../util/array'
import {
QuickPickItemWithValue,
Expand All @@ -25,17 +25,11 @@ const getSeparator = (experiment: Experiment) => ({
})

const getItem = (experiment: Experiment, firstThreeColumnOrder: string[]) => ({
detail: firstThreeColumnOrder
.map(path => {
const { splitUpPath, value } = getDataFromColumnPath(experiment, path)
const truncatedKey = truncateFromLeft(
splitUpPath[splitUpPath.length - 1],
15
)

return value === null ? '' : `${truncatedKey}:${value}`
})
.filter(Boolean)
detail: getDataFromColumnPaths(experiment, firstThreeColumnOrder)
.map(
({ splitUpPath, truncatedValue: value }) =>
`${truncateFromLeft(splitUpPath[splitUpPath.length - 1], 15)}:${value}`
)
.join(', '),
label: experiment.label,
value: omit(experiment, 'checkpoints')
Expand Down
18 changes: 6 additions & 12 deletions extension/src/experiments/model/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ExperimentType } from '.'
import { ExperimentAugmented } from './filterBy/collect'
import { collectDeletable, ExperimentItem } from './collect'
import { MAX_SELECTED_EXPERIMENTS } from './status'
import { getDataFromColumnPath } from './util'
import { getDataFromColumnPaths } from './util'
import { WorkspaceExperiments } from '../workspace'
import { sendViewOpenedTelemetryEvent } from '../../telemetry'
import { EventName } from '../../telemetry/constants'
Expand Down Expand Up @@ -347,18 +347,12 @@ export class ExperimentsTree
}

private getTooltipTable(experiment: Experiment, firstThreeColumns: string[]) {
const data = firstThreeColumns
.map(path => {
const { value, splitUpPath } = getDataFromColumnPath(experiment, path)
const [type] = splitUpPath
const truncatedKey = truncateFromLeft(
path.slice(type.length + 1) || path,
30
)
return value === null ? '' : `| ${truncatedKey} | ${value} |\n`
})
const data = getDataFromColumnPaths(experiment, firstThreeColumns)
.map(
({ truncatedValue: value, columnPath }) =>
`| ${truncateFromLeft(columnPath, 30)} | ${value} |\n`
)
.join('')

return data === '' ? undefined : getMarkdownString(`|||\n|:--|--|\n${data}`)
}

Expand Down
27 changes: 18 additions & 9 deletions extension/src/experiments/model/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ const getStringifiedValue = (value: Value): string => {
return String(value)
}

export const getDataFromColumnPath = (
const getDataFromColumnPath = (
experiment: Experiment,
columnPath: string
): { fullValue: string; splitUpPath: string[]; value: string | null } => {
): {
type: string
value: string | number
columnPath: string
splitUpPath: string[]
truncatedValue: string
} => {
const splitUpPath = splitColumnPath(columnPath)
const collectedVal = get(experiment, splitUpPath)
const value = collectedVal?.value || collectedVal
const [type] = splitUpPath

return {
fullValue: isLongNumber(value)
? value.toString()
: getStringifiedValue(value),
columnPath: columnPath.slice(type.length + 1) || columnPath,
splitUpPath,
value:
columnPath === 'Created' && value === 'undefined'
? null
: getStringifiedValue(value)
truncatedValue: getStringifiedValue(value),
type,
value: isLongNumber(value) ? value : getStringifiedValue(value)
}
}

export const getDataFromColumnPaths = (
experiment: Experiment,
columnPaths: string[]
) => columnPaths.map(path => getDataFromColumnPath(experiment, path))
30 changes: 9 additions & 21 deletions extension/src/plots/model/util.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import { getDataFromColumnPath } from '../../experiments/model/util'
import { getDataFromColumnPaths } from '../../experiments/model/util'
import { Experiment } from '../../experiments/webview/contract'
import { RevisionFirstThreeColumns } from '../webview/contract'

export const getRevisionFirstThreeColumns = (
firstThreeColumns: string[],
experiment: Experiment
) => {
const columns: RevisionFirstThreeColumns = []
for (const path of firstThreeColumns) {
const { value, splitUpPath, fullValue } = getDataFromColumnPath(
experiment,
path
)
const type = splitUpPath[0]

if (value) {
columns.push({
fullValue,
path: path.slice(type.length + 1) || path,
type,
value
})
}
}
return columns
}
): RevisionFirstThreeColumns =>
getDataFromColumnPaths(experiment, firstThreeColumns).map(
({ columnPath: path, value, type }) => ({
path,
type,
value
})
)
3 changes: 1 addition & 2 deletions extension/src/plots/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export type ComparisonPlots = {

export type RevisionFirstThreeColumns = Array<{
path: string
value: string
fullValue: string
value: string | number
type: string
}>

Expand Down
39 changes: 12 additions & 27 deletions extension/src/test/fixtures/plotsDiff/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,21 +542,18 @@ export const getRevisions = (): Revision[] => {
firstThreeColumns: [
{
type: 'Created',
fullValue: '-',
path: 'Created',
value: '-'
},
{
type: ColumnType.METRICS,
fullValue: '1.9293040037155151',
path: 'summary.json:loss',
value: '1.9293'
value: 1.9293040037155151
},
{
type: ColumnType.METRICS,
fullValue: '0.4668000042438507',
path: 'summary.json:accuracy',
value: '0.46680'
value: 0.4668000042438507
}
],
group: undefined
Expand All @@ -566,21 +563,18 @@ export const getRevisions = (): Revision[] => {
firstThreeColumns: [
{
type: 'Created',
fullValue: formatDate(getMain().Created as string),
path: 'Created',
value: formatDate(getMain().Created as string)
},
{
type: ColumnType.METRICS,
fullValue: '2.048856019973755',
path: 'summary.json:loss',
value: '2.0489'
type: ColumnType.METRICS,
value: 2.048856019973755
},
{
type: ColumnType.METRICS,
fullValue: '0.3484833240509033',
path: 'summary.json:accuracy',
value: '0.34848'
type: ColumnType.METRICS,
value: 0.3484833240509033
}
],
id: 'main',
Expand All @@ -593,21 +587,18 @@ export const getRevisions = (): Revision[] => {
firstThreeColumns: [
{
type: 'Created',
fullValue: findAndFormatCreated('exp-e7a67'),
path: 'Created',
value: findAndFormatCreated('exp-e7a67')
},
{
type: ColumnType.METRICS,
fullValue: '2.0205044746398926',
path: 'summary.json:loss',
value: '2.0205'
value: 2.0205044746398926
},
{
type: ColumnType.METRICS,
fullValue: '0.3724166750907898',
path: 'summary.json:accuracy',
value: '0.37242'
value: 0.3724166750907898
}
],
id: 'exp-e7a67',
Expand All @@ -619,22 +610,19 @@ export const getRevisions = (): Revision[] => {
fetched: true,
firstThreeColumns: [
{
fullValue: findAndFormatCreated('test-branch'),
type: 'Created',
path: 'Created',
value: findAndFormatCreated('test-branch')
},
{
fullValue: '1.9293040037155151',
type: ColumnType.METRICS,
path: 'summary.json:loss',
value: '1.9293'
value: 1.9293040037155151
},
{
fullValue: '0.4668000042438507',
type: ColumnType.METRICS,
path: 'summary.json:accuracy',
value: '0.46680'
value: 0.4668000042438507
}
],
id: 'test-branch',
Expand All @@ -646,22 +634,19 @@ export const getRevisions = (): Revision[] => {
fetched: true,
firstThreeColumns: [
{
fullValue: findAndFormatCreated('exp-83425'),
type: 'Created',
path: 'Created',
value: findAndFormatCreated('exp-83425')
},
{
fullValue: '1.775016188621521',
type: ColumnType.METRICS,
path: 'summary.json:loss',
value: '1.7750'
value: 1.775016188621521
},
{
fullValue: '0.5926499962806702',
type: ColumnType.METRICS,
path: 'summary.json:accuracy',
value: '0.59265'
value: 0.5926499962806702
}
],
id: 'exp-83425',
Expand Down
Loading