Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firefighting On Rails

Firefighting On Rails

A discussion of the worst code I ever wrote, and it's positive impact on my community. At the core, don't get so caught up in best practices that you forget to solve the problem you set out to code for.

Ethan Vizitei

May 07, 2013
Tweet

Other Decks in Programming

Transcript

  1. BCFPD 14 Engines, 9 Tankers, 12 Trucks, 2 Squads, 5

    Boats, 2 Command, 1 HazMat 250 firefighters, 14 Stations, 492 Square Miles Tuesday, May 7, 13
  2. Pager function • Alerts to your station tones • limited

    modes of operation • Fits on a normal car visor Tuesday, May 7, 13
  3. Pager Problems • Loud • Audio Only • Limited bandwidth

    • Programmable only by a technician Tuesday, May 7, 13
  4. Requirements 1 Weekend to build No exposed data ASAP info

    delivery Decision Makers vs User Compulsion Computer Literacy Tuesday, May 7, 13
  5. The Plan Web Status Board Polling Job w/ Mechanize Subscription

    Config Dashboard Incident Data Notifications w/ Links Tuesday, May 7, 13
  6. def fetch_call_info(incident_number) agent = Mechanize.new login(agent) page = agent.get("https://istatus.gocolumbiamo.com/DisplayCall.php?Incid=#{incident_number notes

    = page.parser.xpath("/html/body/table/tr[3]/table/tr/td/table/tr").map{|node| {:time=>node.children[0].text,:text=>node.children[1].text.gsub("\n","")}} if notes.size == 0 page = agent.get("https://istatus.gocolumbiamo.com/DisplayFireCall.php? Incid=#{incident_number}") notes = page.parser.xpath("/html/body/table/tr[3]/table/tr/td/table/tr").map{|node| {:time=>node.children[0].text,:text=>node.children[1].text.gsub("\n","")}} end call_info = {:id=>incident_number} address = page.links_with(:href=>/SearchDStatsSubmit\.php\?Address/).first.text call_info[:address] = address call_info[:nature] = page.parser.xpath("/html/body/table/tr[1]/td[1]/table/tr[3]/ td").text.strip.split("-").last call_info[:apparatus] = page.parser.xpath("/html/body/table/tr[1]/td[2]/table/tr/td[1]").m c| c.text.gsub("\n","").strip} call_info[:raw_notes] = notes.map{|n| "#{n[:time]} #{n[:text]}"}.join("|") spliced_notes = {} notes.select{|n| n[:text] =~ /[\(\[]\d+-\d+[\)\]]$/}.each do |note| note_text = note[:text] note_text_arr = note_text.split(/\s/) token = note_text_arr.delete_at(note_text_arr.size - 1) final_text = note_text_arr.join(" ") if spliced_notes[token].nil? spliced_notes[token] = [{:time=>note[:time],:text=>final_text}] else spliced_notes[token] << {:time=>note[:time],:text=>final_text} end end call_info[:notes] = {:pro_qa=>notes.select{|n| n[:text] =~ /^ProQA/}, Tuesday, May 7, 13
  7. class Incident include MongoMapper::Document # ... def formatted_message @msg ||=

    "#{address[0,25]}\n#{nature[0,15]}\n #{cropped_apparatus_list[0,12]}\n #{cross_street_1[0,12]}\n #{cross_street_2[0,12]}\n Map: #{build_map_url}\n Notes: #{build_notes_url}" end # ... end Tuesday, May 7, 13
  8. %h2== Welcome to Watchman, #{current_user.email} -if @status_record.active? %div.status{:style=>"background-color:green;color:white;width:300px;padding: 5px;font-weight:bold;"} Watchman

    is Active -else %div.status{:style=>"background-color:red;color:white;width:300px;padding:5px;font- weight:bold;"} Watchman is Down %br #my_subscriptions{:style=>"border: 1px solid black;padding:10px;width:300px;"} %h2 My current subscriptions -current_user.subscriptions.each do |name| .subscription= name =button_to "Remove","/cancel_subscription/#{name}" %br =form_tag subscriptions_path do =select_tag 'apparatus', options_for_select(Apparatus.county) =submit_tag "subscribe" %br Tuesday, May 7, 13
  9. Results Notifications in quiet spaces Personally configurable notifications Mapping data

    for accurate response Textual data for recall Full notes for decision support Firefighters are losing their pagers and forgetting how to read maps (???) Tuesday, May 7, 13
  10. What now? 1) Find Cool Problem 2) Write Bad Code

    3) Profit! Tuesday, May 7, 13
  11. What now? 1) Find Cool Problem 2) Write Bad Code

    3) Profit! Tuesday, May 7, 13
  12. Volunteer! • We can telecommute! • The workday is the

    hardest time for Volunteer fire departments to staff • You need the exercise! • Dangerous jobs require intelligent problem solvers. • Don’t pay for office space! • Genuine life experiences. • Diversify your social group (hard mode) • ~75% of firefighters in america are volunteers Tuesday, May 7, 13