wizzat / distribution Goto Github PK
View Code? Open in Web Editor NEWShort, simple, direct scripts for creating ASCII graphical histograms in the terminal.
License: GNU General Public License v2.0
Short, simple, direct scripts for creating ASCII graphical histograms in the terminal.
License: GNU General Public License v2.0
Because the "tokenize" parameter is tested for existence, it's challenging to tokenize on "nothing" (which would split everything into individual characters)
Notably, there is also a difference in behavior between the Python and Perl implementations, in that distribution.py will successfully split on "0", while Perl will act as though I hadn't passed anything tokenize parameter in at all, with "-t=0"
The Perl-with-zero behavior should be easy to fix, but I'd suggest adding another special "tokenize" value (along with the existing "white" and "word") of "char" or something similar.
I'm not very experienced with Python, and while in Perl you can simply add a line like
elsif ($tokenize eq 'char') { $tokenize = ''; }
as far as I can tell, Python will not behave that way with splitting on an empty regex. And it's also beyond me how to properly test for "None" vs. some other existence thing to see if it was defined at all on the command line.
Anyway, there's always a work-around for now to split the entire thing before it even gets in.
e.g.
cat theFile | perl -ne 'print join "\n", split //' | distribution
But it feels like something that should be available more easily.
The "runTests" script has a few items that I'm curious about:
Python:
^[[32m /etc/mateconf|^[[34m7780758 ^[[35m(44.60%) ^[[37m••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••^[[0m
Perl:
/etc/mateconf^[[0m |^[[32m7780758 ^[[35m(44.60%) ^[[34m••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••^[[0m
It seems distribution does not handle special characters well:
Chelsea Wolfe - Abyss |44 (17.46%) ▬▬▬▬▬▬▬▬
Chelsea Wolfe - Ἀποκάλυψις |23 (9.13%) ▬▬▬▬
Thanks!
Currently, if using options that colorize the output, distribution
doesn't player super nicely when piping its output to another command, or redirecting it to a file, due to the the shell escape sequences used for colorizing the output.
For example, if your default options have color enabled, and you redirect the output to a file, opening that file in a text editor results in something like this (note all of the escape sequences):
342191L:25�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:24�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:23�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:22�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:21�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:20�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:19�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:18�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:17�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:16�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:15�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:14�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:13�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:12�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
342191L:11�[0m|�[32m1 �[35m(3.85%) �[34m█████████████████████▏�[0m
I propose extending the --color
option to have three options, always
, never
, and auto
, similar to POSIX tools like grep
and ls
. The auto
option detects whether the output is a terminal, and only enables color if so.
This seems like a minor thing, but it would be helpful to have the ability to read from one or more files passed as command line options instead of standard input.
This could save some keystrokes especially in the case of reading from multiple files, where instead of cat /foo/bar/* | distribution
you can do distribution /foo/bar/*
.
Opening this to track fixing up inconsistencies between Perl and Python versions, but only insofar as such differences make it difficult to run tests, per #10
Opened a branch (https://github.com/tstearns/distribution/tree/perl-python-trueup) to propose fixes, with item 1 above done, and the other two to follow, will open the branch merge as a PR for review when done, referencing this ticket.
Is it possible to tag a new release with the latest changes? I'd like to make a distribution
package for OpenBSD, and will base it on the next release tag. Thanks!
Change the shebang to python2 maybe?
Please document installation instructions in README.md
Hello,
does "distribution" has support for "buckets"? In other words, can keys be grouped together by value?
Example: when reading input with values in range 0-255, is there a way to create a histogram like this?
cat /dev/urandom | od -tu1 -w1 -An -v | head -10000 | histogram.py | cut -d: -f1
0.0000 - 25.5000 [ 1052]
25.5000 - 51.0000 [ 994]
51.0000 - 76.5000 [ 976]
76.5000 - 102.0000 [ 997]
102.0000 - 127.5000 [ 989]
127.5000 - 153.0000 [ 1075]
153.0000 - 178.5000 [ 965]
178.5000 - 204.0000 [ 982]
204.0000 - 229.5000 [ 986]
229.5000 - 255.0000 [ 984]
Thanks a lot!
Jirka
❯❯❯ seq 5 |distribution.py
Traceback (most recent call last):
File "/usr/local/bin/distribution.py", line 536, in <module>
main(sys.argv[1:])
File "/usr/local/bin/distribution.py", line 520, in main
s = Settings()
File "/usr/local/bin/distribution.py", line 336, in __init__
if '--rcfile' in sys.argv[1]:
IndexError: list index out of range
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.