Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More user-friendly, high-level API #190

Open
redfrexx opened this issue May 6, 2024 · 1 comment
Open

More user-friendly, high-level API #190

redfrexx opened this issue May 6, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request prio1 Highest Priority: Do now

Comments

@redfrexx
Copy link
Member

redfrexx commented May 6, 2024

Summary

Implement a more high-level API which is easier to use for python programmers by

1. Suggest available parameters for specific mobility types (e.g. car, train) via tab completion

from co2calculator import Trip, BusCarFuel

# CO2 emissions for a trip by car
trip_by_car = Trip(distance=300).by_car(fuel_type=BusCarFuel.DIESEL)

# Same trip with different vehicles
trip = Trip(start='Heidelberg', end='Freiburg')
trip_train = trip.by_train()
trip_plane = trip.by_plane()
trip_bus = trip.by_bus()

# Result could be an object which contains the following information
# Emissions 
trip_train.co2e
# Distance
trip_train.distance
# Meta information (e.g. emission factor and source)
trip_train.emission_factor
trip_train.emission_factor.source

2. List valid parameter combinations based on user specified parameters

This could look like this, but it would then require adding a calculate() method to the example above to enable multiple functions to be called for a specific transport mode.

from co2calculator import Trip, BusCarFuel, Size

# Calculate co2 emission using 'calculate()'
Trip(distance=300).by_car(fuel_type=BusCarFuel.DIESEL).calculate()

# Get valid parameter options based on user chosen parameters
trip = Trip(start='Heidelberg', end='Freiburg')
# print options as dictionary
trip.by_car(fuel_type=BusCarFuel.DIESEL).get_options()
# Returns {'size': [Size.SMALL, Size.LARGE]}

3. Analog for emissions from energy consumption

from co2calculator import Energy, HeatingFuel, Unit

# Calculate co2 emissions 
energy_heating = Energy().from_heating(fuel_type=HeatingFuel.OIL, consumption=100, unit=Unit.LITER).calculate()
energy_electricity = Energy().from_electricity(consumption=100).calculate()

# Print result
energy_heating.co2e
energy_heating.consumption
energy_heating.emission_factor
energy_heating.emission_factor.source

What do you think?

Reference Issues

No response

Unresolved questions

No response

@redfrexx redfrexx added the enhancement New feature or request label May 6, 2024
@redfrexx
Copy link
Member Author

redfrexx commented May 6, 2024

related to issue #137

@redfrexx redfrexx changed the title REQUEST: More user-friendly, high-level API More user-friendly, high-level API May 6, 2024
@redfrexx redfrexx added the prio1 Highest Priority: Do now label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prio1 Highest Priority: Do now
Projects
None yet
Development

No branches or pull requests

2 participants