Giter Club home page Giter Club logo

dynamictable's Introduction

DynamicTable

An easy and user-friendly way to display dynamic data in Python

author: Manu Blanco Valentin
github: manuelblancovalentin
version: v0.0.4

What is this module intended for?

DynamicTable is a module designed to provide an easy way for Python3+ users to display dynamic data in a tabular way in the command line in an easy and compact way.

Using the DynamicTable object is as easy as it comes. Simply initialize the header and update/append lines to the table as many times as desired.

Even though DynamicTable is great for displaying static data, it might be more useful for displaying data that constantly changes inside a loop or a recursive activity. For instance, DynamicTable can be used inside a custom loop when training a model, to display the training process.

Take a look at an example (code provided below).

Example Result

How to install?

To start using DynamicTable simply install it via pip using the following command:

pip install DynamicTable

Extra documentation about the module can be found in our pypi page:

https://pypi.org/project/DynamicTable/

How to use DynamicTable?

There are basically four instructions to be considered when using DynamicTable:

  • Initialization: DynamicTable must be initialized with a list of strings for the header and, optionally, a formatter for each one of the entries in header. Valid formatters are those accepted in common Python3+ string formatting ops (see here). Apart from these, an special format is accepted, denoted by $% which is used for displaying progress bars.

  • Print header: Once the object has been instantiated, the header can be printed using the instruction <DynamicTableObject>.print_header()

  • Update line: To update the values, simply pass a dictionary with a value (or list of values) for each entry in the header. Two flags are very useful when updating the values of the table:

    • append (default = False): If true, the values introduced will be stored in a new row. If false, the last row will be updated.
    • print (default = True): If true, the values will be printed into the table.

    <DynamicTableObject>.update_line(values, append = <True/False>, print = <True/False>)

  • Print bottom: Print the bottom part of the table once the loop is exited.

Take a look at this demo snippet (which produces the result displayed in the GIF above):

""" Import basic modules """
import time
import numpy as np
	
""" Import DynamicTable """
from DynamicTable import DynamicTable
	
""" Init table """
header = ['Epoch','Progress','loss_labels']
formatters = {'Epoch':'{:03d}', 'Progress':'%$', 'loss_labels':'{:.3f}'}
progress_table = DynamicTable(header, formatters)
	
""" Print header """
progress_table.print_header()
	
""" Loop thru iters """
for i in range(5):
    time.sleep(1)
    for b in range(100):
        """ Perform some action here
	
            ...
	
        """
        time.sleep(.01)
	
        """ Get updated values to be set into table """
        vals = {'Epoch': i, 'Progress': b/99, 'loss_labels': 100*np.random.randn()}
	
        """ Update and print line """
        progress_table.update_line(vals, append = b == 99, print = True)
	
""" As we exit the loop, print the bottom of the table """
progress_table.print_bottom()

How to cite this work?

Please, if you found my work valuable and it was useful for you, consider citing it in any published work that used it to help me improve the visibility of my code and make it easier for other people to access it.

If so, use the following bibtex entry in your paper:

@misc{MBValentin2020DynamicTable,
  author = {Valentin, Manuel Blanco},
  title = {Dynamic Table: An easy and user-friendly way to display dynamic data in Python},
  year = {2020},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/manuelblancovalentin/DynamicTable}}
}

dynamictable's People

Contributors

manuelblancovalentin avatar

Stargazers

 avatar  avatar

Watchers

 avatar

dynamictable's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.