# Statistics Extensions for Ignition

**URL:** <https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100>\
**Category:** Ignition\
**Created:** [February 22, 2018, 6:45pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100 "2018-02-22T18:45:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 22, 2018, 6:45pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/1 "2018-02-22T18:45:43Z")

</div>

After discussions elsewhere with @Brian on the forum, I’ve ported the statsutils library from [http://boltons.readthedocs.io](http://boltons.readthedocs.io)

some changes from the originaL

- Removed the **format\_histogram** functions, as they were using unsupported string formatting. Maybe when Ignitions’s Jython gets upgraded, I can look at it again.

- Renamed remaining histogram function to **histogram**. Brevity is good.

- Added ‘raw’ flag to histogram function to give a one-dimensional list with repeat histogram values, instead of a list of (value, count) tuples.

- added mode and all\_modes functions. Read the doc for more info.

[statsutils\_2018-02-22\_1158.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/be22ace4729374002441cc37293397a3b93e0c00.proj) (11.8 KB)  
[statsutils for Ignition.pdf](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a2b11b6c94654f67aec43fb4b306a16424800176.pdf) (168.3 KB)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 22, 2018, 6:57pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/2 "2018-02-22T18:57:44Z")

</div>

@Brian, You had mentioned about using mode on binned values.

1. Make a Stats instance of the list

2. grab the histogram with whatever bins you want to use and setting the ‘raw’ flag. This list will be what you run against mode.

3. make another Stats instance with the new list.

4. get the mode

```auto
from shared.statsutils import Stats

listIn = [1.234, 5.678, 9.012, 3.456, 7.890, 2.345, 4.567]

statsList1 = Stats(listIn)

print 'histogram:', statsList1.histogram(bins = 6, bin_digits = 2)

statsList2 = Stats(statsList1.histogram(bins = 6, bin_digits = 2, raw = 1))

print 'mode:', statsList2.mode

```

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c86f025b9503eb5e15eaca401eca01f8f28a1e89.png)

---

<div class="post-metadata">

**Author:** ![Brian](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@Brian](https://forum.inductiveautomation.com/u/Brian)\
**Post date:** [February 22, 2018, 7:04pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/3 "2018-02-22T19:04:24Z")

</div>

Cool!! I’ll import and play around with this the next time I get a chance!

Thanks!!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 22, 2018, 7:18pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/4 "2018-02-22T19:18:26Z")

</div>

> [@JordanCClark](#):
>
> from shared.statsutils import Stats

Don't do this. After this executes on this module's load, if shared.statsutils is updated, this module won't get the changes. You should always use spelled-out names for shared.\* and project.\* functions and objects. Don't import them.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 22, 2018, 7:53pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/5 "2018-02-22T19:53:05Z")

</div>

Thanks, Phil. It was for demonstration purposes only, and to make the example more reader-friendly.

You hear that kids? Don’t do it!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 22, 2018, 7:55pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/6 "2018-02-22T19:55:32Z")

</div>

> [@JordanCClark](#):
>
> You hear that kids? Don't do it!

And get off my lawn!  
{ Goes with my grey beard... }

---

<div class="post-metadata">

**Author:** ![Brian](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@Brian](https://forum.inductiveautomation.com/u/Brian)\
**Post date:** [March 9, 2018, 8:22pm UTC](https://forum.inductiveautomation.com/t/statistics-extensions-for-ignition/17100/7 "2018-03-09T20:22:06Z")

</div>

I finally had a chance to play around with this code. I think I like the math.mode function that I came up with best for calculating modes. Or at least, matches what excel will give me for a mode on values rounded to 3 digits.

With the statsutils version, I have to try to calculate the number of bins ahead of time to get a fine-grained enough binning. With the other method, the bins are auto-created as needed, so to speak.

I’ll definitely be using the statsutils for other statistical functions though! Very useful stuff!

Thanks again!
