Skip to content

Commit

Permalink
Merge pull request #6 from wd60622/poetry
Browse files Browse the repository at this point in the history
Overhaul
  • Loading branch information
wd60622 authored Jul 24, 2023
2 parents 7767807 + ca4c179 commit 12875be
Show file tree
Hide file tree
Showing 45 changed files with 2,878 additions and 598 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: docs
on:
push:
branches:
- master
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.9
- run: pip install mkdocs mkdocs-material mkdocs-markdownextradata-plugin mkdocs-git-revision-date-localized-plugin "mkdocstrings[python]"
- run: mkdocs gh-deploy --force
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
format:
python -m black divvy tests setup.py
poetry run python -m black lyft_bikes tests

clean:
find divvy tests | grep -E "(/__pycache__$\|\.pyc$\|\.pyo$\)" | xargs rm -rf
find lyft_bikes tests | grep -E "(/__pycache__$\|\.pyc$\|\.pyo$\)" | xargs rm -rf

test:
python -m pytest tests
poetry run python -m pytest tests

coverage:
python -m pytest --cov-report html --cov=divvy tests/ && open htmlcov/index.html
cov:
poetry run python -m pytest --cov-report html --cov=lyft_bikes tests/ && open htmlcov/index.html

export:
conda env export > environment.yaml
html:
poetry run mkdocs serve
102 changes: 16 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,35 @@
# Divvy Rideshare Data
# Lyft Bike Share Data

## Overview
Python client for Lyft bike share data.

Access and work with Chicago rideshare data from Python.

All the information is derived from the official divvy bikes website: [https://divvybikes.com/](https://divvybikes.com/)

Where the data sources were linked to: [https://ride.divvybikes.com/system-data](https://ride.divvybikes.com/system-data)

which point to:

- Historical: [https://divvy-tripdata.s3.amazonaws.com/index.html](https://divvy-tripdata.s3.amazonaws.com/index.html)
- Live and stations: [https://gbfs.divvybikes.com/gbfs/gbfs.json](https://gbfs.divvybikes.com/gbfs/gbfs.json)
## Features

- Support for [cities](https://www.lyft.com/bikes#cities) with Lyft bike share
- [Historical trips](https://wd60622.github.io/lyft-bikes/examples/historical-trips/)
- Live station and bike / scooter availability
- [Applying pricing to trips](https://wd60622.github.io/lyft-bikes/examples/new-pricing/)
- Unlock Fees
- Minute Rates

## Installation

Install from `pip`

```shell
$ pip install python-divvy
```

## Usage

### Reading Data

Reading from the various data sources can be done with the following functions.

```python
import divvy

# Historical trips between a given date range
df_trips = divvy.read_historical_trips(
start_date="2021-01-01",
end_date="2021-02-01"
)
# The trips from July 15th 2022 until latest
df_trips = divvy.read_historical_trips(start_date="2022-07-15")

# Available ebikes and scooters
df_available = divvy.read_available()

# Station information and bikes and scooters available there
df_stations = divvy.read_stations()
```

With the install of [`geopandas`](https://geopandas.org/en/stable/), the pre-May 2022 pricing boundary for ebikes can be accessed with the `read_fee_boundary` function.

```python
# Single row geopandas.GeoDataFrame
gdf_fees = divvy.read_fee_boundary()
$ pip install lyft-bikes
```

### Trip Pricing
## Documentation

This package allows provides access to the latest pricing for the different bikes as defined [here](https://divvybikes.com/pricing). These prices can be apply to `pandas.Series` objects as follows:

```python
df_trips = pd.DataFrame({
"duration_in_mins": [10, 10, 10, 10],
"member": [True, True, False, False],
"electric_bike": [True, False, True, False],
})

df_trips["price"] = divvy.apply_pricing(
duration=df_trips["duration_in_mins"],
member=df_trips["member"],
electric_bike=df_trips["electric_bike"],
)
```

Classic bike prices for casual users are ambiguous due to the daily rate or single trip rate. However, they can be accessed in the `divvy.pricing` module as so.

```python
casual_non_electric_duration = [10, 20, 30]

divvy.pricing.single_ride_rate(casual_non_electric_duration)
divvy.pricing.visitor_pass_rate(casual_non_electric_duration)
```

New pricing can easily be defined from the `divvy.pricing` module as well. For instance, a reduced ebike rate can be created for casual users.

```python
reduced_ebike_rate = (
divvy.pricing.UnlockRate(amount=100)
+ divvy.pricing.MinuteRate(amount=25, start=0)
)

casual_electric_duration = [10, 20, 30]

reduced_ebike_rate(casual_electric_duration)
```
The documentation is hosted on [GitHub Pages](https://wd60622.github.io/lyft-bikes/).

## Development

The development environment was created with `conda` and can be recreated and activated that way. Here are some helpful commands for [conda](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file).

If there is a change to dependencies in the project, the `setup.py` will likely have to be changed as well.
The development environment was created with [`poetry`](https://python-poetry.org/docs/). The `pyproject.toml` file is the main configuration file for the project.

The `setup.py` is important for deployment to PyPI. The project might move to another package manager in the future. In order to ease deployment.
```bash
poetry install .
```

## Contributing

Expand Down
79 changes: 0 additions & 79 deletions divvy/__init__.py

This file was deleted.

92 changes: 0 additions & 92 deletions divvy/historical/historical.py

This file was deleted.

18 changes: 0 additions & 18 deletions divvy/live.py

This file was deleted.

Loading

0 comments on commit 12875be

Please sign in to comment.