예제 #1
0
 def setUp(self):
     from sonofjscompute import models
     self.app = create_app()
     self.client = self.app.test_client()
     models.create_redis(self.app, db=1)
     self.redis = models.redis
     self.addCleanup(self._teardown_redis)
예제 #2
0
def start_mosaic(url='http://25.media.tumblr.com/tumblr_mb50xf8S9c1rgw39go1_500.jpg'):
    response = requests.get(url)
    image = Image.open(StringIO(response.content))
    width, height = image.size
    inputs = []
    for x in range(0, width, RESOLUTION):
        for y in xrange(0, height, RESOLUTION):
            tile = image.crop(box=(x, y, x + RESOLUTION, y + RESOLUTION))
            r = g = b = 0.0
            for pixel in tile.getdata():
                try:
                    r += pixel[0]
                    g += pixel[1]
                    b += pixel[2]
                except IndexError:
                    r += pixel
                    g += pixel
                    b += pixel
            num_pixels = float(len(tile.getdata()))
            r,g,b = r/num_pixels, g/num_pixels, b/num_pixels
            inputs.append(json.dumps({'x':x, 'y':y, 'r':r, 'g':g, 'b':b}))

    models.create_redis(app, db=2)
    shuffle(inputs)
    task = Task.create(name='mosaic', inputs=inputs)
    processes = multiprocessing.cpu_count() or 1
    pool = multiprocessing.Pool(processes)
    pool.map(_work_mosaic, [task] * processes)
예제 #3
0
def create_app():
    static_path = path.join(path.dirname(__file__), '../static')
    app = Flask(__name__, static_folder=static_path)
    app.config.from_object('sonofjscompute.config')

    create_redis(app, db=2)
    sockets = Sockets(app)

    app.register_blueprint(tasks, url_prefix='/tasks')

    return app