Skip to content

Commit

Permalink
Use searchengine instead of studies.tsv for image counts
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Mar 6, 2024
1 parent f96d66c commit f5d845a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
4 changes: 2 additions & 2 deletions idr_gallery/static/idr_gallery/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function imageCount(idrId, container) {
}

let imgCount = containers
.map((row) => row["5D Images"])
.map((row) => row["image count"])
.reduce((total, value) => total + parseInt(value, 10), 0);
return (
new Intl.NumberFormat().format(imgCount) +
Expand Down Expand Up @@ -294,7 +294,7 @@ model.loadStudyStats(IDR_STUDIES_URL, function (stats) {
console.log("Failed to filter studies stats by category");
}
}
let imageCounts = containers.map((row) => row["5D Images"]);
let imageCounts = containers.map((row) => row["image count"]);
totalImages = imageCounts.reduce(
(total, value) => total + parseInt(value, 10),
0
Expand Down
91 changes: 49 additions & 42 deletions idr_gallery/static/idr_gallery/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,51 +508,58 @@ class StudiesModel {
}

loadStudyStats = function (url, callback) {
let self = this;
$.get(url, function (data) {
let tsvRows = data.split("\n");
let columns;
// read tsv => dicts
let rowsAsObj = tsvRows
.map(function (row, count) {
let values = row.split("\t");
if (count == 0) {
columns = values;
return;
}
if (values.length === 0) return;
let row_data = {};
for (let c = 0; c < values.length; c++) {
if (c < columns.length) {
row_data[columns[c]] = values[c];
}

const queryJson = {
"resource": "image",
"query_details": {
"and_filters": [
{
"name": "name",
"value": "idr",
"operator": "contains",
"resource": "container"
}
return row_data;
})
.filter(Boolean);

// Group rows by Study
let stats = {};
rowsAsObj.forEach((row) => {
let studyName = row["Study"];
if (!studyName) return;
let studyId = studyName.split("-")[0];
if (!stats[studyId]) {
stats[studyId] = [];
}
stats[studyId].push(row);
});
],
"or_filters": [],
"case_sensitive": false
}
};

self.studyStats = stats;
const searchurl = SEARCH_ENGINE_URL + "resources/submitquery/containers/";

if (callback) {
callback(stats);
}
}).fail(function () {
console.log("Failed to load studies.tsv");
if (callback) {
callback();
}
console.log("searchurl", searchurl)
let self = this;

$.ajax({
type: "POST",
url: searchurl,
contentType: "application/json;charset=UTF-8",
dataType: "json",
data: JSON.stringify(queryJson),
success: function (data) {
console.log(data);

// Group rows by Study
let stats = {};
data.results.results.forEach((row) => {
// row is {id: 501, image count: 5931242, name: idr..., type: project, key_values: []}
let studyName = row["name"];
if (!studyName) return;
let studyId = studyName.split("-")[0];
if (!stats[studyId]) {
stats[studyId] = [];
}
stats[studyId].push(row);
});

self.studyStats = stats;
if (callback) {
callback(stats);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("Failed to load study stats")
},
});
};
}
Expand Down

0 comments on commit f5d845a

Please sign in to comment.