Showing posts with label transportation. Show all posts
Showing posts with label transportation. Show all posts

2009-10-02

Solving transit questions with PHP

When I saw Visualmotive's "Walk or Bus?" chart, I was fascinated. I love stuff like this! It answers the question of "If I have to be somewhere, is it going to be faster to wait for a bus, or just start hiking?"

I am a multi-mode commuter. I often use my bike combined with the bus to get myself downtown. Sometimes, I also need to get around the city. I almost always do this on my bike unless it's somewhere really close. Still, I felt compelled to create a chart that included bicycling, as well as walking.


The top header is how long you'll have to wait for the bus.Where there's a gray bus icon, it's faster to wait for the bus. Where there's a blue bicycle, it's faster to hop on the bike and ride. The yellow jogging man represents a brisk walking pace and the green foot represents trudging along with an average gait. I extended the chart out to 4.0 miles, which is about how far one can get on a bicycle in an urban setting within half an hour at 8 MPH. These are just guidelines, of course. Some people are considerably faster on bicycles. Others are slower. Same with walking and the bus, actually.

Click for big:


I ended up making a quick program in PHP to draw the main part of the above chart for me. I sourced the icons from the same place Visualmotive did (icons.mysitemyway.com) but opted to modify their icon colors, then added the headers manually in GIMP. I'll upload a .zip file (and link to it) later, with the icons.

The algorithm is pretty straightforward. Urban buses probably average 15 MPH with all their stops included, or about 4 minutes for every mile. Most people can get around on a bicycle at an average speed of 8 MPH (7:30) and so on and so forth as commented in the code below.

The code is pretty simple and very ugly. Not only did I use tables (ew) but I also barf out HTML with PHP. This is why I say there's a massive difference between programmers (like me) and developers (who code for a living).


<html><head><title>Walk, Bike, or Bus?</title></head><body>
<TABLE cellpadding='0' cellspacing='0'><TR>
<TD></TD><TD><CENTER>1</CENTER></TD><TD><CENTER>2</CENTER></TD>
<TD><CENTER>3</CENTER></TD><TD><CENTER>4</CENTER></TD>
<TD><CENTER>5</CENTER></TD><TD><CENTER>6</CENTER></TD>
<TD><CENTER>7</CENTER></TD><TD><CENTER>8</CENTER></TD>
<TD><CENTER>9</CENTER></TD><TD><CENTER>10</CENTER></TD>
<TD><CENTER>11</CENTER></TD><TD><CENTER>12</CENTER></TD>
<TD><CENTER>13</CENTER></TD><TD><CENTER>14</CENTER></TD>
<TD><CENTER>15</CENTER></TD><TD><CENTER>16</CENTER></TD>
<TD><CENTER>17</CENTER></TD><TD><CENTER>18</CENTER></TD>
<TD><CENTER>19</CENTER></TD><TD><CENTER>20</CENTER></TD>
<TD><CENTER>21</CENTER></TD><TD><CENTER>22</CENTER></TD>
<TD><CENTER>23</CENTER></TD><TD><CENTER>24</CENTER></TD>
<TD><CENTER>25</CENTER></TD><TD><CENTER>26</CENTER></TD>
<TD><CENTER>27</CENTER></TD><TD><CENTER>28</CENTER></TD>
<TD><CENTER>29</CENTER></TD><TD><CENTER>30</CENTER></TD></TR><TR>
<!-- Model View Controller what? -->
<?php
$Miles
=.2; # .2 Miles. Just walk it. Jeez.
while ($Miles <= 4.0){
$Miles=$Miles+.1;
$TravelTime['Bus'] = $Miles * 4; # Bus ! 15 MPH (4:00 mile)
$TravelTime['Bike'] = $Miles * 7.5; # Bike ~ 8 MPH (7:30 mile)
$TravelTime['Brisk'] = $Miles * 15; # Brisk walk ~ 4 MPH (15:00)
$TravelTime['Walk'] = $Miles * 20; # Walk ~ 3 MPH (20:00)
$Mins=0;
print
"<TR><TD><CENTER>$Miles</CENTER></TD>";
while (
$Mins < 30){
print
"<TD><CENTER>";
$Mins++;
if (
$Mins >= $TravelTime['Walk'])
{print
"<IMG WIDTH='45' SRC='img/iconwalk.png'>";}
elseif (
$Mins >= $TravelTime['Brisk'])
{print
"<IMG WIDTH='45' SRC='img/iconbrisk.png'>";}
elseif (
$Mins >= $TravelTime['Bike'])
{print
"<IMG WIDTH='45' SRC='img/iconbike.png'>";}
else
{print
"<IMG WIDTH='45' SRC='img/iconbus.png'>";}
print
"</CENTER></TD>";
}
print
"</TR>"; #I know you're not supposed to print HTML. Byte Me.
}
?></body></html>

So, what started as a desire to have a cool chart to share with other bicycling/pedestrian friends of mine turned into an exercise in algorithms last night, with a little bit of PHP programming tossed into the mix. This is yet another example of a quick-n-dirty program I wrote for something simple.

2008-10-03

Do you think this guy's a gamer?

I saw this in my parking garage at work a few days ago. These stickers were adorning some cargo boxes bolted to a nice-looking BMW Motorcycle. Taking a guess, I'd say this guy takes his games pretty seriously. 


My wife tells me "For the Horde!" is a World Of Warcraft reference. She plays it, I do not. Yet.


I particularly got a kick out of this one.

2008-10-02

Open Source... Bicycle Parts?!

Okay, I'll admit that my inner cyclist is a little giddy about this. While it certainly isn't programming or security related, it squarely falls into "other interesting topics" and the Xtracycle guys undoubtedly operate with a "hacker" and "maker" kind of attitude, all the while embracing sustainability and empowering others to use human powered machines for tasks that would previously require a car. The initial premise, realized almost a decade ago, was to build an extension frame that would bolt up to a plain old bicycle and move the rear wheel back quite a ways while adding structure and attachment points to support weight-bearing bags and platforms.

(Creative Commons photo by arifm)

Now, many manufacturers are running with the idea, and the guys at Xtracycle have decided to open-source their design in order to engage the community in collaboration and to allow anyone with the equipment and skill to make their own and build onto an already tried-and-true design. (Click for higher res)


They're using a Wiki to collaborate right now (and I should note that it's not working all the way yet). I'm not sure I'm ready to sell my car and break out the torch to weld one of these up myself yet, but it's a fascinating project, and it's the first time I've seen this kind of detail in their design.