# nercardata

A Python package for querying and processing sensor data from the Northeastern Electric Racing PostgreSQL database.

## Installation

```bash
pip install nercardata
```

## Setup

Create a `.env` file in your project root with the database connection string:

```env
DATABASE_URL=your_database_url_here
```

Ask the team for the connection string if you don't have it.

## Usage

```python
from nercardata import DataLoader

# Fetch cleaned sensor data — returns a DataFrame, unit, and sensor name
df, unit, name = DataLoader.query_builder(
    sensor='DTI/Power/AC_Current',
    start_time='2025-06-08 15:17:09.00',
    end_time='2025-06-08 15:17:23.00'
)
```

### Available Methods

**`DataLoader.query_builder(sensor, start_time, end_time)`**

The main method. Fetches sensor data, cleans it, and returns a tuple of `(DataFrame, unit, sensor_name)`. The DataFrame contains `time` (seconds from start) and `values` (float) columns.

**`DataLoader.get_data(sensor, table, start_time, end_time)`**

Raw database query. Use `table='data'` for time-series readings or `table='data_type'` for sensor metadata.

**`DataLoader.data_cleaner(dataframe, dropping, time, format_list_to_float)`**

Cleans a DataFrame by dropping columns, normalizing timestamps to elapsed seconds, and converting list-wrapped values to floats.

**`DataLoader.time_calls(func)`**

A decorator that prints execution time of any function.

## Dependencies

- `psycopg2` — PostgreSQL adapter
- `pandas` — data manipulation
- `python-dotenv` — environment variable loading

## License

MIT
