Mongo database Docker container with validated and object-document mapped collections

…continued from part 04

Coding the instructions from the docker-container branch on GitHub.


In [1]:
from IPython.core.display import display, HTML
from meta_five import embed

display(HTML(embed))





In [2]:
repo_path = '/tmp/docker-mongo-flpd-hackathon-data/'

In [23]:
!git clone https://github.com/dm-wyncode/docker-mongo-flpd-hackathon-data $repo_path


Cloning into '/tmp/docker-mongo-flpd-hackathon-data'...
remote: Counting objects: 260, done.
remote: Compressing objects: 100% (151/151), done.
remote: Total 260 (delta 72), reused 0 (delta 0), pack-reused 105
Receiving objects: 100% (260/260), 3.80 MiB | 0 bytes/s, done.
Resolving deltas: 100% (127/127), done.
Checking connectivity... done.

In [24]:
!git -C $repo_path checkout docker-container


Branch docker-container set up to track remote branch docker-container from origin.
Switched to a new branch 'docker-container'

In [ ]:
!sudo . $repo_path/docker-run


[sudo] password for dmmmd: 

In [3]:
!python $repo_path/tests/test_*


collection accidents_geojson already exists
collection citations_geojson already exists
collection valid_accidents_geojson already exists
collection valid_citations_geojson already exists
document count for accidents:  13472
document count for citations:  46456
document count for mapped_accidents:  13472
document count for mapped_citations:  45385
document count for valid_accidents:  13472
document count for valid_citations:  45385
document count for accidents_geojson:  0
document count for citations_geojson:  0
document count for valid_accidents_geojson:  0
document count for valid_citations_geojson:  0
some sample keys…
school_bus_related… non_intersection_road_type_descript… number_of_units_involved… supplement_report… road_feature_code… _1st_harmful_event_description… harmful_event_code… road_construction… tract_code… road_character_description
some sample keys…
employee_section_code… court_name… detection_device… employee_division_code… court_address… speed… court_code… street_name… geox… driving_with_unlawful_blood_alcohol_level

In [9]:
from flpd_helper import mapped_citations, mapped_accidents
from pprint import pprint

In [11]:
for collection in (mapped_accidents, mapped_citations, ):
    print(collection.name)
    pprint(collection.find_one())


mapped_accidents
{'_1st_harmful_event_code': '',
 '_1st_harmful_event_description': '',
 '_id': ObjectId('57f13136004f236a9834a6ba'),
 'access_control_code': 1,
 'accident_description': 'COLLISION WITH MOTOR VEH IN TRANSPORT',
 'accident_number': 85830668,
 'agency_code': 'FLPD',
 'ambulance_request_description': '',
 'at_intersection_road_type_code': 'N',
 'at_intersection_road_type_desc': '',
 'case_number': 341504060780,
 'city': 'FORT LAUDERDALE',
 'corrected_report': 'True',
 'county': 'BROWARD',
 'datetime_occurred': datetime.datetime(2015, 4, 15, 16, 43),
 'day_of_week': 'WED',
 'development_type_code': '',
 'development_type_description': '',
 'direction_from': '',
 'direction_toward': '',
 'district_code': '34',
 'district_description': 'FORT LAUDERDALE',
 'dnr': 'False',
 'employee_division': 'PATR',
 'employee_section': 'PATR',
 'employee_shift': 'FL02',
 'employee_unit': 'OPS',
 'fatality': 0,
 'feet_from': '',
 'geoother': '',
 'geox': 26.1221389770508,
 'geoy': -80.1534652709961,
 'harmful_event_code': 14,
 'hazmat_involved': 'False',
 'injured_taken_to_code': '',
 'injured_taken_to_description': '',
 'innear': '',
 'interramp': 'True',
 'intersection': 'NW 9TH AV',
 'light_condition_code': 1,
 'light_condition_description': 'DAYLIGHT',
 'locality_code': '',
 'locality_description': '',
 'location': '(26.1221389770508, -80.1534652709961)',
 'location_of_impact_code': '',
 'location_of_impact_description': '',
 'manner_of_collision_code': 1,
 'manner_of_collision_or_impact': 'FRONT TO REAR',
 'neighborhood_code': '34CC',
 'neighborhood_description': 'DORSEY-RIVERBEND HOA',
 'next_reference_point_code': 'N',
 'next_reference_point_descript': '',
 'non_intersection_road_type_descript': '',
 'notified_by_driver_or_law_enforcement': 2,
 'notn_intersection_road_type_code': 'N',
 'number_of_lanes': 0,
 'number_of_units_involved': 2,
 'officer_dept_id': 6502,
 'other': 'False',
 'pedestrian_control': 'False',
 'private_property': 'False',
 'reccount': 1,
 'relation_to_junction': 'NON-JUNCTION',
 'report_area_code': '34H9',
 'report_area_description': '221',
 'road_character': '',
 'road_character_description': '',
 'road_class': 3,
 'road_class_description': 'STATE',
 'road_construction': 'True',
 'road_defects_code': 1,
 'road_defects_description': '',
 'road_feature_code': 1,
 'road_surface_codes': '',
 'road_surface_conditions': 'DRY',
 'road_surface_description': '',
 'road_type_code': 1,
 'school_bus_related': 'NO',
 'street': 'W BROWARD BLVD',
 'subdivision': '',
 'subdivision_description': '',
 'supplement_report': 'False',
 'taken_by_code': 1,
 'time_cleared_scene': 1626,
 'time_occured': 1520,
 'time_reported': 1522,
 'township_code': '',
 'township_description': '',
 'tract_code': '',
 'tract_description': '',
 'trafficway_flow_code': '',
 'trafficway_flow_description': '',
 'visible_code': '',
 'visible_description': '',
 'weather_code': 1,
 'weather_description': 'CLEAR',
 'within_interchange': 'NO',
 'zone_code': 3440,
 'zone_description': 'FT LAUDERDALE ZONE 40'}
mapped_citations
{'_id': ObjectId('57f13168004f236a9834db5a'),
 'age': 55,
 'apartmentfloor': '',
 'case_number': '',
 'citation_charge': 'FNT ST PASS/OVR 18/SEAT-BELT VIOLATION',
 'citation_delivered_to_person': 1,
 'citation_number': 'A23DH1P',
 'city': 'FORT LAUDERDALE',
 'court_address': '',
 'court_code': 'MAIL',
 'court_datetime': '07/15/2016 12:00:00 AM',
 'court_name': 'SEE MAILER / MUST COMPLY WITHIN 30 DAYS',
 'crash': 'False',
 'date_occurred': datetime.datetime(2016, 6, 14, 0, 0),
 'detection_device': '',
 'district_code': '34',
 'district_description': 'FORT LAUDERDALE',
 'driving_with_unlawful_blood_alcohol_level': 'False',
 'employee_division_code': 'OPSD',
 'employee_section_code': 'TRAF',
 'employee_shift_code': 'FL02',
 'employee_unit_code': 'OPB',
 'ethnicity_code': 'N',
 'geox': 26.1474933624268,
 'geoy': -80.1417388916016,
 'location': '(26.1474933624268, -80.1417388916016)',
 'neighborhood_code': '34BC',
 'neighborhood_description': 'SOUTH MIDDLE RIVER CIVIC ASSOC',
 'police_agency_code': 'FLPD',
 'police_agency_name': 'FORT LAUDERDALE POLICE DEPARTMENT',
 'race_code': 'B',
 'reporting_area_code': '34F4',
 'reporting_area_desc': '212',
 'residence_code': '',
 'sex_code': 'F',
 'speed': 0,
 'street_direction': '',
 'street_name': 'NE 16TH ST',
 'street_number': 300,
 'subdivision_code': '',
 'subdivision_description': '',
 'time_entered': 1029,
 'tract': '',
 'tract_description': '',
 'zone_code': 3450,
 'zone_description': 'FT LAUDERDALE ZONE 50'}

Next up…

  • Building a public API