Skip to content

Commit

Permalink
ability to filter by dataset name and model name (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
weirong-duke committed May 9, 2024
1 parent 849a2bf commit 1bc8965
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ts-client/src/ValorClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,35 @@ export class ValorClient {
});
}

/**
* Fetches all evaluations associated to given models and dataset names
*
* @param modelNames names of the models
* @param datasetNames names of the datasets
* @param offset The start index of the evaluations to return. Used for pagination.
* @param limit The number of evaluations to return. Used for pagination.
* @param metricsToSortBy A map of metrics to sort the evaluations by.
*
* @returns {Promise<Evaluation[]>}
*/
public async getEvaluationsByModelNamesAndDatasetNames(
modelNames: string[],
datasetNames: string[],
offset?: number,
limit?: number,
metricsToSortBy?: {
[key: string]: string | { [inner_key: string]: string };
}
): Promise<Evaluation[]> {
return this.getEvaluations({
models: modelNames.join(','),
datasets: datasetNames.join(','),
offset: offset,
limit: limit,
metrics_to_sort_by: metricsToSortBy != null ? JSON.stringify(metricsToSortBy) : null
});
}

/**
* Adds ground truth annotations to a dataset
*
Expand Down
93 changes: 93 additions & 0 deletions ts-client/tests/ValorClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,99 @@ test('evaluation methods', async () => {
expect((await client.getEvaluationsByDatasetNames([datasetNames[0]])).length).toBe(2);
expect((await client.getEvaluationsByDatasetNames(datasetNames)).length).toBe(4);
expect((await client.getEvaluationsByDatasetNames(['no-such-dataset'])).length).toBe(0);
// check we can get evaluations by model names and dataset names
expect(
(await client.getEvaluationsByModelNamesAndDatasetNames(modelNames, datasetNames))
.length
).toBe(4);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[0]],
datasetNames
)
).length
).toBe(2);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[0]],
[datasetNames[0]]
)
).length
).toBe(1);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[0]],
[datasetNames[1]]
)
).length
).toBe(1);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[1]],
datasetNames
)
).length
).toBe(2);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[1]],
[datasetNames[0]]
)
).length
).toBe(1);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[1]],
[datasetNames[1]]
)
).length
).toBe(1);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[...modelNames, 'fake', 'not-real'],
datasetNames
)
).length
).toBe(4);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[...modelNames, 'fake', 'not-real'],
[datasetNames[0]]
)
).length
).toBe(2);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(modelNames, [
...datasetNames,
'fake',
'not-real'
])
).length
).toBe(4);
expect(
(
await client.getEvaluationsByModelNamesAndDatasetNames(
[modelNames[0]],
[...datasetNames, 'fake', 'not-real']
)
).length
).toBe(2);
expect(
(await client.getEvaluationsByModelNamesAndDatasetNames(['fake'], datasetNames))
.length
).toBe(0);
expect(
(await client.getEvaluationsByModelNamesAndDatasetNames(modelNames, ['fake'])).length
).toBe(0);
// check pagination
expect((await client.getEvaluationsByModelNames(modelNames, 2)).length).toBe(2);
expect((await client.getEvaluationsByModelNames(modelNames, 3)).length).toBe(1);
Expand Down

0 comments on commit 1bc8965

Please sign in to comment.