Flight API - CompteCO2/Carbon-Weight GitHub Wiki
Class: default
Type aliases
Types
Ƭ Types: Object
Type declaration
| Name | Type | 
|---|---|
| AirportI | AirportI | 
| AirportsI | AirportsI | 
| DataE | DataE | 
| FlightI | FlightI | 
| HaulE | HaulE | 
| SeatE | SeatE | 
Functions
getAirports
▸ Const getAirports(): AirportsI
Return the available airports
Returns
AirportsI
constant data loaded
getDistance
▸ Const getDistance(fromLat, fromLon, toLat, toLon): number
Compute distance in km from longitude and lattitude using the haversine formula.
description the law of haversine in brief:
Given a unit sphere, a "triangle" on the surface of the sphere is defined by the great circles
connecting three points u, v, and w on the sphere.
If the lengths of these three sides are a (from u to v), b (from u to w), and c (from v to w),
and the angle of the corner opposite c is C, then the law of haversines states:
hav(c) = hav(a - b) + sin(a) * sin(b) * hav(C)
Since this is a unit sphere, the lengths a, b, and c are simply equal to the angles (in radians) subtended by those sides from the center of the sphere (for a non-unit sphere, each of these arc lengths is equal to its central angle multiplied by the radius R of the sphere).
Parameters
| Name | Type | Description | 
|---|---|---|
| fromLat | number | Lattitude of the point of departure | 
| fromLon | number | Longitude of the point of departure | 
| toLat | number | Lattitude of the point of arrival | 
| toLon | number | Longitude of the point of arrival | 
Returns
number
the distance in km
Table of contents
Constructors
Properties
Methods
- getData
- getDataset
- getEmissionAvg
- getEmissionAvgByPassenger
- getEmissionEstimated
- getHaulFactor
- build
Constructors
constructor
• new default(dataSet, data)
warning
Should not be used : please use the static build method using dataset enum type DataE
Parameters
| Name | Type | 
|---|---|
| dataSet | ADEME_2022 | 
| data | DataI | 
Properties
avgEmission
• Private avgEmission: undefined | number
avgEmissionByPassenger
• Private avgEmissionByPassenger: undefined | number
data
• Private data: DataI
dataSet
• Private dataSet: ADEME_2022
Methods
getData
▸ getData(): DataI
Return the current data constants loaded
Returns
DataI
constant data loaded
getDataset
▸ getDataset(): ADEME_2022
Return the inner data set name
Returns
ADEME_2022
constant data loaded
getEmissionAvg
▸ getEmissionAvg(): number
Return the average co2 estimation in peq.kgCO2e/year (per person).
description
This constant is the ratio totalEmission/#people
Returns
number
The average co2 emission in peq.kgCO2e/year (per person).
getEmissionAvgByPassenger
▸ getEmissionAvgByPassenger(): number
Return the average co2 estimation in peq.kgCO2e/year (per passenger).
description
This constant is the ratio totalEmission/#passenger
Returns
number
The average co2 emission in peq.kgCO2e/year (per passenger).
getEmissionEstimated
▸ getEmissionEstimated(travel, nbFlights): number
Compute the co2 emissions from air travels in kgCO2e/year
description
Firstly the distances are calculated between the airports selected, then we
use the factor emission expressed in kgCO2e/peq.km (peq = person equivalent) to
get our first estimation per equivalent person:
- Emission = Distance * Factor
- [kgCO2e/year] = [km/year] * [kgCO2e/km]
Finally, we add a factor depending on the class of the seat taken (economy class, business class, first class).
Parameters
| Name | Type | Description | 
|---|---|---|
| travel | FlightI | - | 
| nbFlights | number | the number of flight made a year. | 
Returns
number
the estimated flight emissions for the passengers in kgCO2e -1 in case of error (e.g. missing IATA airport)
getHaulFactor
▸ getHaulFactor(distance): number
Retrieve the emission factor from the flight distance
Parameters
| Name | Type | Description | 
|---|---|---|
| distance | number | distance of the flight in km | 
Returns
number
emission factor in kgCO2e/peq.km
build
▸ Static build(dataset)
Create a calculator instance from dataset
Parameters
| Name | Type | 
|---|---|
| dataset | ADEME_2022 | 
Returns
new House calculator - Throw error if dataset not loaded.