semvec/pypi-packages huggingface dataset:
trainer-py 0.2.0
Lightweight context-based library for benchmarking
License: MIT
Keywords: metrics,benchmark

# Trainer ⏱

[![PyPI](https://img.shields.io/pypi/v/trainer-py?color=green)](https://pypi.org/project/trainer-py)

Lightweight benchmarking package with zero dependencies

## Installation

```sh
pip install trainer-py
```

## Usage

```Python
from trainer import Trainer

t = Trainer().round(2)

with t('metric1'):
    time.sleep(0.5)

with t('metric2'):
    time.sleep(0.3)

m = t.add_total('total').metrics
print(m)
```

**output:**

```
{
    'metric1': {'start': 1656844808.09, 'end': 1656844808.59, 'interval': 0.5},
    'metric2': {'start': 1656844808.59, 'end': 1656844808.89, 'interval': 0.3},
    'total': {'start': 1656844808.09, 'end': 1656844808.89, 'interval': 0.8}
}
```

> for more, see
[examples](https://github.com/MichalMoravik/trainer/blob/4bace6cdcdead86ab7d5574c5fe0e73159b6e2e6/examples/example.py)

## Features

### Contexts

- using Python [contexts](https://docs.python.org/3/library/contextlib.html),
you can indent specific parts of the code you want to benchmark
- each measured code part produces a 'metric' dictionary with name (key),
start (epoch), end (epoch), interval (epoch)
- all metrics can be retrieved at any point by calling `trainer.metrics`

### Total Execution Time

- you can add the total execution time by executing `trainer.add_total()`
at the end
- by default, the total time considers the first metric's start time as its
start, but it is possible to prematurely start measurement by calling
`trainer.start_measuring()` instead

### Rounding

- all epoch timestamps can be rounded to any number of decimals using
`trainer.round(<int>)`
- all epoch timestamps can be rounded to full seconds (making them
integers instead of floats) by executing `trainer.round()` or `trainer.round(0)`

### Turning off Trainer

- to turn off trainer, the DummyTrainer class is provided. This class can be
switched on, for example, based on a value of an environment variable

```Python
    trainer = Trainer() if ENV_VAR else DummyTrainer()
```

- calling `.metrics` at the end will always return in an empty dictionary which
is falsy in Python. Your following code that uses the `metrics` dictionary can
first do a check for this falsy value

</br>

[go to examples](https://github.com/MichalMoravik/trainer/blob/4bace6cdcdead86ab7d5574c5fe0e73159b6e2e6/examples/example.py)
droneblocks-python-utils 0.2.2
DroneBlocks Python Utilities
License: MIT

# DroneBlocks Python Utils

DroneBlocks Tello drone Python utilities used in many of the advanced Tello programming with Python courses.

Some of the features:

* DroneBlocksTello class that added Robomaster TT commands to the DJITelloPy Tello class
* Aruco marker utilities
* Video image effect utilities
* tello_script_runner to create an easy to use Tello script execution environment


### Install using pip
```shell
pip install droneblocks-python-utils
```

## Usage

### Simple Tello Example

```python
from droneblocks.DroneBlocksTello import DroneBlocksTello

tello = DroneBlocksTello()

tello.connect()
tello.takeoff()

tello.move_up(100)
tello.rotate_counter_clockwise(90)
tello.move_forward(100)

tello.land()

```

### Simple Robomaster TT Example
```python
from droneblocks.DroneBlocksTello import DroneBlocksTello
import time

tello = DroneBlocksTello()

tello.connect()
tello.clear_display()
tello.takeoff()
tello.display_heart()
tello.move_up(100)
tello.rotate_counter_clockwise(90)
tello.display_smile()
tello.move_forward(100)
time.sleep(2)
tello.clear_display()
tello.land()

```

### Tello Example

in a terminal type:
```shell
python -m droneblocks.tello_web
```

You can then open a browser and type the following url:

`http://localhost:8080`

and you should see a web page that allows you to interact with the Tello.