Metadata-Version: 2.4
Name: pydelay
Version: 0.1.2
Summary: Network time-delay simulation with statistical analysis and plotting
Author: Parham Kebria
License: MIT License
        
        Copyright (c) 2026 Parham Kebria
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/parhamkebria/pydelay
Project-URL: Bug Tracker, https://github.com/parhamkebria/pydelay/issues
Keywords: network,delay,simulation,statistics,signal
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Telecommunications Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: System :: Networking
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: matplotlib>=3.7
Requires-Dist: scipy>=1.10
Dynamic: license-file

# pydelay

**pydelay** is a Python package for simulating and analysing network time delays. It supports two statistical delay models, a Gaussian long-distance model and an exponential short-distance model, and produces publication-ready plots of the delay distribution and signal pulse train.

## Installation

```bash
pip install pydelay
```

## Quick Start

### As a library

```python
import pydelay

# Run a long-distance (Gaussian) delay simulation
result = pydelay.delay("l", n_packets=5000, simulation_time=120.0, seed=42)

print(f"Mean delay : {result.mean_delay:.3f} s")
print(f"Std  delay : {result.std_delay:.3f} s")
print(f"Min  delay : {result.min_delay:.3f} s")

# Plot the results
fig, axes = pydelay.plot(result, show=True)

# Save the figure
pydelay.plot(result, save="delay_plot.png")
```

### As a command-line tool

```bash
# Long-distance model, default settings
pydelay l

# Short-distance model, custom packet count and seed
pydelay s --npack 10000 --stime 60 --seed 0

# Skip writing the CSV output file
pydelay l --no-csv
```

## Delay Models

| Flag | Model | Distribution |
|------|-------|-------------|
| `l`  | Long-distance | Gaussian  μ = 1.50 s, σ = 0.50 s |
| `s`  | Short-distance | Exponential  min ≈ 1 ms, mean ≈ 2 ms |

## API Reference

### `pydelay.delay(model, *, n_packets, simulation_time, seed, output_csv)`

Run the delay simulation and return a `SimulationResult`.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `model` | `"l"` or `"s"` | — | Delay model |
| `n_packets` | `int` | `5000` | Number of packets to simulate |
| `simulation_time` | `float` | `120.0` | Time horizon in seconds |
| `seed` | `int \| None` | `None` | Random seed for reproducibility |
| `output_csv` | `str \| Path \| None` | `"delay_data.csv"` | Path to save CSV; `None` to skip |

### `pydelay.plot(result, *, zoom_start, zoom_stop, show, save)`

Plot the pulse train and delay distributions.

Returns `(fig, (ax_signal, ax_dist, ax_dist2))`.

### `SimulationResult`

| Attribute | Description |
|-----------|-------------|
| `.send_time` | Packet send timestamps (ndarray) |
| `.simulated_delay` | Sampled delays (ndarray) |
| `.pulse_time` / `.pulse_values` | Pulse train arrays |
| `.min_delay` | Minimum delay |
| `.mean_delay` | Mean delay |
| `.std_delay` | Standard deviation of delay |
| `.simdelay` | Dict of `{time, signals}` for external use |

## Requirements

- Python ≥ 3.10
- numpy ≥ 1.24
- matplotlib ≥ 3.7
- scipy ≥ 1.10

## License

MIT © [Parham Kebria](https://github.com/parhamkebria)
