-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e239326
commit 5a4b89c
Showing
3 changed files
with
51 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Blue Brain Project - EPFL, 2024 | ||
"""A library of functions shared across tools. | ||
""" | ||
|
||
import math | ||
import os | ||
import sys | ||
|
||
PROGRESS_STEPS = 50 | ||
DEFAULT_HISTOGRAM_NBINS = 40 | ||
|
||
|
||
def show_histogram(buckets, n_bins=DEFAULT_HISTOGRAM_NBINS): | ||
"""A simple histogram CLI visualizer""" | ||
import numpy # optional | ||
MiB = float(1 << 20) | ||
freq, bins = numpy.histogram(buckets, bins=n_bins) | ||
bin_start = bins[0] | ||
for count, bin_end in zip(freq, bins[1:]): | ||
if count: | ||
print(f" [{bin_start/MiB:5.0f} - {bin_end/MiB:5.0f}]: {count:0d}") | ||
bin_start = bin_end | ||
|
||
|
||
def get_dat_entry_size(base_dir, dat_entry): | ||
"""Obtain the file size of a dat entry""" | ||
dat_file = f"{dat_entry}_2.dat" | ||
file_path = os.path.join(base_dir, dat_file) | ||
return os.path.getsize(file_path) | ||
|
||
|
||
def with_progress(elements): | ||
"""A quick and easy generator for displaying progress while iterating""" | ||
total_elems = len(elements) | ||
report_every = math.ceil(total_elems / PROGRESS_STEPS) | ||
print(f"Processing {total_elems} entries") | ||
for i, elem in enumerate(elements): | ||
if i % report_every == 0: | ||
print(f"{i:10} [{i*100/total_elems:3.0f}%]", file=sys.stderr) | ||
yield elem |