paint-brush
Visualizing data in terminal using leharby@darxtrix
2,607 reads
2,607 reads

Visualizing data in terminal using lehar

by Ankush Sharma
Ankush Sharma HackerNoon profile picture

Ankush Sharma

@darxtrix

Senior Platform Engineer

August 18th, 2017
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<strong>TL;DR:</strong> The post is about a terminal visualization tool <strong>lehar</strong> that is open sourced at <a href="https://github.com/darxtrix/lehar" target="_blank">https://github.com/darxtrix/lehar</a>

Company Mentioned

Mention Thumbnail
Twitter
featured image - Visualizing data in terminal using lehar
Ankush Sharma HackerNoon profile picture
Ankush Sharma

Ankush Sharma

@darxtrix

Senior Platform Engineer

Sometimes insights can be drawn from visualizations of data rather than staring at it.

TL;DR: The post is about a terminal visualization tool lehar that is open sourced at https://github.com/darxtrix/lehar

While hacking on ptop last week, I thought of adding a network sensor to it but I was stuck thinking how will I visualize it to the end user. Just a heads up, ptop is a task manager in Python that I worked upon as a side project back in 2015. It went on to hit the list of trending repositories on GitHub.

A network sensor will basically show the current incoming/outgoing data on the network to the user. For eg. the CPU sensor of ptop showing the CPU info looks like this:

image

CPU usage info in ptop

One distinction we can draw from here is that in case of sensors like CPU, memory we have an upper_bound but in case of a network sensor we don’t have one. So the visualization should make user understand that the network utilization was more at a point t1 as compared to a point t2 along with showing the up-speed & down-speed, so relative ordering of data is needed here.

I tried to draw an analogy with the standard sorting problem where the data can be as random as network speed at a certain point of time(position in case of sorting). So, I wanted to come up with a way to show the movement(swaps) in case of a standard sorting algorithm, i.e something like this GIF:

image

Spark provides a shell command for creating such visualizations out of data but I can’t find any Python library for this. So I wrote lehar. lehar can be used as a Python2 and Python3 module and at the same time it can be used as shell command. The code is open sourced at GitHub


lehar uses the relative ordering of data to represent it. For eg. data = [1,2,3,4,5] will be represented as ▂▄▅▇█ ( increasing heights)

For drawing such visualizations, just call the dead simple lehar API in your Python code. For eg. the code I used for drawing the above visualizations is a slight modification of the standard Selection Sort program where instead of moving smaller elements in the front of the array, the larger ones’ are moved towards the end. Apart from that, we are just printing partially sorted data at line#10 and giving a time delay in line#21 with a carriage return following in next line to print things in the same line in the terminal

image

And, yes lehar has support for colors too !

And finally, the network sensor can be visualized like this along with the network stats:

image

Network visualization ptop

You can contribute to lehar and find the usage instructions at https://github.com/darxtrix/lehar/

In case you liked the story, hit claps. For any reviews/thoughts or any alternate ways to show this info in terminal do comment here.

Let’s share and connect on Twitter @darxtrix

image

Comment on this Story
L O A D I N G
. . . comments & more!

About Author

Ankush Sharma HackerNoon profile picture
Ankush Sharma@darxtrix
Senior Platform Engineer

TOPICS

THIS ARTICLE WAS FEATURED IN...

Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Schockwellenreiter

Mentioned in this story

companies
X REMOVE AD