def insert(self, data) : print "%s %s (cc=%d)" % ("Inserting", data['_id'], self.cur_checks) entity = dict() for field in data.keys() : entity[field] = data.get(field) entity['_id'] = int(entity['_id']) try : resolved = entity['resolved'] == 'True' entity['resolved'] = resolved if not resolved: entity['magic-num'] = int(entity['magic-num']) issueTime = entity['issueDate'] + " " + entity['time'] entity['issueTime'] = datetime.strptime(issueTime, "%m/%d/%Y %I:%M%p") except KeyError : entity['missing'] = entity['missing'] == 'True' except ValueError : entity['issueTime'] = False entity['resolved'] = True self.db.ticket.save(entity) try : nice = fetch.make_nice(entity['location']) if self.db.location.find({'text':nice}).count() == 0 : self.db.location.save({'text':nice, 'checked':False}) except KeyError : pass
lon_min = -75.291367 #sorted(lons)[10] #left lon_max = -74.95491 #sorted(lons)[-1] #right m = Basemap( projection = 'merc', llcrnrlat=lat_min, urcrnrlat=lat_max, llcrnrlon=lon_min, urcrnrlon=lon_max, rsphere=6371200, resolution='l', area_thresh=10000 ) subplot(111, axisbg='black') for loc in db.ticket.find({'resolved':False}): next_one = db.ticket.find_one({'_id': loc['_id'] + 1}) if next_one != None and (not next_one.get('resolved',True) or not next_one.get('missing',True)): try : diff = next_one['issueTime'] - loc['issueTime'] if diff == 0 or diff < timedelta(minutes=30): try : ll1 = db.location.find_one({'text':fetch.make_nice(loc['location'])})['location'] ll2 = db.location.find_one({'text':fetch.make_nice(next_one['location'])})['location'] x,y = m([ll1['lng'],ll2['lng']], [ll1['lat'],ll2['lat']]) m.plot(x,y,',w-', linewidth=.2, alpha=.3) except : pass # Geocoding missing, or placeholder except : print next_one, loc fig = matplotlib.pyplot.gcf() fig.set_size_inches(18.5,10.5) plt.savefig('figures/myfig.png', facecolor='black', dpi=300, bbox_inches='tight', pad_inches=0, alpha=1)
hue = i/360. lightness = np.random.rand() if lightness < .25 : lightness += .25 saturation = np.random.rand() colors.append(colorsys.hls_to_rgb(hue, lightness, saturation)) return colors db = MongoClient().ppa lats = [] lons = [] agents = {} for loc in db.ticket.find({'issueDate':'01/31/2013'}): ll = db.location.find_one({'text':fetch.make_nice(loc['location'])}) #lats.append(ll['location']['lat']) #lons.append(ll['location']['lng']) _id = int(loc['_id']) uniq = _id - (_id % 200) if uniq not in agents : agents[uniq] = {'lats':[],'lons':[]} agents[uniq]['lats'].append(ll['location']['lat']) agents[uniq]['lons'].append(ll['location']['lng']) lat_min = 39.859682 # sorted(lats)[0] #bottom lat_max = 40.14319 #sorted(lats)[-4] #top lon_min = -75.291367 #sorted(lons)[10] #left lon_max = -74.95491 #sorted(lons)[-1] #right spatial_resolution = 0.5