Emissions Avoided Module

Emissions Avoided Module

Contents

Introduction

The Emissions Avoided Module (EAM) is an online service that enables transit agencies to calculate the CO2 emissions for any given transit trip, in comparison to the same trip travelled by car on an SUV. The emission results generated by the EAM are provided in such a way as to be easily integrated into and displayed on trip planning sites. The module is a tool for enhancing local public awareness about how taking public transportation can reduce greenhouse gases while helping to curtail climate change. The EAM is an XML-RPC web service, which means that it can be utilized by any programming language that implements the protocol, with an Internet-connected PC or server.

Connecting to the Service

You can connect to the EAM using the following information:
Host:travelmatters.org
Path:/cgi-bin/webservices.cgi
Method:eam.getCo2

Method Arguments

The eam.getCo2 method takes two arguments:
  • int ntdid: Your agency's ID from the National Transit Database. (See "Determining your NTD ID".)
  • struct trips: The struct contains the following:
    • str name: The key to the struct which should be either 'rail' or 'bus' depending on the mode of travel.
    • int miles: The amount of miles traveled by this mode of travel.

Method Results

The return value of eam.getCo2 is a struct containing the following:

  • int transit_co2: Pounds of CO2 generated by the entire trip.
  • int car_co2: Pounds of CO2 generated by an equivalent length trip in the average passenger car.
  • int suv_co2: Pounds of CO2 generated by an equivilent length trip in the average SUV.

An Example Using PHP

<?php
// Include the PEAR XML_RPC library
require_once('XML/RPC.php');

// NTD ID, and the bus and rail miles should all be integers.
$my_ntdid = 523;
$bus_miles = 90;
$rail_miles = 2;

// Create an XML-RPC value for NTD ID
$Ntdid = new XML_RPC_Value($my_ntdid, 'int');

// Create an XML-RPC value for the trips.  This should be a struct
// containing XML-RPC values for the bus mileage, rail mileage or both.
$Trips = new XML_RPC_Value(
    array(
        
'bus' => new XML_RPC_Value($bus_miles, 'int'),
        
'rail' => new XML_RPC_Value($rail_miles, 'int')
    ),
    
'struct'
);

// The parameters should be an array
$parameters = array($Ntdid, $Trips);

// Create an XML-RPC message to the eam.getCo2 method sending the
// $parameters array as parameters
$Message = new XML_RPC_Message('eam.getCo2', $parameters);

// Create an XML_RPC client object using /cgi-bin/webservices.cgi as
// our path and travelmatters.org as the host
$Client = new XML_RPC_Client('/cgi-bin/webservices.cgi',
                             
'travelmatters.org', 80);

// Send our message and return a response object
$Response = $Client->send($Message);

// Test whether whether there was an error
if (!$Response->faultCode()) {
  
//
  // If there was no error:
  //
  
  // Extract the result as an XML_RPC Value object
  
$Value = $Response->value();

  
// Extract a XML_RPC Value Objects from our result struct
  
$Transit=$Value->structmem('transit_co2');
  
$Car=$Value->structmem('car_co2');
  
$Suv=$Value->structmem('suv_co2');

  
// Get the values from our Value Objects
  
$transit_co2 = $Transit->scalarval();
  
$car_co2 = $Car->scalarval();
  
$suv_co2 = $Suv->scalarval();

  
// Print the results
  
print '<h2>Results</h2>';
  print
'This trip generated ' . $transit_co2 . ' pounds of CO2.<br />';
  print
'An equivalent trip by car would generate ' . $car_co2 .
        
' pounds of CO2.<br />';
  print
'An equivalent trip by SUV would generate ' . $suv_co2 .
        
' pounds of CO2.';

} else {
  
//
  // If there was an error:
  //
  // Print some information to determine what the error was
  
print '<h2>Error</h2>';
  print
'Code: ' . $Response->faultCode() . '<br />';
  print
'Reason: ' . $Response->faultString();
}
?>

An Example Using Python

#!/usr/bin/python

# Import the xmlrpclib
import xmlrpclib

# ntdid, bus_mileage and rail_mileage should all be integers
ntdid = 523
bus_mileage = 90
rail_mileage = 2

# Trips should be of type dictionary, the Python equivalent
# of the XML-RPC struct datatype
trips = {"bus": bus_mileage, "rail": rail_mileage}
   
# This is the correct server_url
server_url = 'http://dev.travelmatters.org/cgi-bin/webservices.cgi';

# Create a server object
server = xmlrpclib.Server(server_url);
   
# Test whether there was an error
try:
  # If there was no error, send the request with the
  # server.eam.getCo2 method
  result = server.eam.getCo2(ntdid, trips)

  # Print our results
  print "Content-Type: text/html\n\n"
  print "<h2>Results</h2>"
  print "This trip generated ", result['transit_co2'], " pounds of CO2.<br />"
  print "An equivalent trip by car would generate ", result['car_co2'], " pounds of CO2.<br />"
  print "An equivalent trip by SUV would generate ", result['suv_co2'], " pounds of CO2."
except xmlrpclib.Fault, error:
  # If there was an error, get information about it:

  print "Content-Type: text/html\n\n"
  print "<h2>Error:</h2>"
  print "Code: ", error.faultCode, "<br />"
  print "Reason: ", error.faultString

Determining Your NTD ID

You can look up your NTD ID at the NTD ID Finder.