Skip to content
bitranoxPublic

Latest commit

 

History

168 Commits

Folders and files

Repository files navigation

lib_cast

Pypi Status license maintenance

Build Status Codecov Status Better Code Maintainability Code Coverage snyk security

cast float, int, time, file sizes etc. to human readable text with SI Prefixes

it can also be used on the commandline for windows and linux bash

>>> # cast floating point values
>>> cast_float_to_human_readable_size(1000,'Volt')
'1.00 KiloVolt (x10^3)'
>>> cast_float_to_human_readable_size(0.1,'Volt')
'100.00 MilliVolt (x10^-3)'
>>> cast_float_to_human_readable_size(0.1,'V', short_form=True)
'100.00 mV (x10^-3)'
>>> cast_float_to_human_readable_size(0.1,'V', short_form=True, show_exponent=False)
'100.00 mV'
>>> cast_float_to_human_readable_size(0.1,'V', short_form=True, show_exponent=False, remove_trailing_zeros=True)
'100 mV'

>>> # cast byte or bit sizes
>>> cast_float_to_human_readable_size(65535,base1024=True)
'64 KibiByte (x1024^1)'

>>> # cast time german
>>> cast_float_2_human_readable_timediff(2455.456898418)
'40 Minuten, 55 Sekunden'

>>> # cast time english
>>> cast_float_2_human_readable_timediff(2455.456898418, language='en')
'40 minutes, 55 seconds'

>>> # cast looong time german
>>> cast_float_2_human_readable_timediff(89452.456898418)
'  1 Tage,  0 Stunden, 50 Minuten, 52 Sekunden'

>>> # AND MANY MORE ! - see usage !
IEC Prefixe (2**n)                  ISO Prefixe (10**-n)                ISO Prefixe (10**n)
=======================             =======================             =======================
'Ki', 'Kibi', (x1024^1)             'm', 'Milli', (x10^-3)              'k', 'Kilo' , (x10^3)
'Mi', 'Mebi', (x1024^2)             'µ', 'Mikro', (x10^-6)              'M', 'Mega' , (x10^6)
'Gi', 'Gibi', (x1024^3)             'n', 'Nano' , (x10^-9)              'G', 'Giga' , (x10^9)
'Ti', 'Tebi', (x1024^4)             'p', 'Piko' , (x10^-12)             'T', 'Tera' , (x10^12)
'Pi', 'Pebi', (x1024^5)             'f', 'Femto', (x10^-15)             'P', 'Peta' , (x10^15)
'Ei', 'Exbi', (x1024^6)             'a', 'Atto' , (x10^-18)             'E', 'Exa'  , (x10^18)
'Zi', 'Zebi', (x1024^7)             'z', 'Zepto', (x10^-21)             'Z', 'Zetta', (x10^21)
'Yi', 'Yobi', (x1024^8)             'y', 'Yokto', (x10^-24)             'Y', 'Yotta', (x10^24)

automated tests, Travis Matrix, Documentation, Badges for this Project are managed with lib_travis_template - check it out

supports python 3.6-3.8, pypy3 and possibly other dialects.

100% code coverage, mypy static type checking, tested under Linux, macOS, Windows and Wine, automatic daily builds and monitoring



Installation and Upgrade

Before You start, its highly recommended to update pip and setup tools:

python3 -m pip --upgrade pip
python3 -m pip --upgrade setuptools
python3 -m pip --upgrade wheel

install latest version with pip (recommended):

# upgrade all dependencies regardless of version number (PREFERRED)
python3 -m pip install --upgrade git+https://github.com/bitranox/lib_cast.git --upgrade-strategy eager

# test without installing (can be skipped)
python3 -m pip install git+https://github.com/bitranox/lib_cast.git --install-option test

# normal install
python3 -m pip install --upgrade git+https://github.com/bitranox/lib_cast.git

install latest pypi Release (if there is any):

# latest Release from pypi
python3 -m pip install --upgrade lib_cast

# test without installing (can be skipped)
python3 -m pip install lib_cast --install-option test

# normal install
python3 -m pip install --upgrade lib_cast

include it into Your requirements.txt:

# Insert following line in Your requirements.txt:
# for the latest Release on pypi (if any):
lib_cast
# for the latest Development Version :
lib_cast @ git+https://github.com/bitranox/lib_cast.git

# to install and upgrade all modules mentioned in requirements.txt:
python3 -m pip install --upgrade -r /<path>/requirements.txt

Install from source code:

# cd ~
$ git clone https://github.com/bitranox/lib_cast.git
$ cd lib_cast

# test without installing (can be skipped)
python3 setup.py test

# normal install
python3 setup.py install

via makefile:

if You are on linux, makefiles are a very convenient way to install. Here we can do much more, like installing virtual environment, clean caches and so on. This is still in development and not recommended / working at the moment:

# from Your shell's homedirectory:
$ git clone https://github.com/bitranox/lib_cast.git
$ cd lib_cast

# to run the tests:
$ make test

# to install the package
$ make install

# to clean the package
$ make clean

# uninstall the package
$ make uninstall

Usage

import the module and check the code - its easy and documented there, including doctest examples.
in case of any questions the usage section might be expanded at a later time

Usage from Commandline

Usage:
    lib_cast (-h | -v | -i)

Options:
    -h, --help          show help
    -v, --version       show version
    -i, --info          show Info

this module exposes no other useful functions to the commandline

Requirements

following modules will be automatically installed :

## Project Requirements
docopt
lib_csv @ git+https://github.com/bitranox/lib_csv.git
btx_lib_list
lib_regexp @ git+https://github.com/bitranox/lib_regexp.git

Acknowledgements

  • special thanks to "uncle bob" Robert C. Martin, especially for his books on "clean code" and "clean architecture"

Contribute

I would love for you to fork and send me pull request for this project. - please Contribute

License

This software is licensed under the MIT license

---

Changelog

0.1.0

2020-05-24:
  • new build matrix
  • mypy strict type testing
  • fix title in pypi documentation
  • drop python2.7 - python 3.4 support

0.0.3

2019-09-03: update setup.py

0.0.2

2019-09-03: refractor

0.0.1

2019-07-22: Initial public release

Releases

Packages

Used by

Contributors

Languages