{ "info": { "author": "Daniel A Hagen", "author_email": "dhagen@usc.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "# Collection of useful python functions/features.\nPrepared by: Daniel A Hagen \n[![Build Status](https://travis-ci.com/danhagen/danpy.svg?branch=master)](https://travis-ci.com/danhagen/danpy)\n[![PEP8](https://img.shields.io/badge/code%20style-pep8-green.svg)](https://www.python.org/dev/peps/pep-0008/)\n[![Coverage Status](https://coveralls.io/repos/github/danhagen/danpy/badge.svg?branch=master&service=github)](https://coveralls.io/github/danhagen/danpy?branch=master&service=github)\n\n## Installation\n```py\npip install danpy\n```\n\n## Installation from GitHub\n```bash\ngit clone https://github.com/danhagen/danpy.git && cd danpy\npip install -r requirements.txt\npip install .\n```\n\n\n## Statusbar for Python `for/while` loops with `danpy.sb`\nThis helpful statusbar can be used with `for/while` loops to keep track of how much time has elapsed as well as how much time remains. Simply place inside the loop (after initializing the statusbar -- `dsb` -- with `final_value`) and `update` with the current timestep (i). A `title` can be added to the statusbar to keep track of individual function/loops and it is recommended that any function that runs a loop uses `arbitrary_function_name.__name__` to automatically assign an appropriate title. The `initial_value` can also be initialized or left at default (0).\n\n### Initialize statusbar before running a for/while loop.\n```py\nfrom danpy.sb import *\nfrom time import sleep\n\ninitial_value = 0\nfinal_value = 10\nstatusbar = dsb(initial_value,final_value,title='a Loop')\nfor i in range(final_value):\n sleep(0.5)\n statusbar.update(i)\n```\n\nIt is useful to either `reset` the statusbar instance. However, loops run in succession will automatically reset if the loops are of the same size.\n\n```py\nfrom danpy.sb import *\nfrom time import sleep\n\ninitial_value = 0\nfinal_value = 10\nnumber_of_outside_loops = 3\nstatusbar = dsb(initial_value,final_value,title=\"Loop-D-Loops\")\nfor j in range(number_of_outside_loops):\n for i in range(final_value):\n sleep(0.5)\n statusbar.update(i)\n```\nIt is also possible to rename loops when they are run in succession by using the updating `title`.\n\n```py\nfrom danpy.sb import *\nfrom time import sleep\n\ninitial_value = 0\nfinal_value = 10\nstatusbar = dsb(initial_value,final_value,title=\"a Loop\")\nfor i in range(final_value):\n sleep(0.5)\n statusbar.update(i)\n\nfor i in range(final_value):\n sleep(0.5)\n statusbar.update(i,title=\"a Different Loop\")\n```\n\nHowever, these automatic reset features will only work if the length of each loop is the same *and* they have the same starting value. If you wish to run consecutive loops with *different* starting values or loop lengths, then you can `reset` the statusbar. It should be noted that the automatic reset, although convenient, will initialize the `start_time` after the first iteration of the loop. Therefore it is not the most accurate representation of runtime. We recommend a hard reset between trials or a redefinition of the statusbar before each loop.\n\n### Resetting Statusbar\n\nA statusbar can be reset by calling the builtin function `reset` one of two way; `reset()` will return a statusbar with the previously used `initial_value`, `final_value`, and `title`, or `reset(**kwargs)` can manually reset any of those values (while the others are kept as previously define).\n\n```py\nfrom danpy.sb import *\nfrom time import sleep\n\ninitial_value = 0\nfinal_value = 10\nstatusbar = dsb(initial_value,final_value,title='One Loop')\nfor i in range(final_value):\n sleep(0.5)\n statusbar.update(i)\n\na_different_final_value = 1010\na_different_initial_value = 1000\nstatusbar.reset(\n initial_value=a_different_initial_value,\n final_value=a_different_final_value,\n title=\"Another Loop\")\nfor i in range(a_different_initial_value,a_different_final_value):\n sleep(0.5)\n statusbar.update(i)\n```\n\n### Using `while` Loops\nIf using a `while` loop, the statusbar will still update, but depending on the nature of the code in the loop, the extrapolation to determine time remaining may be off.\n\n```py\nfrom danpy.sb import *\nfrom time import sleep\n\ncount = 0\nfinal_count = 10\nstatusbar = dsb(count,final_count,title=\"a while Loop\")\nwhile count