In [73]:
import logging

In [74]:
from pymongo import MongoClient

In [75]:
logger = logging.getLogger(__name__)
# supercedes handler level
# if this level is lower than handler messages don't get through
logger.setLevel(logging.DEBUG)

# seems IPthon adds a stream handler. Might as well use it.
stream_handler = logger.handlers.pop(0) \
    if logger.handlers else logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
logger.addHandler(stream_handler)
logger.debug("The logger is working.")


The logger is working.

In [76]:
client = MongoClient()

In [77]:
# app is the name of the database
db = client.app

In [78]:
database_names = (
    citations,
    accidents,
) = (
    'citations',
    'accidents',
)

In [79]:
collections = citations, accidents = [getattr(db, database_name) for database_name in database_names]

In [91]:
for collection in collections:
    logger.debug(' '.join(("document count for {}: ".format(collection), str(collection.count()))))


document count for Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'app'), 'citations'):  46456
document count for Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'app'), 'accidents'):  13472

In [81]:
CITATION_CHARGE = 'Citation Charge'

In [82]:
citation_charges = list({citation[CITATION_CHARGE].lower() for citation in citations.find()})
citation_charges.sort()

In [83]:
logger.debug(citation_charges)


['', 'all on board pwc shall wear approved pfd', 'altered exhaust system', 'attach tag (license plate) not assigned', 'atv/safety equip/accd/under 16', 'bike regulations violations', 'block intersection/crosswalk', 'careless driving', 'careless operation', 'careless operation of vessel', 'child restraint required', 'child under 6 yoa shall wear approved pfd', 'coast guard safety equipment required', 'counterfeiting of-lic plates validation stickers mobile home', 'crash - diabled veh obstruct traffic - driv fail to move veh', 'crash - driv fail to rpt crash w injury/death/damage to lea', 'crash - fail remove obstruct attended veh - prop dam', 'crash - fail report info to injured person', 'crash - failure of veh occup to make report if driv unable', 'crash - leave scene involving injury w/o rendering aid', 'crash - no proof insurance all parties (24 hr clock rule)', 'crash - no proof of insurance', 'crash -give false information or reports to pol', 'crash leave scene w/o giving information (specify damage $$)', 'crash-driv fail rpt crash w inj/death/damage to lea ($500)', 'crash-fail to leave info unattended vehicle - prop damage', 'damage prop-crim misch-intrf w trf cont dev < 200 dols', 'defective windshield wipers', 'disobey flashing signal/yellow', 'disobey flashing signals/red', 'disobey lane control device', 'disobey no change of lane sign', 'disobey no pass zone sign', 'disobey red flashing signal', 'disobey steady red light ftyrow one way st', 'disobey stop/yield sign', 'disobey yellow light', 'disobey/avoid red light', 'disobey/avoid red light/turning', 'disobey/avoid traffic device', 'disobeyed stop/yield sign', 'display of registration decal', 'display of registration numbers and letters', 'display of truck tags: front/rear trucks cmv', 'display special state plates wo appli', 'display/obscur unauth traf dev', 'diving from any publicly owned (road) bridge (not csx)', 'dl possession/display/permitting use of susp/rev/canc/dq dl', 'dl suspended/ financial responsibility', 'driv on wrong side divided hwy', 'driv one-way street', 'driv permit riding on exterior', 'drive across divided section', 'drive across/on median', 'drive around detour/barricade', 'drive lic susp comml veh 2nd or subsq', 'drive on sidewalk/bike path', 'drive round/railroad gate/barr', 'drive veh unsafe/defect equip', 'drive w sus rev dl habit traffic off', 'drive w susp revkd dl for ftp child s', 'drive while lic susp 1st off', 'drive while lic susp 2nd off', 'drive while lic susp 3rd or subsq off', 'drive while lic susp comml veh 1st of', 'drive while lic susp habitual offende', 'drive while license susp w/o knowledge', 'drive while license suspended  revoked  cancelled w/know', 'drive while license suspended/revoked/canceled/w/knowledge', 'drive wo lic causes death/serious inj', 'drive wo valid comml drivers license', 'drive wrong lane or side', 'drive wrong side of roadway', 'driver present non current insurance', 'driver view obstructed', 'drivers view obstructed', 'driving on airless tire', 'driving thru safety zone', 'driving under the influence', 'driving w/ exp lic > 6mo', 'driving w/o lights', 'driving wrong lane or side', 'driving wrong way down one-way', 'drop / shift / leak load', 'drop or uncovered load', 'drugs-possession of controlled substance', 'drv left side in no pass zone', 'drv safe/dist rr after signal', 'drv w/o lghts twilght/fog/rain', 'dui alcohol or drugs   2nd offense', 'dui alcohol or drugs  1st offense', 'dui alcohol or drugs  3rd offense within 10 years', 'dui ubal>.15 or accom by pers < 18yoa', 'dui w/dam to prop or person of another', 'dui-unlaw bld alch-.15 or > or accom by pers < 18y/o 1st off', 'dui-unlaw bld alch-.15 or > or accom by pers < 18y/o 2nd off', 'dui-unlaw bld alch-bui 1st or 2nd violation', 'dui-unlaw bld alch-bui 1st violation', 'emit excess exhaust fumes', 'engine run/key in ignition', 'engine run/key/set brake', 'equip violation/migrant transp', 'exceed speed lim in work zone', 'expired d/l less than 6 months', 'expired mtr veh reg over 6 mos subsq', 'expired mtr veh registration over 6 months 1st off', 'expired tag less than 6 mos', 'expired tag/less than 6 months', 'fail change address/name', 'fail cover/secure load', 'fail dim headlghts/imp adjust', 'fail dim headlights/imp adjust', 'fail dim lights from rear', 'fail drive in single lane', 'fail drive to right/slow', 'fail give turn/stop signal', 'fail to change address on dl', 'fail to change name on dl', 'fail to dim headlights', 'fail to display veh reg', 'fail to drive in single lane', 'fail to lower dive flag', 'fail to notify hsmv chg of address', 'fail to obey cmv rules', 'fail to obey police or fire department', 'fail to obey sign/signal', 'fail to register motor veh', 'fail to signal turn properly', 'fail to stop remain accdnt involv non-ser injry', 'fail to stop remain accdnt involving serious injry', 'fail to stop steady red indication', 'fail to use designated lane/drive w/i single lane', 'fail to wear bike helmet', 'fail to yield right-of-way to pedestrian', 'fail turn as directed', 'fail use designated lane', 'fail use sidewalk/ped', 'fail wear safety belt/operator', 'failed to yield - approach/enter intersection', 'failed to yield at a four-way stop-intersection', 'failed to yield to emergency vehicle', 'failed to yield/stop at a yield intersection', 'failure of emergency vehicle to use warning dev', 'failure to move over for emergency vehicle', 'failure to move over/slow down for emg veh', 'failure to obey dl restrictions ordered by court', 'failure to obey restrictions placed on dl', 'failure to slow down for emergency veh/wrecker', 'failure to use due care', 'flee/elude police-aggrav fleeing w injury or damage', 'flee/elude police-fail to obey leo order to stop', 'flee/elude police-flee elude leo at high speed', 'flee/elude police-flee w disregard of safety to pers or prop', 'florida seat belt law violation', 'fnt st pass/ovr 18/seat-belt violation', 'follow fire apparatus to close', 'following to close w/tow/truck', 'following too closely', 'forgery of-alter veh regis sticker certif obscure plate', 'fraud-display handicap park prmt that belongs anoth', 'fraud-imperson-display possess fictitious identification car', 'fraud-imperson-false id given to leo', 'fraud-imperson-non blind person carry white cane', 'fraud-improper temporary tag unlawful use', 'fraud-misuse of temp tag to avoid registr veh', 'fraud-unlawful lending of drivers license', 'fty - vehichle in intersections (all others must yield)', 'fty x/sec inoperative signal', 'fty-violation veh on left yields to veh on right', 'fty/s at sidewalk- alley/bldg/priv rd/dr wy to veh/ped appro', 'fty/s at sidewalk- alley/bldg/priv rd/drive way to veh appr', 'fty/stop at sidewalk from alley/bldg/priv rd/drive way', 'ftyrow enter state highwy', 'ftyrow to highway worker', 'ftyrow to ped at crosswalk with signage', 'ftyrow to ped at intersection with traffic ctrl device', 'ftyrow to ped when no signal', 'ftyrow when turning left', 'ftyrow x/county paved road', 'golfcart improper operation of', 'green arrow veh facing failed to yld row while turning', 'green light veh facing failed to yld row while turning', 'hazardous without comply w federal regulations', 'head lamp violation', 'headlights required / tinted', 'health-safety-tamper with pollution control device subsq off', 'illegal op of nonconform moped', 'imp backing sholder/lm acc fac', 'imp lens on red light', 'imp park one/two way rd/angle', 'imp park/agnst flow/curb 1 way', 'imp start from park/stop posit', 'imp stop on sidewalk', 'imp stop roadway/xsection', 'imp stop un/load pasg limt acs', 'imp sunscrn at top of wndshld', 'imp/no rear stop/lamps', 'improper backing', 'improper center lane use', 'improper change of lane- pull in front of veh same direction', 'improper change of lane-pass when meeting oncoming veh', 'improper horn/warning dev', 'improper left turn', 'improper or unsafe equip / cmv', 'improper parking unincorp area', 'improper parking/two way road', 'improper pass - not specified', 'improper pass on right', 'improper pass oncoming', 'improper pass overtake right', 'improper pass veh proceed opp dir-ea must give half roadway', 'improper pass veh proceeding opposite direction', 'improper pass/lane change', 'improper passing on right', 'improper passing on right - driving of pavement', 'improper right turn', 'improper stop on bike path', 'improper stop on crosswalk', 'improper stop/rr track', 'improper stop/stand/park', 'improper temporary tag unlawful use', 'improper towing', 'improper use hov lane', 'improper/no bike brake', 'inadequate serv/brakes', 'injurious material/road', 'learner dl/operate invalid hrs', 'learners drivers lic viol', 'learners drivers license vio', 'learners drivers license viol', 'leave highway avoid traff dev', 'leave scene of vessel accident or injury', 'leaving scene of any accident', 'license not carried/exhibit', 'license not carried/exhibited', 'litter less 15lb/27 cubic ft', 'litter on private land', 'litter pub hghwy/mot veh', 'load not secure/supports truck', 'loud / harsh horn', 'loud defective muffler', 'manatee protection zones (mpz)', 'maximum bumper heights/none', 'mcycle / no headgear', 'mcycle improper lane use', 'mcycle improper riding', 'mcycle no/defective harsh horn', 'mcycle no/imp rearview mirror', 'mcycle none/improper muffler', 'mcycle oper between lane/veh', 'mcycle pass within occup lane', 'mcycle w/o / imp head lamp', 'mcycle w/o / imp red reflector', 'mcycle w/o / imp stop lamp', 'mcycle w/o / imp tail lamp', 'mcycle w/o eye protection', 'mcycle w/o footrest passg', 'mcycle without multibeam light', 'mcycle/moped head/eye device', 'mcycle/moped imp ride/sitting', 'misrepresentation of insurance', 'misuse dealer or manufacturer license', 'motocycle w/o proper headlight', 'moving traffic viol-drive on permanently revoked driver lice', 'moving traffic viol-reckless drive damage person or property', 'moving traffic viol-reckless driving 1st off', 'mtrcycle/moped: tag improperly affixed  concealed  obscured', 'municipal ordinance viol', 'must have pip ins card', 'neglect child-unattended child in mtr veh excess of 15 mins', 'no brake/turn/signals lighted', 'no head lamps rain/fog/smk/ect', 'no helmet/insurance motorcycle', 'no lamp/flag on projected load', 'no lamps/illuminating devices', 'no safety belts- operator/passg under 18', 'no stop lamp', 'no stop/shift at rr crossing', 'no stoplight/turn ind', 'no tag light', 'no turn signal light', 'no/fail carry physical exam', 'no/improper turn/stop signal given', 'none/def rear view mirror', 'none/improper brakes', 'obstruct traffic', 'obstruct/dig up/distrib road', 'op exh sysm noise/abate modify', 'op veh unsafe/improper equip', 'open container or consumption of alcohol in/on vehicle', 'opening door into traffic', 'oper veh unsafe/improp equip', 'oper veh with headset on', 'operate 1/2 hr after sunset', 'operate against dl restrictions-spec mech control device req', 'operate commmercial vehicle wo valid', 'operate motor vehicle w/o drivers license', 'operate motor vehicle wo valid licens', 'operate motorcycle wo license', 'operate w/illegal sunscreen', 'operating non-cmv not properly insured proof of ins required', 'operating while dl suspended/cancelled/revoked-no prior', 'operation after expiration', 'operator boating safety id card and photo id', 'opn contnr on in/stop/prk veh', 'over height of load', 'overtaking and passing a bicycle (improp distance)', 'overtaking and passing a veh (cutting in)', 'overtaking/passing a veh-fail to give row to overtaking veh', 'parent/guardian allow bike violation', 'park handicapped zone', 'park/obstruct disable pk space', 'park/prohib/by traffic device', 'parked in no park zone', 'pass in no passing zone', 'pass stopped school bus', 'pass veh when yield to pedest', 'passg riding on exterior of vehicle', 'passing in no passing zone', 'passing within 100` of intersct approach', 'passing within 100` of rr crossing approach', 'ped cros rd right angl/shortrt', 'ped cross intersect diagonally', 'ped fail obey traffic sig', 'ped fail to cross in x-walk', 'ped fail to yield to traffic', 'ped failed to yield to emergency veh', 'ped leave place of safety', 'ped/fail obey traf sig/intersc', 'pedestrain obstructing traffic', 'permit unauthorized person to drive', 'permit unlicensed minor to drive', 'poss of open cont in m/v', 'poss of open cont in m/v drive', 'possess counterfeit dl or id', 'possess more than one valid drivers l', 'possess stolen dl or id', 'projecting load on passg veh', 'propelling a moped sidewalk', 'public order crimes-fail to register moped', 'public order crimes-obstruction of public streets wo permit', 'public order crimes-viol nonresident exemption from regis', 'r/r crossing - fail to obey traffic control device', 'r/r crossing- insufficient space to drive completely through', 'ran stop sign', 'rear lamp/reflector color imp', 'rear window nontransparent', 'reckless driving-drives any veh willful disregard for safety', 'reckless operation', 'registration required', 'resist officer-fail to obey police or fire department', 'resist officer-flee elude leo with lights siren active', 'resist officer-refuse to accept sign citation or post bond', 'restrction for wndow behnd drv', 'restricton for wndow behnd drv', 'ride w/o hands on handle bar', 'riding bike with no or improper light', 'riding bike with no/imp light', 'side wind/rest sunscreen', 'skate/coaster/toy on roadway', 'slow bike fail ride right curb', 'slow speed/impede traffic', 'speed to fast cond/special haz', 'speed to fast for cond / curve', 'speed too fast/conditions', 'speed zone violation', 'speed/busn/resid/intrstate/4ln', 'speed/racing on highway', 'speeding/schoolbus res/busn/in', 'splash / spray suppressant dev', 'splash/spray suppressant dev', 'stand in rd/ solict ride/busns', 'stand/park proh/fire hydrant', 'stand/park prohibit by sign', 'stand/parking prohib/driveway', 'stnd/park prohib bike lane', 'sudden stop without signal', 'sunscrn/sign/covering on wndsh', 'tag unsecured/obscured/improper display/defaced/none', 'tail lights none/improper', 'temporary tag - expired 7 days or less', 'texting while driving', 'texting while driving secondary offense', 'to fast for cond narow/wind rd', 'too fast for conditions', 'traffic offense-dui alcohol or drugs', 'traffic offense-dui alcohol or drugs 3rd viol more than 10 y', 'traffic offense-dui alcohol or drugs 3rd viol w/in 10 years', 'traffic offense-dui and damage property', 'traffic offense-participate in unlawful race', 'traffic offense-refuse to submit dui test after lic susp', 'traffic violation/animal', 'transporter license plates', 'turned when unsafe/no signal', 'tv receivers in drivers view', 'two lgtd headlamp/req/m/v', 'two lighted lamps min required', 'u-turn: improper/unsafe/prohibited', 'unauthor/disp/blue/red light', 'under 16/no mcycle/150 cm disp', 'unl/speed in school zone', 'unlaw disp blue lights', 'unlaw number of person on bike', 'unlawful number person on bike', 'unlawful speed posted municip/countyrd', 'unlawful speed posted state/intersct', 'unlawful speed school zone', 'unlawfully operate atv on public road  street/hway', 'unnecessary use of horn', 'unsecured load / truck', 'veh damage road surface', 'veh deprive mcycle of lane', 'veh fail use due care-ped/bike', 'veh w/o lights night', 'vessels: expired vessel registration', 'vessels: no registration certificate', 'viol drivers lic/restriction', 'violate drivers license law', 'violation nonresident requirements for drivers lic', 'violation of navigation rules', 'violation of restricted areas', 'violation of safety equipment regulations', 'violation restricted area', 'walk left side when no sidewlk', 'wearing headset/listening dev', 'windshield violation', 'windshld none/uprght/fixed/gls', 'wrong headlight nbr/loc', 'wrong lane/rotary/one-way']

In [86]:
FIRST = 0
collection_keys = [list(collection.find()[FIRST].keys()) for collection in collections]
for collection_key in collection_keys:
    collection_key.sort()
    logger.debug(collection_key)


['Apartment/Floor', 'Case Number', 'Citation Charge', 'Citation Delivered to Person', 'Court Address', 'Court Code', 'Court Date/Time', 'Court Name', 'Crash', 'Date Occurred', 'Detection Device', 'District Code', 'District Description', 'Driving with Unlawful Blood Alcohol Level', 'Employee Division Code', 'Employee Section Code', 'Employee Shift Code', 'Employee Unit Code', 'Ethnicity Code', 'Neighborhood Code', 'Neighborhood Description', 'Police Agency Code', 'Police Agency Name', 'Race Code', 'Reporting Area Code', 'Reporting Area Desc', 'Residence Code', 'Sex Code', 'Street Direction', 'Street Name', 'Street Number', 'Subdivision Code', 'Subdivision Description', 'Time Entered', 'Tract Description', 'Zone Code', 'Zone Description', '_id', 'age', 'city', 'geox', 'geoy', 'location', 'speed', 'tract', '\ufeffCitation Number']
['1st Harmful Event Code', '1st Harmful Event Description', 'Access Control Code', 'Accident Description', 'Agency Code', 'Ambulance Request Description', 'At Intersection Road Type Code', 'At Intersection Road Type Desc', 'Case Number', 'City', 'Corrected Report', 'County', 'Date/Time Occurred', 'Day of Week', 'Development Type Code', 'Development Type Description', 'Direction From', 'Direction Toward', 'District Code', 'District Description', 'Employee Division', 'Employee Section', 'Employee Shift', 'Employee Unit', 'Feet From', 'Harmful Event Code', 'Hazmat Involved', 'In/Near', 'Injured Taken To Code', 'Injured Taken To Description', 'Intersection', 'Light Condition Code', 'Light Condition Description', 'Locality Code', 'Locality Description', 'Location of Impact Code', 'Location of Impact Description', 'Manner of Collision Code', 'Manner of Collision or Impact', 'Neighborhood Code', 'Neighborhood Description', 'Next Reference Point Code', 'Next Reference Point Descript', 'Non Intersection Road Type Descript', 'Notified by Driver or Law Enforcement', 'Notn Intersection Road Type Code', 'Number of Lanes', 'Number of Units Involved', 'Officer Dept ID', 'Pedestrian Control', 'Private Property', 'Relation to junction', 'Report Area Code', 'Report Area Description', 'Road Character', 'Road Character Description', 'Road Class', 'Road Class Description', 'Road Defects Code', 'Road Defects Description', 'Road Feature Code', 'Road Surface Codes', 'Road Surface Conditions', 'Road Surface Description', 'Road Type Code', 'Road construction', 'School Bus Related', 'Street', 'Subdivision', 'Subdivision Description', 'Supplement Report', 'Taken By Code', 'Time Cleared Scene', 'Time Occured', 'Time Reported', 'Township Code', 'Township Description', 'Tract Code', 'Tract Description', 'Trafficway Flow Code', 'Trafficway Flow Description', 'Visible Code', 'Visible Description', 'Weather Code', 'Weather Description', 'Within Interchange', 'Zone Code', 'Zone Description', '_id', 'dnr', 'fatality', 'geoother', 'geox', 'geoy', 'interramp', 'location', 'other', 'recCount', '\ufeffAccident Number']

In [ ]: