Statistics
Source code: stopwatch/statistics.py
Supported Operations
python
len(x) # get the length of the valueslen(x) # get the length of the valuesInitialization
python
def __init__(self, values: Optional[List[float]] = None) -> None:def __init__(self, values: Optional[List[float]] = None) -> None:values: The list of values to be used for the statistics.- Type: Optional[List[float]]
- Default: None
Attributes
All attributes of the Statistics class.
mean
The mean value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.mean) # 0.5from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.mean) # 0.5maximum
The maximum value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.maximum) # 0.9from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.maximum) # 0.9median
The median value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.median) # 0.5from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.median) # 0.5minimum
The minimum value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.minimum) # 0.1from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.minimum) # 0.1total
The total value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.total) # 2.5from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.total) # 2.5variance
The variance value in seconds.
Type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.variance) # 0.09from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.variance) # 0.09Methods
All methods of the Statistics class.
add
python
def add(self, value: float) -> None:def add(self, value: float) -> None:Add a value to the list of values.
Parameters
value: The value to be added.- Type: float
to_dict
python
def to_dict(self) -> Dict[str, float]:def to_dict(self) -> Dict[str, float]:Get a dictionary with all statistics.
Returns
- The dictionary with all statistics.
Return type
Example
python
from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.to_dict())
# {'mean': 0.5, 'maximum': 0.9, 'median': 0.5, 'minimum': 0.1, 'total': 2.5, 'variance': 0.09}from stopwatch import Stopwatch
from random import randint
from time import sleep
with Stopwatch() as sw:
for _ in range(1, 6):
with sw.lap():
sleep(randint(1, 10) / 10)
print(sw.statistics.to_dict())
# {'mean': 0.5, 'maximum': 0.9, 'median': 0.5, 'minimum': 0.1, 'total': 2.5, 'variance': 0.09}