def compute_connections(incidents, incident_filter=(lambda i: True), min_checkins = MIN_CHECKINS): counts_by_unit = fire.count_checkins_by(incidents) good_units = set([u for (u,c) in counts_by_unit.iteritems() if c >= min_checkins]) # compute connections connections = { u: defaultdict(int) for u in good_units } for i in incidents: if incident_filter(i): gus = [u for u in i['units'] if u in good_units] for u1 in gus: for u2 in gus: if u1 != u2: connections[u1][u2] += 1 return connections, counts_by_unit
locations, type_re='(?i)(fire$|fire [^a])', resize_by=(lambda x: x)) # assaults plot_incidents(incidents, locations, type_re='(?i)(assault)', resize_by=(lambda x: x)) # average centroid of solo checkins for E trucks CUTOFF = 100 counts_by_unit = fire.count_checkins_by(incidents) good_units = set([u for (u,c) in counts_by_unit.iteritems() if c >= CUTOFF]) locs_by_unit = {u : [] for u in good_units} for i in incidents: if len(i["units"]) <= 1: loc = i["location"] if loc in locations and locations[loc]: lat,lng = locations[loc] for u in i['units']: if u in good_units: locs_by_unit[u].append((lat,lng))
plot_incidents(incidents, locations, type_re='(?i)(fire$|fire [^a])', resize_by=(lambda x: x)) # assaults plot_incidents(incidents, locations, type_re='(?i)(assault)', resize_by=(lambda x: x)) # average centroid of solo checkins for E trucks CUTOFF = 100 counts_by_unit = fire.count_checkins_by(incidents) good_units = set([u for (u, c) in counts_by_unit.iteritems() if c >= CUTOFF]) locs_by_unit = {u: [] for u in good_units} for i in incidents: if len(i["units"]) <= 1: loc = i["location"] if loc in locations and locations[loc]: lat, lng = locations[loc] for u in i['units']: if u in good_units: locs_by_unit[u].append((lat, lng)) def median(lst):