on-the-fly-stats


Nameon-the-fly-stats JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryOn the fly statistics including standard deviation, average, min/max and counters
upload_time2024-12-11 23:02:35
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords statistics utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            * website: <https://arrizza.com/python-on-the-fly-stats>
* installation: see <https://arrizza.com/setup-common>

## Summary

This Python module contains various statistic functions (e.g. standard deviation) that can
be updated on the fly i.e. the entire dataset is not needed up front.

* See [Quick Start](https://arrizza.com/user-guide-quick-start) for information on using scripts.
* See [xplat-utils submodule](https://arrizza.com/xplat-utils) for information on the submodule.

## Sample code

see sample.py for a full example

```python
from on_the_fly_stats import OTFStats

stats = OTFStats()

# create an instance of the std deviation
stats.create_stddev('some_tag')
# add some values to it
stats.update_stddev('some_tag', 1)
stats.update_stddev('some_tag', 2)
stats.update_stddev('some_tag', 3)

# have other instances of it
stats.update_stddev('other_tag', 0.1)
stats.update_stddev('other_tag', 0.2)
stats.update_stddev('other_tag', 0.3)

# show the current data for a specific instance
print(stats.stddev['some_tag'].stddev)
print(stats.stddev['some_tag'].variance)
print(stats.stddev['some_tag'].mean)
print(stats.stddev['some_tag'].num_elements)

# show the current data for a specific instance
print(stats.stddev['other_tag'].stddev)

# some a summary report
stats.set_report_writer(print)
stats.report_minimal()
# skip the headers for even less data
stats.report_minimal(headers=False)
```

## Min/Max

Holds the minimum and maximum of the values provided so far

```python
import random

from on_the_fly_stats import OTFStats

stats = OTFStats()

stats.create_min_max('minmax1')
for _ in range(10):
    stats.update_min_max('minmax1', random.randint(0, 10))

print(stats.min_max['minmax1'].minimum)
print(stats.min_max['minmax1'].maximum)
print(stats.min_max['minmax1'].num_elements)
```

## Average

Holds the average of the values provided so far

```python
import random

from on_the_fly_stats import OTFStats

stats = OTFStats()
stats.create_average('avg1')
stats.update_average('avg1', random.uniform(0, 10))
stats.update_average('avg1', random.uniform(0, 10))

print(stats.average['avg1'].average)
print(stats.average['avg1'].anum_elementss)
```

## Standard Deviation

Holds the standard deviation, mean and variance of the values provided so far

```python
import random

from on_the_fly_stats import OTFStats

stats = OTFStats()
stats.create_stddev('sd1')
stats.update_stddev('sd1', random.random())
stats.update_stddev('sd1', random.random())
stats.update_stddev('sd1', random.random())

print(stats.stddev['sd1'].stddev)
print(stats.stddev['sd1'].mean)
print(stats.stddev['sd1'].variance)
print(stats.stddev['sd1'].num_elementss)
```

### Counters

Holds counters of the values provided so far

```python
from on_the_fly_stats import OTFStats

stats = OTFStats()

# automatically create a counter
stats.inc_counter('counter1')
stats.inc_counter('counter1')  # should be 2
stats.dec_counter('counter2')  # should be -1
stats.inc_counter('counter3')
stats.dec_counter('counter3')  # should be 0

print(stats.counters['counter1'].count)
print(stats.counters['counter2'].count)
print(stats.counters['counter3'].count)
```

### Reports

There are two builtin reports:

* a minimal report
* a full report

To use the builtin reports a function that writes a single line must be provided.
The simplest is to use print().

```python
stats.set_report_writer(print)
stats.report_minimal()
stats.report()
```

## Minimal report output

The minimal report shows each stat kept and minimal data with minimal formatting

```text
Min/Max:
              0               7 minmax1
       0.019647        0.825751 minmax2
Average:
            4.495221 avg1
Stddev
     111.109474 stddev1
       0.300395 stddev2
Counters:
              2 counter1
             -1 counter2
              0 counter3
```

## Full report output

The full report has more formatting and layout

```text
---- Stats:

                 Min             Max statistic
     --------------- --------------- ------------------------------------------------------------------
                   0               7 minmax1
            0.019647        0.825751 minmax2
     >>> end of min/max

             Average statistic
     --------------- ------------------------------------------------------------------
            4.495221 avg1
     >>> end of Averages

              StdDev statistic
     --------------- ------------------------------------------------------------------
          111.109474 stddev1
            0.300395 stddev2
     >>> end of StdDev

               Total statistic
     --------------- ------------------------------------------------------------------
                   2 counter1
                  -1 counter2
                   0 counter3
     >>> end of counters
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "on-the-fly-stats",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "\"J. Arrizza\" <cppgent0@gmail.com>",
    "keywords": "statistics, utility",
    "author": null,
    "author_email": "\"J. Arrizza\" <cppgent0@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fb/2e/b5887810da5e7abb09eabcd9250499efe26cff210e8141116f144a5a6266/on_the_fly_stats-1.1.0.tar.gz",
    "platform": null,
    "description": "* website: <https://arrizza.com/python-on-the-fly-stats>\n* installation: see <https://arrizza.com/setup-common>\n\n## Summary\n\nThis Python module contains various statistic functions (e.g. standard deviation) that can\nbe updated on the fly i.e. the entire dataset is not needed up front.\n\n* See [Quick Start](https://arrizza.com/user-guide-quick-start) for information on using scripts.\n* See [xplat-utils submodule](https://arrizza.com/xplat-utils) for information on the submodule.\n\n## Sample code\n\nsee sample.py for a full example\n\n```python\nfrom on_the_fly_stats import OTFStats\n\nstats = OTFStats()\n\n# create an instance of the std deviation\nstats.create_stddev('some_tag')\n# add some values to it\nstats.update_stddev('some_tag', 1)\nstats.update_stddev('some_tag', 2)\nstats.update_stddev('some_tag', 3)\n\n# have other instances of it\nstats.update_stddev('other_tag', 0.1)\nstats.update_stddev('other_tag', 0.2)\nstats.update_stddev('other_tag', 0.3)\n\n# show the current data for a specific instance\nprint(stats.stddev['some_tag'].stddev)\nprint(stats.stddev['some_tag'].variance)\nprint(stats.stddev['some_tag'].mean)\nprint(stats.stddev['some_tag'].num_elements)\n\n# show the current data for a specific instance\nprint(stats.stddev['other_tag'].stddev)\n\n# some a summary report\nstats.set_report_writer(print)\nstats.report_minimal()\n# skip the headers for even less data\nstats.report_minimal(headers=False)\n```\n\n## Min/Max\n\nHolds the minimum and maximum of the values provided so far\n\n```python\nimport random\n\nfrom on_the_fly_stats import OTFStats\n\nstats = OTFStats()\n\nstats.create_min_max('minmax1')\nfor _ in range(10):\n    stats.update_min_max('minmax1', random.randint(0, 10))\n\nprint(stats.min_max['minmax1'].minimum)\nprint(stats.min_max['minmax1'].maximum)\nprint(stats.min_max['minmax1'].num_elements)\n```\n\n## Average\n\nHolds the average of the values provided so far\n\n```python\nimport random\n\nfrom on_the_fly_stats import OTFStats\n\nstats = OTFStats()\nstats.create_average('avg1')\nstats.update_average('avg1', random.uniform(0, 10))\nstats.update_average('avg1', random.uniform(0, 10))\n\nprint(stats.average['avg1'].average)\nprint(stats.average['avg1'].anum_elementss)\n```\n\n## Standard Deviation\n\nHolds the standard deviation, mean and variance of the values provided so far\n\n```python\nimport random\n\nfrom on_the_fly_stats import OTFStats\n\nstats = OTFStats()\nstats.create_stddev('sd1')\nstats.update_stddev('sd1', random.random())\nstats.update_stddev('sd1', random.random())\nstats.update_stddev('sd1', random.random())\n\nprint(stats.stddev['sd1'].stddev)\nprint(stats.stddev['sd1'].mean)\nprint(stats.stddev['sd1'].variance)\nprint(stats.stddev['sd1'].num_elementss)\n```\n\n### Counters\n\nHolds counters of the values provided so far\n\n```python\nfrom on_the_fly_stats import OTFStats\n\nstats = OTFStats()\n\n# automatically create a counter\nstats.inc_counter('counter1')\nstats.inc_counter('counter1')  # should be 2\nstats.dec_counter('counter2')  # should be -1\nstats.inc_counter('counter3')\nstats.dec_counter('counter3')  # should be 0\n\nprint(stats.counters['counter1'].count)\nprint(stats.counters['counter2'].count)\nprint(stats.counters['counter3'].count)\n```\n\n### Reports\n\nThere are two builtin reports:\n\n* a minimal report\n* a full report\n\nTo use the builtin reports a function that writes a single line must be provided.\nThe simplest is to use print().\n\n```python\nstats.set_report_writer(print)\nstats.report_minimal()\nstats.report()\n```\n\n## Minimal report output\n\nThe minimal report shows each stat kept and minimal data with minimal formatting\n\n```text\nMin/Max:\n              0               7 minmax1\n       0.019647        0.825751 minmax2\nAverage:\n            4.495221 avg1\nStddev\n     111.109474 stddev1\n       0.300395 stddev2\nCounters:\n              2 counter1\n             -1 counter2\n              0 counter3\n```\n\n## Full report output\n\nThe full report has more formatting and layout\n\n```text\n---- Stats:\n\n                 Min             Max statistic\n     --------------- --------------- ------------------------------------------------------------------\n                   0               7 minmax1\n            0.019647        0.825751 minmax2\n     >>> end of min/max\n\n             Average statistic\n     --------------- ------------------------------------------------------------------\n            4.495221 avg1\n     >>> end of Averages\n\n              StdDev statistic\n     --------------- ------------------------------------------------------------------\n          111.109474 stddev1\n            0.300395 stddev2\n     >>> end of StdDev\n\n               Total statistic\n     --------------- ------------------------------------------------------------------\n                   2 counter1\n                  -1 counter2\n                   0 counter3\n     >>> end of counters\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "On the fly statistics including standard deviation, average, min/max and counters",
    "version": "1.1.0",
    "project_urls": {
        "Download": "https://bitbucket.org/arrizza-public/on-the-fly-stats/get/master.zip",
        "Source": "https://bitbucket.org/arrizza-public/on-the-fly-stats/src/master",
        "Website": "https://arrizza.com/python-on-the-fly-stats"
    },
    "split_keywords": [
        "statistics",
        " utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb2eb5887810da5e7abb09eabcd9250499efe26cff210e8141116f144a5a6266",
                "md5": "d07b7c78ec08a215a81458428a5580e2",
                "sha256": "5562b9044dc9915accb37a4a4026e83430f931c18f88eefc9c0b2578b5dcadab"
            },
            "downloads": -1,
            "filename": "on_the_fly_stats-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d07b7c78ec08a215a81458428a5580e2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8479,
            "upload_time": "2024-12-11T23:02:35",
            "upload_time_iso_8601": "2024-12-11T23:02:35.721631Z",
            "url": "https://files.pythonhosted.org/packages/fb/2e/b5887810da5e7abb09eabcd9250499efe26cff210e8141116f144a5a6266/on_the_fly_stats-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-11 23:02:35",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "codeberg": false,
    "bitbucket_user": "arrizza-public",
    "bitbucket_project": "on-the-fly-stats",
    "lcname": "on-the-fly-stats"
}
        
Elapsed time: 0.39911s