Skip to content

Commit

Permalink
Merge branch 'main' into use-json5
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 authored Nov 10, 2022
2 parents 9120741 + 8539d34 commit 7f9317b
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 72 deletions.
2 changes: 2 additions & 0 deletions extension/src/experiments/columns/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export const timestampColumn: Column = {
type,
types: [type]
}

export const EXPERIMENT_COLUMN_ID = 'id'
70 changes: 43 additions & 27 deletions extension/src/experiments/columns/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ beforeEach(() => {

describe('ColumnsModel', () => {
const exampleDvcRoot = 'test'
const mockedColumnsOrderChanged = buildMockedEventEmitter<void>()
const mockedColumnsOrderOrStatusChanged = buildMockedEventEmitter<void>()

it('should return the expected columns when given the default output fixture', async () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(outputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -59,7 +59,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(survivalOutputFixture)
expect(model.getSelected()).toStrictEqual(survivalColumnsFixture)
Expand All @@ -69,7 +69,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -81,7 +81,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -93,7 +93,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -105,7 +105,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -117,7 +117,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -129,7 +129,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -141,7 +141,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(deeplyNestedOutputFixture)
expect(mockedGetConfigValue).toHaveBeenCalled()
Expand All @@ -152,7 +152,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
'',
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(dataTypesOutputFixture)
expect(model.getSelected()).toStrictEqual(dataTypesColumnsFixture)
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('ColumnsModel', () => {
const model = new ColumnsModel(
exampleDvcRoot,
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(exampleData)
expect(model.getSelected()).toStrictEqual([
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('ColumnsModel', () => {
[testParamPath]: Status.UNSELECTED
}
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(exampleData)
expect(model.getSelected()).toStrictEqual([
Expand Down Expand Up @@ -246,19 +246,20 @@ describe('ColumnsModel', () => {
[PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER + exampleDvcRoot]:
persistedState
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
expect(model.getColumnOrder()).toStrictEqual(persistedState)
})

it('should return the first three columns from the persisted state', () => {
it('should return the first three none hidden columns from the persisted state', async () => {
const persistedState = [
{ path: 'A', width: 0 },
{ path: 'B', width: 0 },
{ path: 'C', width: 0 },
{ path: 'D', width: 0 },
{ path: 'E', width: 0 },
{ path: 'F', width: 0 }
'id',
'Created',
'params:params.yaml:dvc_logs_dir',
'params:params.yaml:process.threshold',
'params:params.yaml:process.test_arg',
'deps:src/prepare.py',
'deps:src/featurization.py'
]

const model = new ColumnsModel(
Expand All @@ -267,19 +268,26 @@ describe('ColumnsModel', () => {
[PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER + exampleDvcRoot]:
persistedState
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(outputFixture)

expect(model.getFirstThreeColumnOrder()).toStrictEqual(
persistedState.slice(1, 4)
)

model.toggleStatus('Created')

expect(model.getFirstThreeColumnOrder()).toStrictEqual(
persistedState.slice(2, 5)
)
})

it('should return first three columns collected from data if state is empty', async () => {
it('should return the first three none hidden columns collected from data if state is empty', async () => {
const model = new ColumnsModel(
exampleDvcRoot,
buildMockMemento(),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
await model.transformAndSet(outputFixture)

Expand All @@ -288,6 +296,14 @@ describe('ColumnsModel', () => {
'metrics:summary.json:loss',
'metrics:summary.json:accuracy'
])

model.toggleStatus('Created')

expect(model.getFirstThreeColumnOrder()).toStrictEqual([
'metrics:summary.json:loss',
'metrics:summary.json:accuracy',
'metrics:summary.json:val_loss'
])
})

it('should re-order the columns if a new columnOrder is set', () => {
Expand All @@ -300,7 +316,7 @@ describe('ColumnsModel', () => {
{ path: 'C', width: 0 }
]
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
const newState = ['C', 'B', 'A']
model.setColumnOrder(newState)
Expand All @@ -321,7 +337,7 @@ describe('ColumnsModel', () => {
[PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER + exampleDvcRoot]:
persistedState
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
expect(model.getColumnOrder()).toStrictEqual(persistedState)
})
Expand All @@ -338,7 +354,7 @@ describe('ColumnsModel', () => {
[PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER + exampleDvcRoot]:
persistedState
}),
mockedColumnsOrderChanged
mockedColumnsOrderOrStatusChanged
)
const changedColumnId = 'C'
const expectedWidth = 77
Expand Down
66 changes: 51 additions & 15 deletions extension/src/experiments/columns/model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EventEmitter, Memento } from 'vscode'
import { collectChanges, collectColumns, collectParamsFiles } from './collect'
import { EXPERIMENT_COLUMN_ID, timestampColumn } from './constants'
import { Column, ColumnType } from '../webview/contract'
import { ExperimentsOutput } from '../../cli/dvc/contract'
import { PersistenceKey } from '../../persistence/constants'
import { PathSelectionModel } from '../../path/selection/model'

export class ColumnsModel extends PathSelectionModel<Column> {
private columnsOrderChanged: EventEmitter<void>
private columnOrderState: string[] = []
private columnWidthsState: Record<string, number> = {}
private columnsChanges: string[] = []
Expand All @@ -15,9 +15,14 @@ export class ColumnsModel extends PathSelectionModel<Column> {
constructor(
dvcRoot: string,
workspaceState: Memento,
columnsOrderChanged: EventEmitter<void>
columnsOrderOrStatusChanged: EventEmitter<void>
) {
super(dvcRoot, workspaceState, PersistenceKey.METRICS_AND_PARAMS_STATUS)
super(
dvcRoot,
workspaceState,
PersistenceKey.METRICS_AND_PARAMS_STATUS,
columnsOrderOrStatusChanged
)

this.columnOrderState = this.revive(
PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER,
Expand All @@ -27,17 +32,16 @@ export class ColumnsModel extends PathSelectionModel<Column> {
PersistenceKey.METRICS_AND_PARAMS_COLUMN_WIDTHS,
{}
)
this.columnsOrderChanged = columnsOrderChanged
}

public getColumnOrder(): string[] {
return this.columnOrderState
}

public getFirstThreeColumnOrder(): string[] {
return this.columnOrderState.length === 0
? this.getFirstThreeColumnOrderFromData()
: this.columnOrderState.slice(1, 4)
return this.columnOrderState
.filter(path => this.status[path] && this.status[path] === 2)
.slice(0, 3)
}

public getColumnWidths(): Record<string, number> {
Expand Down Expand Up @@ -65,7 +69,7 @@ export class ColumnsModel extends PathSelectionModel<Column> {
PersistenceKey.METRICS_AND_PARAMS_COLUMN_ORDER,
this.getColumnOrder()
)
this.columnsOrderChanged.fire()
this.statusChanged?.fire()
}

public setColumnWidth(id: string, width: number) {
Expand All @@ -91,13 +95,6 @@ export class ColumnsModel extends PathSelectionModel<Column> {
return this.data.length > 1
}

private getFirstThreeColumnOrderFromData(): string[] {
return this.data
.filter(({ hasChildren }) => !hasChildren)
.slice(0, 3)
.map(({ path }) => path)
}

private filterChildren(path?: string) {
return this.data.filter(element =>
path
Expand All @@ -108,6 +105,40 @@ export class ColumnsModel extends PathSelectionModel<Column> {
)
}

private findChildrenColumns(
parent: string,
columns: Column[],
childrenColumns: string[]
) {
const filteredColumns = columns.filter(
({ parentPath }) => parentPath === parent
)
for (const column of filteredColumns) {
if (column.hasChildren) {
this.findChildrenColumns(column.path, columns, childrenColumns)
} else {
childrenColumns.push(column.path)
}
}
}

private getColumnsFromType(type: string): string[] {
const childrenColumns: string[] = []
const dataWithType = this.data.filter(({ path }) => path.startsWith(type))
this.findChildrenColumns(type, dataWithType, childrenColumns)
return childrenColumns
}

private getColumnOrderFromData() {
return [
EXPERIMENT_COLUMN_ID,
timestampColumn.path,
...this.getColumnsFromType(ColumnType.METRICS),
...this.getColumnsFromType(ColumnType.PARAMS),
...this.getColumnsFromType(ColumnType.DEPS)
]
}

private async transformAndSetColumns(data: ExperimentsOutput) {
const [columns, paramsFiles] = await Promise.all([
collectColumns(data),
Expand All @@ -117,6 +148,11 @@ export class ColumnsModel extends PathSelectionModel<Column> {
this.setNewStatuses(columns)

this.data = columns

if (this.columnOrderState.length === 0) {
this.setColumnOrder(this.getColumnOrderFromData())
}

this.paramsFiles = paramsFiles
}

Expand Down
12 changes: 8 additions & 4 deletions extension/src/experiments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Experiments extends BaseRepository<TableData> {
public readonly onDidChangeIsParamsFileFocused: Event<string | undefined>
public readonly onDidChangeExperiments: Event<ExperimentsOutput | void>
public readonly onDidChangeColumns: Event<void>
public readonly onDidChangeColumnOrder: Event<void>
public readonly onDidChangeColumnOrderOrStatus: Event<void>
public readonly onDidChangeCheckpoints: Event<void>

public readonly viewKey = ViewKey.EXPERIMENTS
Expand All @@ -79,7 +79,7 @@ export class Experiments extends BaseRepository<TableData> {
)

private readonly columnsChanged = this.dispose.track(new EventEmitter<void>())
private readonly columnsOrderChanged = this.dispose.track(
private readonly columnsOrderOrStatusChanged = this.dispose.track(
new EventEmitter<void>()
)

Expand All @@ -106,15 +106,19 @@ export class Experiments extends BaseRepository<TableData> {
this.onDidChangeIsParamsFileFocused = this.paramsFileFocused.event
this.onDidChangeExperiments = this.experimentsChanged.event
this.onDidChangeColumns = this.columnsChanged.event
this.onDidChangeColumnOrder = this.columnsOrderChanged.event
this.onDidChangeColumnOrderOrStatus = this.columnsOrderOrStatusChanged.event
this.onDidChangeCheckpoints = this.checkpointsChanged.event

this.experiments = this.dispose.track(
new ExperimentsModel(dvcRoot, workspaceState)
)

this.columns = this.dispose.track(
new ColumnsModel(dvcRoot, workspaceState, this.columnsOrderChanged)
new ColumnsModel(
dvcRoot,
workspaceState,
this.columnsOrderOrStatusChanged
)
)

this.checkpoints = this.dispose.track(new CheckpointsModel())
Expand Down
Loading

0 comments on commit 7f9317b

Please sign in to comment.