Skip to main content

A Python library for calculating delivery distances and pricing using the Haversine formula

Project description

Delivery Optimizer

A Python library for calculating delivery distances and pricing using the Haversine formula.

Features

  • Distance Calculation: Calculate the great-circle distance between two geographical locations using the Haversine formula
  • Pricing Engine: Calculate delivery pricing based on distance and weight
  • Location Management: Simple Location class for managing geographical coordinates
  • Customizable: Configurable pricing parameters

Installation

pip install delivery-optimizer

Quick Start

from delivery_optimizer import Location, DistanceCalculator, PricingEngine

# Create locations
pickup = Location(53.3498, -6.2603, "Dublin, Ireland")
delivery = Location(53.4129, -8.2439, "Galway, Ireland")

# Calculate distance
distance = DistanceCalculator.calculate(pickup, delivery)
print(f"Distance: {distance} km")  # Distance: 208.42 km

# Calculate price
pricing = PricingEngine()
price = pricing.calculate(distance, weight_kg=2.5)
print(f"Price: ${price}")  # Price: $528.55

Usage

Location

The Location class represents a geographical location:

from delivery_optimizer import Location

location = Location(
    latitude=53.3498,
    longitude=-6.2603,
    address="Dublin, Ireland"
)

Distance Calculation

Calculate the distance between two locations:

from delivery_optimizer import Location, DistanceCalculator

location1 = Location(53.3498, -6.2603)
location2 = Location(53.4129, -8.2439)

distance_km = DistanceCalculator.calculate(location1, location2)
print(f"Distance: {distance_km} km")

Pricing

Calculate delivery pricing:

from delivery_optimizer import PricingEngine

# Default pricing
pricing = PricingEngine()
price = pricing.calculate(distance_km=100, weight_kg=2.5)

# Custom pricing
custom_pricing = PricingEngine(
    base_price=10.0,
    price_per_km=3.0,
    price_per_kg=1.5
)
price = custom_pricing.calculate(distance_km=100, weight_kg=2.5)

Pricing Formula

The default pricing formula is:

price = base_price + (distance_km × price_per_km) + (weight_kg × price_per_kg)

Default values:

  • Base price: $5.0
  • Price per km: $2.5
  • Price per kg: $1.0

API Reference

Location

Location(latitude: float, longitude: float, address: str = "")

DistanceCalculator

DistanceCalculator.calculate(location1: Location, location2: Location) -> float

Returns distance in kilometers (rounded to 2 decimal places).

PricingEngine

PricingEngine(base_price: float = None, price_per_km: float = None, price_per_kg: float = None)
pricing.calculate(distance_km: float, weight_kg: float = 1.0) -> float

Returns price rounded to 2 decimal places.

Requirements

  • Python 3.8+

License

MIT License

Author

Abhishek Sharma

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

delivery_optimizer-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

delivery_optimizer-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file delivery_optimizer-1.0.0.tar.gz.

File metadata

  • Download URL: delivery_optimizer-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for delivery_optimizer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 100d995063ab0764afb005c2ac31521630425806f9de9f5b97e3c06943898b74
MD5 0f2a548eeb9cdbd5db31216d47528101
BLAKE2b-256 137589ef8120001c571ac9650f1ec63bc40f4906d431f577e122221439ac9379

See more details on using hashes here.

File details

Details for the file delivery_optimizer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for delivery_optimizer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f234a818d621467d6561426f4fab8a0e9e65741e51c1197982041660a5e8444
MD5 63696ebfdb255cd2585e17cfad8e489e
BLAKE2b-256 0d9d30174f9ade4f40a0d5fcd69255b99625645db6f964ebbf2d101be2530434

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page