Skip to content

Instantly share code, notes, and snippets.

@pablotron
Created February 19, 2015 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablotron/8735f7ad2f9f6f2b3f39 to your computer and use it in GitHub Desktop.
Save pablotron/8735f7ad2f9f6f2b3f39 to your computer and use it in GitHub Desktop.
example recall database parser
[{"RECORD_ID"=>"98200",
"CAMPNO"=>"13V454000",
"MAKETXT"=>"BMW",
"MODELTXT"=>"320I",
"YEARTXT"=>"2014",
"MFGCAMPNO"=>"",
"COMPNAME"=>"SERVICE BRAKES, HYDRAULIC:POWER ASSIST:VACUUM",
"MFGNAME"=>"BMW of North America, LLC",
"BGMAN"=>"20120501",
"ENDMAN"=>"20130831",
"RCLTYPECD"=>"V",
"POTAFF"=>"76191",
"ODATE"=>"20140131",
"INFLUENCED_BY"=>"ODI",
"MFGTXT"=>"BMW of North America, LLC",
"RCDATE"=>"20130926",
"DATEA"=>"20131021",
"RPNO"=>"",
"FMVSS"=>"",
"DESC_DEFECT"=>
"BMW of North America LLC (BMW) is recalling certain model year 2012-2014 320i, 328i, 320i xDrive, and 328i xDrive sedans; model year 2014 328i xDrive Sports Wagons; model year 2012-2013 528i and 528i xDrive sedans, model year 2013-2014 X1 sDrive28i and X1 xDrive28i vehicles and model year 2012-2014 Z4 sDrive28i roadsters. Due to insufficient lubrication, the vacuum pump that supplies brake power assistance may fail.",
"CONEQUENCE_DEFECT"=>
"A failure of the brake vacuum pump results in a reduction in braking power that could increase the risk of a crash.",
"CORRECTIVE_ACTION"=>
"BMW will notify owners, and dealers will modify the vehicles to prevent insufficient vacuum pump lubrication, free of charge. The safety recall began on January 31, 2014. Owners may contact BMW customer relations at 1-800-525-7417 or email BMW at CustomerRelations@bmwusa.com.",
"NOTES"=>
"Owners may also contact the National Highway Traffic Safety Administration Vehicle Safety Hotline at 1-888-327-4236 (TTY 1-800-424-9153), or go to www.safercar.gov.",
"RCL_CMPT_ID"=>"000055218001917946000000067"},
{"RECORD_ID"=>"98201",
"CAMPNO"=>"13V454000",
"MAKETXT"=>"BMW",
"MODELTXT"=>"320I",
"YEARTXT"=>"2014",
"MFGCAMPNO"=>"",
"COMPNAME"=>
"SERVICE BRAKES, HYDRAULIC:POWER ASSIST:VACUUM:HOSES, LINES/PIPING, AND FITTINGS",
"MFGNAME"=>"BMW of North America, LLC",
"BGMAN"=>"20120501",
"ENDMAN"=>"20130831",
"RCLTYPECD"=>"V",
"POTAFF"=>"76191",
"ODATE"=>"20140131",
"INFLUENCED_BY"=>"ODI",
"MFGTXT"=>"BMW of North America, LLC",
"RCDATE"=>"20130926",
"DATEA"=>"20131021",
"RPNO"=>"",
"FMVSS"=>"",
"DESC_DEFECT"=>
"BMW of North America LLC (BMW) is recalling certain model year 2012-2014 320i, 328i, 320i xDrive, and 328i xDrive sedans; model year 2014 328i xDrive Sports Wagons; model year 2012-2013 528i and 528i xDrive sedans, model year 2013-2014 X1 sDrive28i and X1 xDrive28i vehicles and model year 2012-2014 Z4 sDrive28i roadsters. Due to insufficient lubrication, the vacuum pump that supplies brake power assistance may fail.",
"CONEQUENCE_DEFECT"=>
"A failure of the brake vacuum pump results in a reduction in braking power that could increase the risk of a crash.",
"CORRECTIVE_ACTION"=>
"BMW will notify owners, and dealers will modify the vehicles to prevent insufficient vacuum pump lubrication, free of charge. The safety recall began on January 31, 2014. Owners may contact BMW customer relations at 1-800-525-7417 or email BMW at CustomerRelations@bmwusa.com.",
"NOTES"=>
"Owners may also contact the National Highway Traffic Safety Administration Vehicle Safety Hotline at 1-888-327-4236 (TTY 1-800-424-9153), or go to www.safercar.gov.",
"RCL_CMPT_ID"=>"000055218001917946000000068"},
{"RECORD_ID"=>"98202",
"CAMPNO"=>"13V454000",
"MAKETXT"=>"BMW",
"MODELTXT"=>"320I",
"YEARTXT"=>"2013",
"MFGCAMPNO"=>"",
"COMPNAME"=>"SERVICE BRAKES, HYDRAULIC:POWER ASSIST:VACUUM",
"MFGNAME"=>"BMW of North America, LLC",
"BGMAN"=>"20120501",
"ENDMAN"=>"20130831",
"RCLTYPECD"=>"V",
"POTAFF"=>"76191",
"ODATE"=>"20140131",
"INFLUENCED_BY"=>"ODI",
"MFGTXT"=>"BMW of North America, LLC",
"RCDATE"=>"20130926",
"DATEA"=>"20131021",
"RPNO"=>"",
"FMVSS"=>"",
"DESC_DEFECT"=>
"BMW of North America LLC (BMW) is recalling certain model year 2012-2014 320i, 328i, 320i xDrive, and 328i xDrive sedans; model year 2014 328i xDrive Sports Wagons; model year 2012-2013 528i and 528i xDrive sedans, model year 2013-2014 X1 sDrive28i and X1 xDrive28i vehicles and model year 2012-2014 Z4 sDrive28i roadsters. Due to insufficient lubrication, the vacuum pump that supplies brake power assistance may fail.",
"CONEQUENCE_DEFECT"=>
"A failure of the brake vacuum pump results in a reduction in braking power that could increase the risk of a crash.",
"CORRECTIVE_ACTION"=>
"BMW will notify owners, and dealers will modify the vehicles to prevent insufficient vacuum pump lubrication, free of charge. The safety recall began on January 31, 2014. Owners may contact BMW customer relations at 1-800-525-7417 or email BMW at CustomerRelations@bmwusa.com.",
"NOTES"=>
"Owners may also contact the National Highway Traffic Safety Administration Vehicle Safety Hotline at 1-888-327-4236 (TTY 1-800-424-9153), or go to www.safercar.gov.",
"RCL_CMPT_ID"=>"000055218001917945000000067"},
{"RECORD_ID"=>"98203",
"CAMPNO"=>"13V454000",
"MAKETXT"=>"BMW",
"MODELTXT"=>"320I",
"YEARTXT"=>"2013",
"MFGCAMPNO"=>"",
"COMPNAME"=>
"SERVICE BRAKES, HYDRAULIC:POWER ASSIST:VACUUM:HOSES, LINES/PIPING, AND FITTINGS",
"MFGNAME"=>"BMW of North America, LLC",
"BGMAN"=>"20120501",
"ENDMAN"=>"20130831",
"RCLTYPECD"=>"V",
"POTAFF"=>"76191",
"ODATE"=>"20140131",
"INFLUENCED_BY"=>"ODI",
...
#!/usr/bin/env ruby
module Recall
class Search
def initialize(path)
# load data
@data = File.readlines(path)
end
def search(q)
# split query string into search terms
terms = q.strip.downcase.split(/\s+/)
@data.select { |line|
begin
# lowercase line
lc = line.downcase
# match search terms
terms.all? { |t| lc.index(t) }
rescue Exception => e
# skip records with invalid encoding
# warn "skipping record: #{e}"
false
end
}.map { |line|
# convert line to record and return it
to_record(line)
}
end
private
# source: http://www-odi.nhtsa.dot.gov/downloads/folders/Recalls/RCL.txt
COLUMNS = [
{ name: 'RECORD_ID', type: 'NUMBER(9', blurb: 'RUNNING SEQUENCE NUMBER, WHICH UNIQUELY IDENTIFIES THE RECORD.' },
{ name: 'CAMPNO', type: 'CHAR(12', blurb: 'NHTSA CAMPAIGN NUMBER' },
{ name: 'MAKETXT', type: 'CHAR(25', blurb: 'VEHICLE/EQUIPMENT MAKE' },
{ name: 'MODELTXT', type: 'CHAR(256', blurb: 'VEHICLE/EQUIPMENT MODEL' },
{ name: 'YEARTXT', type: 'CHAR(4', blurb: 'MODEL YEAR, 9999 IF UNKNOWN or N/A' },
{ name: 'MFGCAMPNO', type: 'CHAR(20', blurb: 'MFR CAMPAIGN NUMBER' },
{ name: 'COMPNAME', type: 'CHAR(256', blurb: 'COMPONENT DESCRIPTION' },
{ name: 'MFGNAME', type: 'CHAR(40', blurb: 'MANUFACTURER THAT FILED DEFECT/NONCOMPLIANCE REPORT' },
{ name: 'BGMAN', type: 'CHAR(8', blurb: 'BEGIN DATE OF MANUFACTURING' },
{ name: 'ENDMAN', type: 'CHAR(8', blurb: 'END DATE OF MANUFACTURING' },
{ name: 'RCLTYPECD', type: 'CHAR(4', blurb: 'VEHICLE, EQUIPMENT OR TIRE REPORT' },
{ name: 'POTAFF', type: 'NUMBER(9', blurb: 'POTENTIAL NUMBER OF UNITS AFFECTED ' },
{ name: 'ODATE', type: 'CHAR(8', blurb: 'DATE OWNER NOTIFIED BY MFR' },
{ name: 'INFLUENCED_BY', type: 'CHAR(4', blurb: 'RECALL INITIATOR (MFR/OVSC/ODI)' },
{ name: 'MFGTXT', type: 'CHAR(40', blurb: 'MANUFACTURERS OF RECALLED VEHICLES/PRODUCTS' },
{ name: 'RCDATE', type: 'CHAR(8', blurb: 'REPORT RECEIVED DATE' },
{ name: 'DATEA', type: 'CHAR(8', blurb: 'RECORD CREATION DATE' },
{ name: 'RPNO', type: 'CHAR(3', blurb: 'REGULATION PART NUMBER' },
{ name: 'FMVSS', type: 'CHAR(10', blurb: 'FEDERAL MOTOR VEHICLE SAFETY STANDARD NUMBER' },
{ name: 'DESC_DEFECT', type: 'CHAR(2000', blurb: 'DEFECT SUMMARY' },
{ name: 'CONEQUENCE_DEFECT', type: 'CHAR(2000', blurb: 'CONSEQUENCE SUMMARY ' },
{ name: 'CORRECTIVE_ACTION', type: 'CHAR(2000', blurb: 'CORRECTIVE SUMMARY' },
{ name: 'NOTES', type: 'CHAR(2000', blurb: 'RECALL NOTES' },
{ name: 'RCL_CMPT_ID', type: 'CHAR(27', blurb: 'NUMBER THAT UNIQUELY IDENTIFIES A RECALLED COMPONENT.' },
]
def to_record(line)
r = {}
# strip trailing whitespace, break into columns, then map values
# to column names
line.strip.split(/\t/).each_with_index do |val, i|
warn "i = #{i}"
r[COLUMNS[i][:name]] = val
end
# return result
r
end
end
end
#!/usr/bin/env ruby
require 'pp'
require './recall.rb'
# source: http://catalog.data.gov/dataset/nhtsas-office-of-defects-investigation-odi-recalls-nhtsa-api-1e65f
s = Recall::Search.new('FLAT_RCL.txt')
pp s.search('bmw 2014 brakes')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment