codeforanchorage / realtime-bus-sms

Text back current arrival time for buses given a texted in bus stop number for People Mover. AddressLookup branch would allow texting "Arctic and Fireweed"
https://bus.codeforanchorage.org
14 stars 10 forks source link

Find the Electric Bus #132

Closed joelturman closed 6 years ago

joelturman commented 6 years ago

Adds "Find the Electric Bus" to the webpage. When a user clicks, a remote xml file is check for the current location of the electric bus and it is returned to the user. The 'xml2json' package was added to handle the xml data.

mark-meyer commented 6 years ago

Hey Joel — I was able to get this working locally with no trouble. It's very cool! I have few ideas, which you can use if you're interested.

When you click the link, it replaces the text in the link itself and so the new text about the bus is linked, which is a little unusual. I wonder if it would work more consistently with the rest of the app if the output ended up in the same place as the output for other requests? There's already a function in the index.jade that does this, which you could use like if you wanted to do this:

function electricBus() {
            var http = new XMLHttpRequest();
            var url = '/electricBus';
            http.open('GET', url, true);
            http.onreadystatechange = updateOutputDiv.bind(http);
            http.send();
        }

Also, the way you are finding the bus object is working fine, but there is an option to simplify if you're interested. You can get the bus object directly with something like:

var parsed_data = JSON.parse(parser.toJson(body));
var bus_object = parsed_data['vehicle-locations'].vehicle.find(item => item.name == '60303') 

bus_object should then be just the object you want:

{ 'op-status': 'none',
  'comm-status': 'OOS Inactive',
  'gps-status': 'bad',
  name: '60303',
  routeid: '0',
  tripid: '0',
  direction: {},
  laststop: {},
  latitude: '61.1774',
  longitude: '-149.81412',
  speed: { units: 'mph', '$t': '0' },
  heading: '0' }

That will save you the extra steps of creating the drill_down objects…just an idea.

Also, I wonder if we could find something about the bus and include a little snippet of info about the bus and why it's here. It might be a nice opportunity to let the riders know what's going. I'll ask on slack and see if Brendan has any info we can include.

joelturman commented 6 years ago

Thanks Mark! I am on board.

If this gets pulled today for the Transportation Fair I can submit another pull request later this week with these changes, and maybe some neat electric bus icons.