def compose_and_save(key, tile, x, y): # but this has to be done in a transaction - otherwise the different threads will overwrite each other's progress on the shared mapimage mapimage = db.get(key) input_tuples = [(tile.image_out(), x, y, 1.0, images.TOP_LEFT)] if mapimage.img: input_tuples.append((mapimage.img, 0, 0, 1.0, images.TOP_LEFT)) img = images.composite(inputs=input_tuples, width=mapimage.width, height=mapimage.height, color=0, output_encoding=images.PNG) # redraw main image every time to show progress mapimage.img = db.Blob(img) mapimage.tiles_remaining -= 1 mapimage.last_updated = datetime.now() mapimage.put()
assert raw.count('/') == 6, "%d /'s" % raw.count('/') foo, bar, layer, zoom, xy, category, metro = raw.split('/') assert xy.count(',') == 1, "%d /'s" % xy.count(',') x, y = xy.split(',') assert zoom.isdigit() and x.isdigit() and y.isdigit() and category.isdigit() and metro.isdigit(), "not digits" zoom = int(zoom) x = int(x) y = int(y) category = int(category) metro = int(metro) assert 0 <= zoom <= (consts.MAX_ZOOM - 1), "bad zoom: %d" % zoom except AssertionError, err: log.error(err.args[0]) self.respondError(err) return else: self.respondError("Invalid path") return tile = Tile(layer, zoom, x, y, category, metro) log.info("Start-B1: %2.2f" % (time.clock() - st)) self.response.headers['Content-Type'] = "image/png" #log.info("Building image...") img_data = tile.image_out() log.info("Start-B2: %2.2f" % (time.clock() - st)) #log.info("Writing out image...") self.response.out.write(img_data) log.info("Start-End: %2.2f" % (time.clock() - st))
assert xy.count(',') == 1, "%d /'s" % xy.count(',') x, y = xy.split(',') assert zoom.isdigit() and x.isdigit() and y.isdigit( ) and category.isdigit() and metro.isdigit(), "not digits" zoom = int(zoom) x = int(x) y = int(y) category = int(category) metro = int(metro) assert 0 <= zoom <= (consts.MAX_ZOOM - 1), "bad zoom: %d" % zoom except AssertionError, err: log.error(err.args[0]) self.respondError(err) return else: self.respondError("Invalid path") return tile = Tile(layer, zoom, x, y, category, metro) log.info("Start-B1: %2.2f" % (time.clock() - st)) self.response.headers['Content-Type'] = "image/png" #log.info("Building image...") img_data = tile.image_out() log.info("Start-B2: %2.2f" % (time.clock() - st)) #log.info("Writing out image...") self.response.out.write(img_data) log.info("Start-End: %2.2f" % (time.clock() - st))