<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CARMA Blog &#187; Oscar Merida</title>
	<atom:link href="http://carma.org/blog/author/oscar/feed/" rel="self" type="application/rss+xml" />
	<link>http://carma.org/blog</link>
	<description>What goes around comes around</description>
	<lastBuildDate>Sat, 10 Sep 2011 17:09:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DNA for More API Mashups</title>
		<link>http://carma.org/blog/dna-for-more-api-mashups/</link>
		<comments>http://carma.org/blog/dna-for-more-api-mashups/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 20:16:33 +0000</pubDate>
		<dc:creator>Oscar Merida</dc:creator>
				<category><![CDATA[Blogroll]]></category>
		<category><![CDATA[CARMA Features]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carma.org/blog/dna-for-more-api-mashups/</guid>
		<description><![CDATA[I started writing this post thinking I&#8217;d find some other Environmental/Green-related API&#8217;s to mash up with CARMA&#8217;s data. At the moment, though, I couldn&#8217;t find many data sources that make available a comparable data set as openly as the CARMA API does. It&#8217;s disappointing, as this represents a barrier to creating really interesting applications. The bar [...]]]></description>
			<content:encoded><![CDATA[<p>I started writing this post thinking I&#8217;d find some other Environmental/Green-related API&#8217;s to mash up with CARMA&#8217;s data. At the moment, though, I couldn&#8217;t find many data sources that make available a comparable data set as openly as the CARMA API does. It&#8217;s disappointing, as this represents a barrier to creating really interesting applications. The bar is much higher in terms of resources needed for finding, scraping, and transforming data locked into HTML tables or proprietary spreadsheet files. Still, more and more organizations are beginning to realize that making their data available &#8211; in ways others can begin using immediately &#8211; can generate a much bigger impact than keeping it to themselves. There are some interesting possibilities for CARMA mashups out there today, and I&#8217;ve documented them below. If you know of any that I&#8217;ve missed, we&#8217;d love to hear about them in the comments.</p>
<p><span id="more-69"></span></p>
<h3>Data &#8211; Carbon Footprint</h3>
<p>AMME, the Avoid Mass Extinctions Engine, provides a common standard for calculating carbon footprint. Data are available via an <a href="http://trac.co2.dgen.net/wiki/AmeeConcepts">API</a>. These calculations are tied to a profile, which could be an individual, an organization, or another entity. It&#8217;s another REST API and returns data in HTML, XML, or JSON. Access to the API requires credentials, and the idea is to provide data about the carbon footprint of nearly any product, such as an appliance, or activity, like an airplane trip. It&#8217;d be interesting to see how average domestic electrical use correlates with power plant emissions. A mashup might use AMEE to get representative <a href="http://wiki.amee.cc/index.php/Home">home&#8217;s electricity usage</a> for a country and compare that to the CO<sub>2</sub> output and Intensity from CARMA.</p>
<h3>Data &#8211; Environmental Protection Agency</h3>
<p>The United Stated Environmental Protection Agency provides an <a href="http://www.epa.gov/enviro/html/technical.html">envirofacts database</a>, which could be really compelling if displayed next to CARMA data, particularly mapped power plants, for a US zip code, city, or county. The EPA maps show points where pollutions was discharged to water, Superfund sites, hazardous waste, and more. You can see a sample map for the latest Geospatial Data files. The zip file contains a single 169 MB file. That&#8217;s better than nothing, but you will have to parse the file and transform it into data you can query by state, zip code, etc.<a href="http://findpollution.org/"> FindPollution</a> makes use of EPA data for displaying pollution by US Zip code. <a href="http://www.planethazard.com/">Planet Hazard</a> also maps EPA&#8217;s National Emission Inventory of hazardous air pollutants.  But neither of them republish the data.</p>
<h3>Data &#8211; CAIT</h3>
<p>Protected behind a login and password, the World Resources Institute has a <a href="http://cait.wri.org/">Climate Analysis Indicators Tool</a>. You can get some data, but as posted in their Forum, &#8220;We have actually purposely set up CAIT to not allow users to download large amounts of data at a time (e.g., by sector, or year). This is due to our data-sharing agreement with the International Energy Agency, one of CAIT&#8217;s principal sources for CO<sub>2</sub> data.&#8221; A quick look at the<a href="http://data.iea.org/ieastore/default.asp?"> IAE&#8217;s data page</a> shows that getting data from them is not so easy or available for free. Still, if you are willing to register and parse the CSV files , you could do some interesting analyses. For example, one could calculate and compare what fraction of a country&#8217;s total CO<sub>2</sub> emission come from its power sector. Similarly, one could compare CAIT&#8217;s calculations of Intensity (in gCO<sub>2</sub>/kWh) per country to CARMA&#8217;s intensity data for Power Plants.</p>
<h3>Tools &#8211; DIY Map</h3>
<p><a href="http://backspace.com/mapapp/">DIY Map</a> is a very easy to use flash mapping application that reads data from a specially crafted XML file.  It can present data as points on a map or by filling a country or state with different colors.  CARMA data could be presented by coloring countries based on their CO<sub>2</sub> emissions.  Users could then click around various regions and countries to explore the data further.  Transforming CARMA data to display on a world map wouldn&#8217;t be very difficult, the only challenge is in matching Country data to the <a href="http://en.wikipedia.org/wiki/List_of_FIPS_country_codes">FIPS country codes</a> DIY Map uses to identify countries.</p>
<h3>Tools &#8211; XML/SWF Charts</h3>
<p>Another way to present data is through traditional graphs and charts, and there are many solutions available for building graphs from data.  One free option is <a href="http://www.maani.us/xml_charts/">XML/SWF Charts</a>, which takes an XML data file describing a chart and its data to draw and animate slick <a href="http://www.maani.us/xml_charts/index.php?menu=Gallery">flash charts</a>.  Besides the usual regional/country/state comparisons, one could plot the CO<sub>2</sub> emission, electricity generated, and intensity for a set of plants.  Such a chart could provide another perspective for comparing the environmental impact of a group of plants.</p>
]]></content:encoded>
			<wfw:commentRss>http://carma.org/blog/dna-for-more-api-mashups/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Use the PHP CARMA Client to Seamlessly Retrieve Data</title>
		<link>http://carma.org/blog/how-to-use-the-php-carma-client-to-seamlessly-retrieve-data/</link>
		<comments>http://carma.org/blog/how-to-use-the-php-carma-client-to-seamlessly-retrieve-data/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 21:56:42 +0000</pubDate>
		<dc:creator>Oscar Merida</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://carma.org/blog/how-to-use-the-php-carma-client-to-seamlessly-retrieve-data/</guid>
		<description><![CDATA[At some point, working with any API involves making HTTP requests to retrieve data, followed by decoding that into a useful data structure for your own application. In the case of the CARMA API, there are five methods that can be called (getPlant, getCompany, searchPlants, searchCompanies,and searchLocations), and data can be returned as either JSON [...]]]></description>
			<content:encoded><![CDATA[<p>At some point, working with any API involves making HTTP requests to retrieve data, followed by decoding that into a useful data structure for your own application. In the case of the <a target="_blank" href="http://carma.org/api/1.2/">CARMA API</a>, there are five methods that can be called (getPlant, getCompany, searchPlants, searchCompanies,and searchLocations), and data can be returned as either JSON (Javascript Object Notation) or XML. Making HTTP requests and decoding the data returned can be a tedious, thankless operation, and, frankly, its not code that a lot of developers look forward to writing.</p>
<p>So, to make CARMA&#8217;s API even easier, we&#8217;re pleased to provide a <a href="http://carma.org/api/php_client/">PHP5 CARMA client</a> that takes care of the low-level details and lets you focus on creating a cool widget or mash up with CARMA&#8217;s data.<span id="more-62"></span></p>
<p><strong>Requirements</strong></p>
<p>The Carma PHP Client requires PHP5. It makes use of <a href="http://www.php.net/stream">PHP&#8217;s native streams</a> functionality to fetch data from the CARMA site. If you have the JSON extension, behind the scenes it will decode returned data, otherwise it falls back to using SimpleXML to parse XML data.</p>
<p><strong>Download the Client</strong></p>
<p>Download the PHP source code for the <a href="http://carma.org/api/php_client/">CARMA client here</a>. You may need to right click and select &#8220;Save as..&#8221; from your browser&#8217;s context menu.</p>
<p><strong>Basic Usage</strong></p>
<p>I&#8217;ve tried to make the client as simple to use as possible, leaving the implementation details out of the way. After you download it, simply include it in your script and you&#8217;re ready to go. Here is a simple example for retrieving data for a plant whose ID we already know:</p>
<pre>
include('CarmaClient.php')$carma = new CarmaClient();$plant = $carma-&gt;getPlant(25097);// will display "LEWISTON MILL" and its dataecho $plant-&gt;name . " is operated by " . $plant-&gt;company-&gt;name . '';   

echo "&lt;br /&gt;Current carbon output: " . number_format($plant-&gt;carbon-&gt;present, 2)';   

echo "&lt;br /&gt;Future carbon output: " . number_format($plant-&gt;carbon-&gt;future, 2) ;</pre>
<p>If you know the ID of a company in CARMA&#8217;s database, you can fetch the details for the company with one call. Continuing our example:</p>
<pre>$company = $carma-&gt;getCompany(array("id" =&gt; $plant-&gt;company-&gt;id));</pre>
<p>The searchPlants, searchCompanies, and searchLocations commands query the CARMA database in useful and revealing ways. These methods are available through the php client and will return an array of php objects. Let&#8217;s say we want to produce a list of companies in the state of Virginia in the USA. This is a two-step query; we need to figure out the locaiton ID for the state of Virginia, and then we can find the companies associated with that location.</p>
<p>First, we need to find the location ID of the state of Virginia:</p>
<pre>$locations = $carma-&gt;searchLocations(array('name' =&gt; 'Virginia', 'type' =&gt; '3'));// carma api returns ANY location with the word Virginia in it so we have to filter the resultsforeach ($location as $loc) {   

    if ('Virginia' == $loc-&gt;name)   

    {   

        $va = $loc;   

    }   

}</pre>
<p>Now we can find all the plants located in Virginia and list them:</p>
<pre>$plants = $carma-&gt;searchPlants(array('location' =&gt; $va-&gt;id));echo "&lt;p&gt;There are " . $va-&gt;plant_count . " plants in Virginia.  They are: &lt;/p&gt;&lt;ul&gt;";foreach ($plants as $plant)   

{   

    echo "&lt;li&gt;" . $plant-&gt;name .' -Future Carbon Output: ' . number_format($plant-&gt;carbon-&gt;future) ." tons &lt;/li&gt;"   

}echo "&lt;/ul&gt;"</pre>
<p>CARMA&#8217;s data has infinite applications, as my colleague Matt Gibbs <a href="http://carma.org/blog/carma-api-widgets/">noted in an earlier post</a>, and now it&#8217;s easier than ever to start creating great projects of your own. If you want to play with the CARMA API and have PHP available, please download the <a href="http://carma.org/api/php_client/">Carma Client</a> and let us know how you are using it.</p>
]]></content:encoded>
			<wfw:commentRss>http://carma.org/blog/how-to-use-the-php-carma-client-to-seamlessly-retrieve-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

