def _enhanceMarkers(self, markers): now = time.time() for marker in markers: marker["newestHtml"] = self._formatNewestHtml(marker["newest"]) ageDays = localdate.calcAgeDays(marker["newest"][0]["createdDate"], now) shadeIndex = min(ageDays // 4, len(SHADES) - 1) shade = SHADES[shadeIndex] marker["color"] = "%02x%02x%02x" % (shade, shade, shade) del marker["newest"]
def getClustered(self, analyses, zoom, bounds=None): """ Returns analyses clustered inside geo tiles. Returns {(tiledLng,tiledLng):[analysis,analysis,...], ...}. Considers only offers newer than maxAgeDays calculated from the zoom. This limits the number useless of markers on zoomed-out map. """ clusters = {} latInc, lngInc = self._calcTileSize(zoom) if bounds: bounds = gis.extendBounds(bounds) bounds = self._gridizeBounds(bounds, latInc, lngInc) if zoom > 12: # The function could be tweaked at: # http://www.shodor.org/interactivate/activities/DataFlyer/ maxAgeDays = int((1.5*zoom - 18)**2 + 2) else: maxAgeDays = 2 ageDays = None self.count = 0 self.lastDate = None for analysis in analyses: geo = analysis["geo"] if bounds is None or gis.containsLatLng(bounds, geo): if analysis["createdDate"] != self.lastDate: ageDays = localdate.calcAgeDays(analysis["createdDate"]) if ageDays > maxAgeDays and self.count > self.minCount: break self.lastDate = analysis["createdDate"] lat, lng = geo tile = lat // latInc, lng // lngInc self._addToCluster(clusters, tile, analysis) return clusters
def formatAge(strDate, now=None): ageDays = localdate.calcAgeDays(strDate, now) ungettext = _.im_self.ungettext return ungettext(u"%s day", u"%s days", ageDays) % ageDays