Skip to content

Commit

Permalink
Frame initial CLI functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sco1 committed Jul 20, 2023
1 parent 56b9f43 commit 46a4704
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 178 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ extend-exclude=
.venv,
per-file-ignores =
tests/test_*.py:D103 E501,
extend-immutable-calls =
# Typer CLI
typer.Option, typer.Argument,
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ htmlcov
# mypy
.mypy_cache/

sample_data/
sample_data/
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
Expand Down
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,86 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)

Python helpers for the [EDC Dropmate](https://earthlydynamics.com/dropmate/).

## Installation
Install by cloning this repository and installing into a virtual environment:

```bash
$ pip install .
```

You can confirm proper installation via the `dropmate` CLI:
<!-- [[[cog
import cog
from subprocess import PIPE, run
out = run(["dropmate", "--help"], stdout=PIPE, encoding="ascii")
cog.out(
f"```bash\n$ dropmate --help\n{out.stdout.rstrip()}\n```"
)
]]] -->
```bash
$ dropmate --help
Usage: dropmate [OPTIONS] COMMAND [ARGS]...

Options:
--help Show this message and exit.

Commands:
audit
audit-bulk
```
<!-- [[[end]]] -->

## Usage
### Environment Variables
The following environment variables are provided to help customize pipeline behaviors.

| Variable Name | Description | Default |
|--------------------|-----------------------------------|--------------|
| `PROMPT_START_DIR` | Start path for UI file/dir prompt | `'.'` |

### `dropmate audit`
Process a consolidated Dropmate log CSV.
#### Input Parameters
| Parameter | Description | Type | Default |
|------------------|------------------------------------|--------------|------------|
| `--log-filepath` | Path to Dropmate log CSV to parse. | `Path\|None` | GUI Prompt |
| `--min-alt-loss` | Threshold altitude delta. | `int` | `200` |
| `--min-firmware` | Threshold firmware version. | `int\|float` | `5` |

### `dropmate audit-bulk`
Batch process a directory of consolidated Dropmate log CSVs.
#### Input Parameters
| Parameter | Description | Type | Default |
|------------------|-----------------------------------------------|--------------|------------|
| `--log-dir` | Path to Dropmate log directory to parse. | `Path\|None` | GUI Prompt |
| `--log-pattern` | Dropmate log file glob pattern.<sup>1,2</sup> | `str` | `"*.csv"` |
| `--min-alt-loss` | Threshold altitude delta. | `int` | `200` |
| `--min-firmware` | Threshold firmware version. | `int\|float` | `5` |

1. Case sensitivity is deferred to the host OS
2. Recursive globbing requires manual specification (e.g. `**/*.csv`)

## Contributing
**NOTE:** Due to deployment environment restrictions preventing the use of compiled libraries (e.g. Polars, Pandas/Numpy), tooling is intentionally limited to pure-Python implementations.
### Development Environment
This project uses [Poetry](https://python-poetry.org/) to manage dependencies. With your fork cloned to your local machine, you can install the project and its dependencies to create a development environment using:

```bash
$ poetry install
```

A [pre-commit](https://pre-commit.com) configuration is also provided to create a pre-commit hook so linting errors aren't committed:

```bash
$ pre-commit install
```

### Testing & Coverage
A [pytest](https://docs.pytest.org/en/latest/) suite is provided, with coverage reporting from [pytest-cov](https://github.com/pytest-dev/pytest-cov). A [tox](https://github.com/tox-dev/tox/) configuration is provided to test across all supported versions of Python. Testing will be skipped for Python versions that cannot be found.

```bash
$ tox
```

Details on missing coverage, including in the test suite, is provided in the report to allow the user to generate additional tests for full coverage.
54 changes: 54 additions & 0 deletions dropmate_py/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
from pathlib import Path

import typer
from dotenv import load_dotenv
from sco1_misc.prompts import prompt_for_dir, prompt_for_file

MIN_ALT_LOSS = 200
MIN_FIRMWARE = 5

load_dotenv()
start_dir = os.environ.get("PROMPT_START_DIR", ".")
PROMPT_START_DIR = Path(start_dir)

dropmate_cli = typer.Typer(add_completion=False)


@dropmate_cli.command()
def audit(
log_filepath: Path = typer.Option(exists=True, file_okay=True, dir_okay=False),
min_alt_loss: int = typer.Option(default=MIN_ALT_LOSS),
min_firmware: float = typer.Option(default=MIN_FIRMWARE),
) -> None:
if log_filepath is None:
log_filepath = prompt_for_file(
title="Select Flight Log",
start_dir=PROMPT_START_DIR,
filetypes=[
("FlySight Flight Log", "*.csv"),
("Gaggle Flight Log", "*.gpx"),
("All Files", "*.*"),
],
)

raise NotImplementedError


@dropmate_cli.command()
def audit_bulk(
log_dir: Path = typer.Option(exists=True, file_okay=False, dir_okay=True),
log_pattern: str = typer.Option("*.csv"),
min_alt_loss: int = typer.Option(default=MIN_ALT_LOSS),
min_firmware: float = typer.Option(default=MIN_FIRMWARE),
) -> None:
if log_dir is None:
log_dir = prompt_for_dir(
title="Select directory for batch processing", start_dir=PROMPT_START_DIR
)

raise NotImplementedError


if __name__ == "__main__":
dropmate_cli()
1 change: 1 addition & 0 deletions dropmate_py/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pathlib import Path
Loading

0 comments on commit 46a4704

Please sign in to comment.