<?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>Adam Albright</title>
	<atom:link href="http://adam-albright.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://adam-albright.com</link>
	<description></description>
	<lastBuildDate>Thu, 10 Jun 2010 20:01:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Vanderbilt Crime View</title>
		<link>http://adam-albright.com/2010/06/crimeview/</link>
		<comments>http://adam-albright.com/2010/06/crimeview/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 05:41:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://adam-albright.com/?p=55</guid>
		<description><![CDATA[<p>The final project for my Web 2.0 class involved creating a Mashup by aggregating multiple data sources from the internet and creating a visual representation of the data. As I scoured the internet for various data sources I came across the Vanderbilt Crime Log, which lists all of the crimes or incidences that occurred on [...]]]></description>
			<content:encoded><![CDATA[<p>The final project for my Web 2.0 class involved creating a Mashup by aggregating multiple data sources from the internet and creating a visual representation of the data. As I scoured the internet for various data sources I came across the <a title="VPD Crime Log" href="http://police.vanderbilt.edu/crime_log" target="_blank">Vanderbilt Crime Log</a>, which lists all of the crimes or incidences that occurred on or near the Vanderbilt University campus in Nashville, TN. I combined this data along with historical weather data provided by Weather Underground to create Vanderbilt Crime View.</p>
<p style="text-align: center;"><a href="http://adam-albright.com/vucrime/" target="_blank"><img class="size-full wp-image-85 aligncenter" title="Vanderbilt Crime View" src="http://adam-albright.com/wp-content/uploads/2010/05/vucrime.png" alt="" width="674" height="416" /></a></p>
<p><a title="Vanderbilt Crime View Demo" href="http://adam-albright.com/vucrime/" target="_blank" class="button-demo">DEMO</a></p>
<hr />
<h1><span style="color: #ff0000;">How I Did It</span></h1>
<h2>Part I: The Data</h2>
<p>===================</p>
<h3>Parsing the data</h3>
<p>Unfortunately, as of May 2010 the data was provided in a PDF format [<a href="http://adam-albright.com/blog_files/2010.04.vpd.crime.log.pdf" target="_blank">example PDF</a>] and had to be converted into a spreadsheet/database before geo-coding could be done. Using Adobe Acrobat’s Export to Plain Text feature I was able to produce a file that I could parse (the HTML and DOC exports were unable to produce consistent tables due to the lack of vertical lines on the tables). Luckily the text file was formatted so that each row was on a separate line and columns (for the most part) were delimited by a tab. Using the following regular expression and some PHP I was able to convert 15 months worth of PDFs into a MySQL table.</p>
<pre class="brush: php;">
// REGEX
^(.+?)  (.+?)(?:10|09)-.+?  (.+?)  (.+?)(?:Active|Inactive|Arrest|Unfounded).*?  (.*)
</pre>
<h3>Cleaning the data</h3>
<p>After looking through the data that was collected I noticed that the format used for displaying the location had changed sometime during the year. Locations were sometimes written BUILDING NAME &#8211; ADDRESS while other times listed as ADDRESS (BUILDING NAME). In order to geo-code the data I needed to separate the address from the building name. I decided to add a `building` field to my MySQL table which I would populate by parsing the location field for each record. I used the following PHP and regular expression to do so:</p>
<pre class="brush: php;">
$l = 'Location From the DB'

if(strpos($l,'(') !== false){
    $loc = preg_replace('/\s*\(.+?\)\s*/im', '', $l);

    if (preg_match('/\((.+?)\)/im', $l, $regs))
        $name = $regs[1];
}
elseif (strpos($l,'-') !== false) {
    $c = explode('-',$l);
    $name = trim($c[0]);
    $loc = trim($c[1]);
}
</pre>
<p>While this does not take into account hyphenated building names and other edge cases, it provided adequate results for the project and was definitely preferred to manually parsing the data.</p>
<h3>Geo-coding the data</h3>
<p>The next step of the process was to geo-code (i.e. determine the latitude and longitude) for each of the crimes. I turned to Google for this task and wrote a PHP script to query the <a target="_blank" href="http://code.google.com/apis/maps/documentation/geocoding/index.html#GeocodingRequests">Google Geocoding API</a> and save the resulting data to the MySQL table. By only geocoding DISTINCT locations and issuing an UPDATE on all crimes that shared a particular location I was able to drastically cut down on the number of geocoder lookups needed.</p>
<p>For each lookup Google provides an accuracy value that indicates how sure Google is about the result. By saving this value to the database I was able to determine which locations needed more attention. Some of the entries were misspelled or corrupt, while others didn’t include adequate location information. In particular, many locations just had a BUILDING NAME without an address. In addition to this many buildings are located in the middle of campus (not near a road). To remedy these issues I turned to the <a target="_blank" href="http://www.vanderbilt.edu/map">Vanderbilt Map</a> which makes use of a GML file containing the latitude/longitude coordinates for each building on campus (I discovered the file using the Firefox Tamper Data plugin). After a few tweaks to the file, PHP was able to parse it and provided me the geocoding data for all buildings on campus. I saved this parsed data into my database and used it to update my crimes table.</p>
<pre class="brush: php;">
&lt;?PHP

$buildings = simplexml_load_string(file_get_contents(&quot;vu.gml&quot;));

foreach($buildings as $building) {
  $building_name = $building-&gt;facilities-&gt;FACILITY_NAME;
  $coords = $building-&gt;facilities-&gt;msGeometry-&gt;Polygon-&gt;outerBoundaryIs-&gt;LinearRing-&gt;coordinates;
}

?&gt;
</pre>
<h3>Spreading out the data</h3>
<p>Since there exact locations that appear more than once, there are also multiple latitude/longitude pairs that are the same. This becomes problematic when visualizing the data on a map because all of crimes that occurred at the same location are plotted on top of one another are covered by the top marker. In order to provide a more useful visualization I moved all pins that were at the same lat/lon by a random amount (between 0 and a hundred feet) in a random direction. I accomplished this using the below SQL query.</p>
<pre class="brush: php;">
$result = mysql_query(&quot;SELECT count(*), lat, lon FROM `crimes` GROUP BY lat, lon HAVING count(*) &gt; 1 ORDER BY count(*) desc&quot;);

while($r = mysql_fetch_assoc($result)){
    mysql_query(&quot;UPDATE crimes SET lat = (lat + (RAND() * 0.0002516197121987) - 0.00012580985609934), lon = (lon + (RAND() * 0.0002516197121987) - 0.00012580985609934) WHERE lat=&quot;.$r['lat'].&quot; AND lon=&quot;.$r['lon'];
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://adam-albright.com/2010/06/crimeview/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programming Competition</title>
		<link>http://adam-albright.com/2009/11/programming-competition/</link>
		<comments>http://adam-albright.com/2009/11/programming-competition/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 06:44:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://adam-albright.com/?p=35</guid>
		<description><![CDATA[<p>Every year the ACM International Collegiate Programming Contest gives college students the opportunity to compete in teams to solve software design problems. This year I competed in the Mid-Central USA Regional round at Tennessee Technological University that consisted of 24 teams from 10 universities. My team placed first, solving 5 brain-teasers in under 5 hours. [...]]]></description>
			<content:encoded><![CDATA[<p>Every year the ACM International Collegiate Programming Contest gives college students the opportunity to compete in teams to solve software design problems. This year I competed in the Mid-Central USA Regional round at Tennessee Technological University that consisted of 24 teams from 10 universities. My team placed first, solving 5 brain-teasers in under 5 hours. With the last minute pressure stepping up our game, we submitted our 5<sup>th</sup> problem minutes before the buzzer and completed a 6<sup>th</sup> problem minutes after the competition had ended.</p>
<p>Each team was assigned a single workstation in a classroom with 5-7 other teams. The workstation was not connected to the internet and the use of other electronic devices was not allowed. The competition stipulates that solutions may only be submitted in Java, C, or C++. Fortunately, Eclipse with code assist and Javadoc was available, making the precious minutes we actually got to program very enjoyable. When the <a class="wpGallery" href="http://www.adam-albright.com/files/ACM.Problems.2009.pdf" target="_blank">packet of problems</a> was handed out we quickly scanned through them to determine which could be solved quickly and which would require a longer time commitment. We did this by assigning certain problems to each member of our 3 person team so we could each screen for difficulty, and code-up a solution for any really easy ones we found. We used modular arithmetic to divide the problems. I was assigned those that the problem number mod 3 equaled 1 (1, 4 and 7). Since we had to share a single terminal, most of our time was spent writing out code (pseudo-code really) on paper and stacking it up to be programmed when the PC became available.</p>
<p>Each program could be run locally against a set of test inputs to determine if the output was correct and once the problem was submitted to the judges, the program was tested against a much larger set of inputs to verify correct functionality.  A response was usually received by the judges within about 30 seconds stating whether or not the submitted solution was correct. I submitted the Gnome problem (#1) within the first 15 minutes (after waiting my turn for the computer) and worked the remainder of the time predominantly on the Cell problem (#4) which involved calculating the signal strength of cellular towers at precise intervals located along an arbitrary route.</p>
<p>After the competition we devoured lots of free pizza and sodas before heading to the auditorium to hear the results. Each member of each team was presented with a certificate and the top 3 teams were awarded prizes. For first place, my team received IBM <a class="wpGallery" href="http://www.greenorb.co.uk/product_info.php?products_id=182" target="_blank">water powered clocks</a>.</p>
<p>Check out the article published by the Vanderbilt School of Engineering:</p>
<h3><span style="color: #ff0000;"><a href="http://frontweb.vuse.vanderbilt.edu/vuse_web/news/releases2009/VandyComputerScienceTeamPlacesFirst.htm" target="_blank">&#8220;Vanderbilt computer science team places first in regional round of IBM’s Battle of the Brains&#8221;</a></span></h3>
]]></content:encoded>
			<wfw:commentRss>http://adam-albright.com/2009/11/programming-competition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zapping the Zune Display</title>
		<link>http://adam-albright.com/2009/08/zapping-the-zune-display/</link>
		<comments>http://adam-albright.com/2009/08/zapping-the-zune-display/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 02:22:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://adam-albright.com/?p=20</guid>
		<description><![CDATA[<p>In June 2007 my Apple iPod 5g died, displaying the infamous sad face of death. I decided it was time for a change and purchased the Microsoft Zune as its replacement, hoping its larger screen and lower price would make the switch a pleasant one. While the user interface of the Zune met my expectations, [...]]]></description>
			<content:encoded><![CDATA[<p>In June 2007 my Apple iPod 5g died, displaying the infamous sad face of death. I decided it was time for a change and purchased the Microsoft Zune as its replacement, hoping its larger screen and lower price would make the switch a pleasant one. While the user interface of the Zune met my expectations, it lacked a few essential features, namely a clock or sleep timer. The fact that the onboard wireless card could only be used to send music to other Zunes was another cause of disappointment. My biggest gripe with the Zune is that the <strong>backlight cannot be turned off</strong><em> </em>when listening to music &amp; it’s plugged in (or it&#8217;s placed in the official Microsoft Dock).  Now, this usually isn&#8217;t an issue during the day, but for those of us that like to play music while we&#8217;re falling asleep, it lights up the room like a flashlight.</p>
<p>My first response was to search the Settings menu for a backlight option. Unfortunately changing the backlight setting to &#8220;Never&#8221; was useless. So my options were either to remove the Zune from the dock or try to cover up the display to reduce the light. Because Microsoft failed to include a sleep timer, the first option doesn&#8217;t make sense if you&#8217;d like to wake up to a charged mp3 player. So while I waited for months on end for Microsoft to release updated firmware that would remedy my dilemma, I found myself scavenging each night for a book or other dense objects that could block out the Zune&#8217;s display from lighting up my otherwise dark room.</p>
<p>As the weeks turned into months, my hope that Microsoft would fix this bug/feature diminished. Because physically blocking the screen wasn&#8217;t completely effective, I continued searching for workarounds. Using my programmer mentality I looked into writing my own software for the Zune that would cut off the display. This was another dead end as the Zune&#8217;s API doesn&#8217;t support that. My next move was to load a solid black image into the Zune photo gallery and display it fullscreen when going to sleep. That worked fairly well and was a great alternative to having the album art displayed.</p>
<p>Recently after trying to download an open source sleep timer to my Zune, I discovered the best workaround yet &#8212; the TV output mode. Apparently Microsoft thought it was necessary to have the Zune capable of being displayed on a TV using special cords or a dock. While I doubt I’d ever want to hook up my Zune to a TV, the TV output mode has an interesting property &#8212; it redirects the video from the Zune&#8217;s display to the TV. Luckily the Zune doesn&#8217;t check to see if it&#8217;s actually connected to a TV, and shuts off its display regardless. Finally a way to preserve the pitch black state of my room without sacrificing the Zune&#8217;s battery or my sanity. Now if Microsoft would only provide a sleep timer, I&#8217;d be set.</p>
]]></content:encoded>
			<wfw:commentRss>http://adam-albright.com/2009/08/zapping-the-zune-display/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Here we go!</title>
		<link>http://adam-albright.com/2009/07/hello-world/</link>
		<comments>http://adam-albright.com/2009/07/hello-world/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 18:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http:/?p=1</guid>
		<description><![CDATA[<p>I&#8217;ve finally decided to indulge in the blogosphere and soup up my website with code I&#8217;ve written and information about my life and projects I&#8217;m involed with. Stay tuned for more posts soon as I get everything organized!</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally decided to indulge in the blogosphere and soup up my website with code I&#8217;ve written and information about my life and projects I&#8217;m involed with. Stay tuned for more posts soon as I get everything organized!</p>
]]></content:encoded>
			<wfw:commentRss>http://adam-albright.com/2009/07/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

