Skip to content

Commit

Permalink
feat: Add diff detection for new datasets page query (#1446)
Browse files Browse the repository at this point in the history
* add =

* lint
  • Loading branch information
bchu1 authored Jan 9, 2025
1 parent 8d258b7 commit 2ac96b6
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 49 deletions.
19 changes: 19 additions & 0 deletions frontend/packages/data-portal/app/graphql/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Depositions_Bool_Exp } from 'app/__generated__/graphql'
import { Tomogram_Reconstruction_Method_Enum } from 'app/__generated_v2__/graphql'

export const depositionWithAnnotationFilter: Depositions_Bool_Exp = {
annotations_aggregate: {
Expand All @@ -9,3 +10,21 @@ export const depositionWithAnnotationFilter: Depositions_Bool_Exp = {
},
},
}

export function convertReconstructionMethodToV2(
v1: string,
): Tomogram_Reconstruction_Method_Enum {
switch (v1) {
case 'Fourier Space':
return Tomogram_Reconstruction_Method_Enum.FourierSpace
case 'SART':
return Tomogram_Reconstruction_Method_Enum.Sart
case 'SIRT':
return Tomogram_Reconstruction_Method_Enum.Sirt
case 'WBP':
return Tomogram_Reconstruction_Method_Enum.Wbp
case 'Unknown':
default:
return Tomogram_Reconstruction_Method_Enum.Unknown
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const GET_DATASETS_DATA_QUERY = gql(`
query GetDatasetsData(
$limit: Int,
$offset: Int,
$order_by: datasets_order_by!,
$order_by: [datasets_order_by!]!,
$filter: datasets_bool_exp,
) {
datasets(
limit: $limit,
offset: $offset,
order_by: [$order_by],
order_by: $order_by,
where: $filter
) {
id
Expand Down Expand Up @@ -383,12 +383,15 @@ export async function getBrowseDatasets({
limit: MAX_PER_PAGE,
offset: (page - 1) * MAX_PER_PAGE,

// Order by dataset title if orderBy is set, otherwise order by release date
// Default order primarily by release date.
order_by: orderBy
? { title: orderBy }
: {
release_date: Order_By.Desc,
},
? [{ title: orderBy }, { release_date: Order_By.Desc }]
: [
{
release_date: Order_By.Desc,
},
{ title: Order_By.Asc },
],
},
})

Expand Down
17 changes: 12 additions & 5 deletions frontend/packages/data-portal/app/graphql/getDatasetByIdDiffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function logIfHasDiff(
}
// Consistent sort order.
run.annotationsAggregate?.aggregate?.sort((groupA, groupB) =>
groupA.groupBy!.objectName!.localeCompare(groupB.groupBy!.objectName!),
String(groupA.groupBy!.objectName).localeCompare(
String(groupB.groupBy!.objectName),
),
)
}
for (const annotationsAggreate of v2.annotationsAggregate.aggregate ?? []) {
Expand All @@ -41,14 +43,19 @@ export function logIfHasDiff(
}
// Consistent sort order.
v2.annotationsAggregate.aggregate?.sort((groupA, groupB) =>
groupA.groupBy!.objectName!.localeCompare(groupB.groupBy!.objectName!),
String(groupA.groupBy!.objectName).localeCompare(
String(groupB.groupBy!.objectName),
),
)
v2.annotationShapesAggregate.aggregate?.sort((groupA, groupB) =>
groupA.groupBy!.shapeType!.localeCompare(groupB.groupBy!.shapeType!),
String(groupA.groupBy!.shapeType).localeCompare(
String(groupB.groupBy!.shapeType),
),
)
v2.tiltseriesAggregate.aggregate?.sort(
(groupA, groupB) =>
groupA.groupBy!.tiltSeriesQuality! - groupB.groupBy!.tiltSeriesQuality!,
Number(groupA.groupBy!.tiltSeriesQuality) -
Number(groupB.groupBy!.tiltSeriesQuality),
)

const v1Transformed: GetDatasetByIdV2Query = {
Expand Down Expand Up @@ -270,7 +277,7 @@ export function logIfHasDiff(
console.log(
`DIFF AT ${url} ================================================================================ ${JSON.stringify(
v1Transformed,
)} ================================================================================ ${JSON.stringify(
)} ================================================================================================================================================================ ${JSON.stringify(
v2,
)}`,
)
Expand Down
251 changes: 251 additions & 0 deletions frontend/packages/data-portal/app/graphql/getDatasetsDiffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { diff } from 'deep-object-diff'

import {
GetDatasetsDataQuery,
GetDatasetsFilterDataQuery,
} from 'app/__generated__/graphql'
import {
Annotation_File_Shape_Type_Enum,
GetDatasetsV2Query,
} from 'app/__generated_v2__/graphql'

import { convertReconstructionMethodToV2 } from './common'

/* eslint-disable no-console, no-param-reassign */
export function logIfHasDiff(
url: string,
v1: GetDatasetsDataQuery,
v1FilterValues: GetDatasetsFilterDataQuery,
v2: GetDatasetsV2Query,
): void {
console.log('Checking for datasets query diffs')

v2 = structuredClone(v2)

// Counts not used.
// Create consistent sort order.
for (const dataset of v2.datasets) {
for (const annotationsAggregate of dataset.distinctObjectNames!.aggregate ??
[]) {
delete annotationsAggregate.count
}
dataset.distinctObjectNames!.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.annotations!.objectName).localeCompare(
String(groupB.groupBy!.annotations!.objectName),
),
)
}
for (const group of v2.distinctOrganismNames.aggregate!) {
delete group.count
}
v2.distinctOrganismNames.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.organismName).localeCompare(
String(groupB.groupBy!.organismName),
),
)
for (const group of v2.distinctCameraManufacturers.aggregate!) {
delete group.count
}
v2.distinctCameraManufacturers.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.cameraManufacturer).localeCompare(
String(groupB.groupBy!.cameraManufacturer),
),
)
for (const group of v2.distinctReconstructionMethods.aggregate!) {
delete group.count
}
v2.distinctReconstructionMethods.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.reconstructionMethod).localeCompare(
String(groupB.groupBy!.reconstructionMethod),
),
)
for (const group of v2.distinctReconstructionSoftwares.aggregate!) {
delete group.count
}
v2.distinctReconstructionSoftwares.aggregate =
v2.distinctReconstructionSoftwares
.aggregate!.filter(
// Bug in APIv2 returns this as a duplicate of 'AreTomo3 v2.0.4'
(group) => group.groupBy?.reconstructionSoftware !== 'AreTomo3_v2.0.4',
)
.sort((groupA, groupB) =>
String(groupA.groupBy!.reconstructionSoftware).localeCompare(
String(groupB.groupBy!.reconstructionSoftware),
),
)
for (const group of v2.distinctObjectNames.aggregate!) {
delete group.count
}
v2.distinctObjectNames.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.objectName).localeCompare(
String(groupB.groupBy!.objectName),
),
)
for (const group of v2.distinctShapeTypes.aggregate!) {
delete group.count
}
v2.distinctShapeTypes.aggregate!.sort((groupA, groupB) =>
String(groupA.groupBy!.shapeType).localeCompare(
String(groupB.groupBy!.shapeType),
),
)

const v1Transformed: GetDatasetsV2Query = {
datasets: v1.datasets.map((dataset) => ({
id: dataset.id,
title: dataset.title,
organismName: dataset.organism_name,
datasetPublications: dataset.dataset_publications,
keyPhotoThumbnailUrl: dataset.key_photo_thumbnail_url,
relatedDatabaseEntries: dataset.related_database_entries,
authors: {
edges: dataset.authors.map((author) => ({
node: {
name: author.name,
primaryAuthorStatus: author.primary_author_status,
correspondingAuthorStatus: author.corresponding_author_status,
},
})),
},
runsCount: {
aggregate:
// Platformics returns an empty array if the count is 0.
dataset.runs_aggregate.aggregate!.count !== 0
? [
{
count: dataset.runs_aggregate.aggregate!.count,
},
]
: [],
},
distinctObjectNames: {
aggregate: [
...new Set(
dataset.runs.flatMap((run) =>
run.tomogram_voxel_spacings.flatMap((voxelSpacing) =>
voxelSpacing.annotations.map(
(annotation) => annotation.object_name,
),
),
),
),
]
.map((distinctObjectName) => ({
groupBy: {
annotations: {
objectName: distinctObjectName,
},
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.annotations.objectName.localeCompare(
groupB.groupBy.annotations.objectName,
),
),
},
})),
totalDatasetsCount: {
aggregate: [
{
count: v1.datasets_aggregate.aggregate!.count,
},
],
},
filteredDatasetsCount: {
aggregate: [
{
count: v1.filtered_datasets_aggregate.aggregate!.count,
},
],
},
distinctOrganismNames: {
aggregate: v1FilterValues.organism_names
.map((organismName) => ({
groupBy: {
organismName: organismName.organism_name,
},
}))
.sort((groupA, groupB) =>
String(groupA.groupBy.organismName).localeCompare(
String(groupB.groupBy.organismName),
),
),
},
distinctCameraManufacturers: {
aggregate: v1FilterValues.camera_manufacturers
.map((cameraManufacturer) => ({
groupBy: {
cameraManufacturer: cameraManufacturer.camera_manufacturer,
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.cameraManufacturer.localeCompare(
groupB.groupBy.cameraManufacturer,
),
),
},
distinctReconstructionMethods: {
aggregate: v1FilterValues.reconstruction_methods
.map((reconstructionMethod) => ({
groupBy: {
reconstructionMethod: convertReconstructionMethodToV2(
reconstructionMethod.reconstruction_method,
),
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.reconstructionMethod.localeCompare(
groupB.groupBy.reconstructionMethod,
),
),
},
distinctReconstructionSoftwares: {
aggregate: v1FilterValues.reconstruction_softwares
.map((reconstructionSoftware) => ({
groupBy: {
reconstructionSoftware:
reconstructionSoftware.reconstruction_software,
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.reconstructionSoftware.localeCompare(
groupB.groupBy.reconstructionSoftware,
),
),
},
distinctObjectNames: {
aggregate: v1FilterValues.object_names
.map((objectName) => ({
groupBy: {
objectName: objectName.object_name,
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.objectName.localeCompare(groupB.groupBy.objectName),
),
},
distinctShapeTypes: {
aggregate: v1FilterValues.object_shape_types
.map((shapeType) => ({
groupBy: {
shapeType: shapeType.shape_type as Annotation_File_Shape_Type_Enum,
},
}))
.sort((groupA, groupB) =>
groupA.groupBy.shapeType.localeCompare(groupB.groupBy.shapeType),
),
},
}

const diffObject = diff(v1Transformed, v2)

if (Object.keys(diffObject).length > 0) {
console.log(
`DIFF AT ${url} ================================================================================ ${JSON.stringify(
v1Transformed,
)} ================================================================================================================================================================================================================================================================================================================================ ${JSON.stringify(
v2,
)}`,
)
}
}
Loading

0 comments on commit 2ac96b6

Please sign in to comment.