Skip to content

Commit a0d2135

Browse files
Updates & debugs (#20)
* feat: add compatability for new structuree * feat: update base branch * feat: add pre-commit * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: add pre-commit --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ea19dba commit a0d2135

File tree

4 files changed

+74
-46
lines changed

4 files changed

+74
-46
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# PyCharm
2-
.idea/*
2+
.idea/*

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
default_install_hook_types:
2+
- pre-commit
3+
- commit-msg
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v5.0.0
8+
hooks:
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
13+
- repo: https://github.com/codespell-project/codespell
14+
rev: v2.4.1
15+
hooks:
16+
- id: codespell
17+
additional_dependencies:
18+
- tomli
19+
20+
- repo: https://github.com/compilerla/conventional-pre-commit
21+
rev: v4.2.0
22+
hooks:
23+
- id: conventional-pre-commit
24+
stages: [commit-msg]
25+
args: [--verbose]

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<title>Dandiset Access Summaries</title>
88

9+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js-yaml.min.js"></script>
910
<script src="https://cdn.plot.ly/plotly-3.0.1.min.js" charset="utf-8"></script>
1011
<script src="errors.js" defer></script>
1112
<script src="plots.js" defer></script>

plots.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const BASE_URL = "https://raw.githubusercontent.com/dandi/access-summaries/main"
66
const BASE_TSV_URL = `${BASE_URL}/content/summaries`;
77

88
const ARCHIVE_TOTALS_URL = `${BASE_URL}/content/archive_totals.json`;
9-
const ALL_DANDISET_TOTALS_URL = `${BASE_URL}/content/all_dandiset_totals.json`;
10-
const REGION_CODES_TO_LATITUDE_LONGITUDE_URL = `${BASE_URL}/content/region_codes_to_coordinates.json`;
9+
const ALL_DANDISET_TOTALS_URL = `${BASE_URL}/content/totals.json`;
10+
const REGION_CODES_TO_LATITUDE_LONGITUDE_URL = `${BASE_URL}/content/region_codes_to_coordinates.yaml`;
1111

1212
let REGION_CODES_TO_LATITUDE_LONGITUDE = {};
1313
let ALL_DANDISET_TOTALS = {};
@@ -28,11 +28,11 @@ window.addEventListener("load", () => {
2828
if (logScaleCheckbox) {
2929
logScaleCheckbox.addEventListener("change", function() {
3030
USE_LOG_SCALE = this.checked;
31-
31+
3232
// Get the current dandiset ID
3333
const dandiset_selector = document.getElementById("dandiset_selector");
3434
const selected_dandiset = dandiset_selector.value;
35-
35+
3636
// Reload plots with the current dandiset ID
3737
load_over_time_plot(selected_dandiset);
3838
load_per_asset_histogram(selected_dandiset);
@@ -112,15 +112,15 @@ function resizePlots() {
112112
fetch(REGION_CODES_TO_LATITUDE_LONGITUDE_URL)
113113
.then((response) => {
114114
if (!response.ok) {
115-
throw new Error(`Failed to fetch JSON file: ${response.statusText}`);
115+
throw new Error(`Failed to fetch YAML file: ${response.statusText}`);
116116
}
117-
return response.json();
117+
return response.text();
118118
})
119119
.then((data) => {
120-
REGION_CODES_TO_LATITUDE_LONGITUDE = data;
120+
REGION_CODES_TO_LATITUDE_LONGITUDE = jsyaml.load(data);
121121
})
122122
.catch((error) => {
123-
console.error("Error loading JSON file:", error);
123+
console.error("Error loading YAML file:", error);
124124
});
125125

126126
fetch(ARCHIVE_TOTALS_URL)
@@ -153,7 +153,20 @@ fetch(ALL_DANDISET_TOTALS_URL)
153153
})
154154
.then((all_dandiset_totals_text) => {
155155
Object.assign(ALL_DANDISET_TOTALS, JSON.parse(all_dandiset_totals_text));
156-
const dandiset_ids = Object.keys(ALL_DANDISET_TOTALS);
156+
let dandiset_ids = Object.keys(ALL_DANDISET_TOTALS);
157+
dandiset_ids.sort((a, b) => {
158+
if (a === "archive") return -1;
159+
if (b === "archive") return 1;
160+
// Compare as numbers if both are numeric
161+
const aNum = Number(a);
162+
const bNum = Number(b);
163+
if (!isNaN(aNum) && !isNaN(bNum)) {
164+
return aNum - bNum;
165+
}
166+
// Fallback to string comparison
167+
return a.localeCompare(b);
168+
});
169+
157170
const selector = document.getElementById("dandiset_selector");
158171

159172
if (!selector) {
@@ -208,7 +221,7 @@ function update_totals(dandiset_id) {
208221
const footnote = document.createElement("div");
209222
footnote.style.fontSize = "0.5em";
210223
footnote.style.marginTop = "7px";
211-
footnote.innerHTML = "<sup>*</sup> These values are only estimates for publically released datasets and are subject to change as additional information becomes available.";
224+
footnote.innerHTML = "<sup>*</sup> These values are only estimates for publicly released datasets and are subject to change as additional information becomes available.";
212225
totals_element.appendChild(footnote);
213226
} catch (error) {
214227
console.error("Error:", error);
@@ -221,13 +234,7 @@ function update_totals(dandiset_id) {
221234
// Function to fetch and render the over time for a given Dandiset ID
222235
function load_over_time_plot(dandiset_id) {
223236
const plot_element_id = "over_time_plot";
224-
let by_day_summary_tsv_url;
225-
226-
if (dandiset_id === "archive") {
227-
by_day_summary_tsv_url = `${BASE_TSV_URL}/archive_summary_by_day.tsv`;
228-
} else {
229-
by_day_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/dandiset_summary_by_day.tsv`;
230-
}
237+
let by_day_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/by_day.tsv`;
231238

232239
fetch(by_day_summary_tsv_url)
233240
.then((response) => {
@@ -261,8 +268,9 @@ function load_over_time_plot(dandiset_id) {
261268

262269
const plot_info = [
263270
{
264-
type: "scatter",
265-
mode: "lines+markers",
271+
//type: "scatter",
272+
//mode: "lines+markers",
273+
type: "bar",
266274
x: dates, // Use raw dates for proper alignment
267275
y: plot_data,
268276
text: dates.map((date, index) => `${date}<br>${human_readable_bytes_sent[index]}`),
@@ -310,7 +318,7 @@ function load_over_time_plot(dandiset_id) {
310318
// Function to fetch and render histogram over asset IDs
311319
function load_per_asset_histogram(dandiset_id) {
312320
const plot_element_id = "per_asset_histogram";
313-
let by_day_summary_tsv_url = "";
321+
let by_asset_summary_tsv_url = "";
314322

315323
// Suppress div element content if 'archive' is selected
316324
if (dandiset_id === "archive") {
@@ -320,10 +328,10 @@ function load_per_asset_histogram(dandiset_id) {
320328
}
321329
return "";
322330
} else {
323-
by_day_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/dandiset_summary_by_asset.tsv`;
331+
by_asset_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/by_asset.tsv`;
324332
}
325333

326-
fetch(by_day_summary_tsv_url)
334+
fetch(by_asset_summary_tsv_url)
327335
.then((response) => {
328336
if (!response.ok) {
329337
throw new Error(`Failed to fetch TSV file: ${response.statusText}`);
@@ -346,23 +354,25 @@ function load_per_asset_histogram(dandiset_id) {
346354
throw new Error("Currently only supports NWB files.");
347355
}
348356

349-
// TODO: this was a heuristic idea for shortening the asset names
350-
// const subject_and_session = filename.split("_");
351-
// const subject = subject_and_session.at(0).split("-").slice(1).join("-");
352-
// const session = subject_and_sessions.slice(1).split("-").slice(1).join("-");
353-
// return `${subject} ${session}`;
354-
355357
return filename;
356358
});
357359
const bytes_sent = data.map((row) => parseInt(row[1], 10));
358-
const human_readable_bytes_sent = bytes_sent.map((bytes) => format_bytes(bytes));
359360

361+
// Sort asset_names and bytes_sent in descending order by bytes_sent
362+
const combined = asset_names.map((name, idx) => ({ name, bytes: bytes_sent[idx] }));
363+
combined.sort((a, b) => b.bytes - a.bytes);
364+
365+
const sorted_asset_names = combined.map(item => item.name);
366+
const sorted_bytes_sent = combined.map(item => item.bytes);
367+
const human_readable_bytes_sent = sorted_bytes_sent.map((bytes) => format_bytes(bytes));
368+
369+
// Use sorted arrays in the plot
360370
const plot_data = [
361371
{
362372
type: "bar",
363-
x: asset_names,
364-
y: bytes_sent,
365-
text: asset_names.map((name, index) => `${name}<br>${human_readable_bytes_sent[index]}`),
373+
x: sorted_asset_names,
374+
y: sorted_bytes_sent,
375+
text: sorted_asset_names.map((name, index) => `${name}<br>${human_readable_bytes_sent[index]}`),
366376
textposition: "none",
367377
hoverinfo: "text",
368378
}
@@ -375,14 +385,10 @@ function load_per_asset_histogram(dandiset_id) {
375385
},
376386
xaxis: {
377387
title: {
378-
text: "Asset Name",
388+
text: "(hover over an entry for asset names)",
379389
font: { size: 16 }
380390
},
381391
showticklabels: false,
382-
// TODO: ticks are currently too long to fit since heuristic is not working well
383-
// tickangle: -45,
384-
// tickfont: { size: 10 },
385-
// automargin: true,
386392
},
387393
yaxis: {
388394
title: {
@@ -403,21 +409,17 @@ function load_per_asset_histogram(dandiset_id) {
403409
console.error("Error:", error);
404410
const plot_element = document.getElementById(plot_element_id);
405411
if (plot_element) {
406-
plot_element.innerText = "Failed to load data for per asset (current supports NWB datasets only).";
412+
while (plot_element.firstChild) {
413+
plot_element.removeChild(plot_element.firstChild);
414+
}
407415
}
408416
});
409417
}
410418

411419
// Function to fetch and render heatmap over geography
412420
function load_geographic_heatmap(dandiset_id) {
413421
const plot_element_id = "geography_heatmap";
414-
let by_region_summary_tsv_url;
415-
416-
if (dandiset_id === "archive") {
417-
by_region_summary_tsv_url = `${BASE_TSV_URL}/archive_summary_by_region.tsv`;
418-
} else {
419-
by_region_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/dandiset_summary_by_region.tsv`;
420-
}
422+
let by_region_summary_tsv_url = `${BASE_TSV_URL}/${dandiset_id}/by_region.tsv`;
421423

422424
if (!REGION_CODES_TO_LATITUDE_LONGITUDE) {
423425
console.error("Error:", error);

0 commit comments

Comments
 (0)