Skip to content

Commit

Permalink
HARMONY-1876: Populate all 3 dataset cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durbin committed Jan 7, 2025
1 parent 2724876 commit 7cfad7e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 51 deletions.
44 changes: 11 additions & 33 deletions services/harmony/app/frontends/free-text-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,7 @@ interface GeneratedHarmonyRequestParameters {
}

interface CmrAndHarmonyResponse {
collection: string;
collectionName: string;
variable: string;
variableName: string;
variableDefinition: string;
statusUrl: string;
granuleCount: string;
collections: any;
}

Expand Down Expand Up @@ -323,7 +317,8 @@ export async function freeTextGetCmrResults(

console.log(`Top 3 collections with granules matching spatial and temporal search: ${JSON.stringify(collConceptIds)}`);

const collectionInfo = {};
const collectionsInfo = [];
let i = 0;
for (const collectionId of collConceptIds) {
// Query for the top 5 variables by similarity for that collection ID
const topVariablesSQL = `SELECT collection_name, variable_id, variable_name, variable_definition, 1 - (embedding <=> '[${embedding}]') AS similarity FROM umm_embeddings WHERE collection_id = '${collectionId}' ORDER BY similarity DESC LIMIT 5;`;
Expand All @@ -332,28 +327,17 @@ export async function freeTextGetCmrResults(

now = logPerf(now, 'Query database for top variables');

// for (const row of dbVarResults.rows) {
console.log(`Top 5 variables: ${JSON.stringify(dbVarResults.rows)}`);
// }
collectionInfo[collectionId] = dbVarResults.rows;
const collectionInfo = dbVarResults.rows;
collectionInfo[0].collection_id = collectionId;
collectionInfo[0].granule_count = collsWithGranules[i].granule_count;
collectionsInfo.push(collectionInfo);
i = i + 1;
}

let collectionId = null;
let collectionName = null;
let variableId = null;
let variableName = null;
let variableDefinition = null;
let granuleCount = null;

// The first collection in the embedding query result that has granules is the best match
console.log(JSON.stringify(collectionsInfo));
if (collConceptIds.length > 0) {
collectionId = collConceptIds[0];
collectionName = collectionInfo[collectionId][0].collection_name;
variableId = collectionInfo[collectionId][0].variable_id;
variableName = collectionInfo[collectionId][0].variable_name;
variableDefinition = collectionInfo[collectionId][0].variable_definition;
granuleCount = collsWithGranules[0].granule_count;
console.log(`BEST MATCH: COLLECTION ID: ${collectionId} VARIABLE ID: ${variableId} SIMILARITY: ${collectionInfo[collectionId][0].similarity}`);
console.log(`Found ${collConceptIds.length} matching collections`);
} else {
console.log('No matching collections are found');
}
Expand All @@ -365,17 +349,11 @@ export async function freeTextGetCmrResults(
queryParams.format = outputFormat;
}

const harmonyJob = await submitHarmonyRequest(collectionId, variableId, queryParams, geoJson, req.accessToken);
const harmonyJob = await submitHarmonyRequest(collectionsInfo[0][0].collection_id, collectionsInfo[0][0].variable_id, queryParams, geoJson, req.accessToken);
logPerf(now, 'submit harmony request');
const cmrResults: CmrAndHarmonyResponse = {
collection: collectionId,
collectionName,
variable: variableId,
variableName,
variableDefinition,
statusUrl: harmonyJob.links[2].href,
collections: collectionInfo,
granuleCount,
collections: collectionsInfo,
};

res.send(cmrResults);
Expand Down
42 changes: 24 additions & 18 deletions services/harmony/app/views/free-text-query/index.mustache.html
Original file line number Diff line number Diff line change
Expand Up @@ -516,24 +516,30 @@ <h2 id="dataset-title-3" class="dataset-title"></h2>
});

const data = await response.json();
const datasetId = 1;
const datasetElement = document.getElementById(`dataset-container-${datasetId}`);

const datasetTitle = datasetElement.querySelector(`#dataset-title-${datasetId}`);
datasetTitle.textContent = `${data.collectionName} (`;
const link = document.createElement('a');
link.href = `https://cmr.uat.earthdata.nasa.gov/concepts/${data.collection}`;
link.textContent = data.collection;
link.target = '_blank';
datasetTitle.appendChild(link);
datasetTitle.appendChild(document.createTextNode(')'));

const variableTitle = datasetElement.querySelector(`#variable-title-${datasetId}`);
variableTitle.textContent = `${data.variableName} (${data.variable})`;
const variableDescription = datasetElement.querySelector(`#variable-description-${datasetId}`);
variableDescription.textContent = data.variableDefinition;
const granuleCount = datasetElement.querySelector(`#granule-count-${datasetId}`);
granuleCount.textContent = data.granuleCount;
let datasetId = 0
for (const collectionInfo of data.collections) {
datasetId = datasetId + 1;

const dataset = collectionInfo[0];
// const datasetId = 1;
const datasetElement = document.getElementById(`dataset-container-${datasetId}`);

const datasetTitle = datasetElement.querySelector(`#dataset-title-${datasetId}`);
datasetTitle.textContent = `${dataset.collection_name} (`;
const link = document.createElement('a');
link.href = `https://cmr.uat.earthdata.nasa.gov/concepts/${dataset.collection_id}`;
link.textContent = dataset.collection_id;
link.target = '_blank';
datasetTitle.appendChild(link);
datasetTitle.appendChild(document.createTextNode(')'));

const variableTitle = datasetElement.querySelector(`#variable-title-${datasetId}`);
variableTitle.textContent = `${dataset.variable_name} (${dataset.variable_id})`;
const variableDescription = datasetElement.querySelector(`#variable-description-${datasetId}`);
variableDescription.textContent = dataset.variable_definition;
const granuleCount = datasetElement.querySelector(`#granule-count-${datasetId}`);
granuleCount.textContent = dataset.granule_count;
}

status.innerHTML = 'Waiting for harmony output';
pollJobStatus(data.statusUrl);
Expand Down

0 comments on commit 7cfad7e

Please sign in to comment.