Exemple #1
0
 def GET(self):
     if session.user.name == "Anonymous":
         raise web.seeother("/")
     yays = model.get_reviews(writer=session.user.name, happy=True)
     nays = model.get_reviews(writer=session.user.name, happy=False)
     favs = model.get_reviews(writer=session.user.name, favourite=True)
     return render.dashboard(session.user.name, yays, nays, favs)
Exemple #2
0
 def GET(self):
     if session.user.name == "Anonymous":
         raise web.seeother("/")
     yays = model.get_reviews(writer=session.user.name, happy=True)
     nays = model.get_reviews(writer=session.user.name, happy=False)
     favs = model.get_reviews(writer=session.user.name, favourite=True)
     return render.dashboard(session.user.name, yays, nays, favs)
Exemple #3
0
    def GET(self, zoom, x, y):
        cache_file = "cache/%s-%s-%s.png" % (zoom, x, y)

        if os.path.exists(cache_file):
            return file(cache_file).read()

        (lat0, lon0) = num2deg(int(x)-1, int(y)+2, int(zoom))
        (lat1, lon1) = num2deg(int(x),   int(y)+2, int(zoom))
        (lat2, lon2) = num2deg(int(x)+1, int(y),   int(zoom))
        (lat3, lon3) = num2deg(int(x)+2, int(y)-1, int(zoom))
        (latd, lond) = (abs(lat1-lat2), abs(lon1-lon2))

        rs = list(model.get_reviews(bbox=[
            lon0, lat0,
            lon3, lat3
        ]))

        im = Image.new('RGBA', (256, 256))
        pix = im.load()

        logging.info("Generating tile based on %d reviews" % len(rs))
        if rs:
            for x in range(0, 256):
                for y in range(0, 256):
                    lat = lat1 + latd * float(256-y)/256
                    lon = lon1 + lond * float(x)/256
                    goodness = 0
                    badness = 0
                    for r in rs:
                        d = math.sqrt(math.pow((lat-r.lat)/latd, 2) + math.pow((lon-r.lon)/lond, 2))
                        if d < 1:
                            if r.happy:
                                goodness = goodness + (1-d)
                            else:
                                badness = badness + (1-d)
                            #if r.happy:
                            #    goodness = goodness + (0.001 - d) * 1000
                            #else:
                            #    badness = badness + (0.001 - d) * 1000
                    good_hue = 2.0/6
                    bad_hue = 0.0/6
                    mid = (good_hue + bad_hue) / 2
                    if goodness - badness == 0:
                        hue = mid
                        alp = 0
                    else:
                        ratio = (goodness - badness) / (goodness + badness)
                        hue = mid + mid * ratio
                        alp = 63 * clamp(0, max(goodness, badness)/2, 1)
                    sat = 1
                    val = 1
                    (r, g, b) = colorsys.hsv_to_rgb(hue, sat, val)
                    pix[x, y] = (int(r*256), int(g*256), int(b*256), int(alp))

        buf = StringIO.StringIO()
        im.save(buf, format= 'PNG')

        file(cache_file, "w").write(buf.getvalue())

        return buf.getvalue()
Exemple #4
0
    def GET(self, zoom, x, y):
        cache_file = "cache/%s-%s-%s.png" % (zoom, x, y)

        if os.path.exists(cache_file):
            return file(cache_file).read()

        (lat0, lon0) = num2deg(int(x) - 1, int(y) + 2, int(zoom))
        (lat1, lon1) = num2deg(int(x), int(y) + 2, int(zoom))
        (lat2, lon2) = num2deg(int(x) + 1, int(y), int(zoom))
        (lat3, lon3) = num2deg(int(x) + 2, int(y) - 1, int(zoom))
        (latd, lond) = (abs(lat1 - lat2), abs(lon1 - lon2))

        rs = list(model.get_reviews(bbox=[lon0, lat0, lon3, lat3]))

        im = Image.new('RGBA', (256, 256))
        pix = im.load()

        logging.info("Generating tile based on %d reviews" % len(rs))
        if rs:
            for x in range(0, 256):
                for y in range(0, 256):
                    lat = lat1 + latd * float(256 - y) / 256
                    lon = lon1 + lond * float(x) / 256
                    goodness = 0
                    badness = 0
                    for r in rs:
                        d = math.sqrt(
                            math.pow((lat - r.lat) / latd, 2) +
                            math.pow((lon - r.lon) / lond, 2))
                        if d < 1:
                            if r.happy:
                                goodness = goodness + (1 - d)
                            else:
                                badness = badness + (1 - d)
                            #if r.happy:
                            #    goodness = goodness + (0.001 - d) * 1000
                            #else:
                            #    badness = badness + (0.001 - d) * 1000
                    good_hue = 2.0 / 6
                    bad_hue = 0.0 / 6
                    mid = (good_hue + bad_hue) / 2
                    if goodness - badness == 0:
                        hue = mid
                        alp = 0
                    else:
                        ratio = (goodness - badness) / (goodness + badness)
                        hue = mid + mid * ratio
                        alp = 63 * clamp(0, max(goodness, badness) / 2, 1)
                    sat = 1
                    val = 1
                    (r, g, b) = colorsys.hsv_to_rgb(hue, sat, val)
                    pix[x, y] = (int(r * 256), int(g * 256), int(b * 256),
                                 int(alp))

        buf = StringIO.StringIO()
        im.save(buf, format='PNG')

        file(cache_file, "w").write(buf.getvalue())

        return buf.getvalue()
Exemple #5
0
def review():
    name = request.args.get('name', default="", type=str)
    reviews = model.get_reviews(name)
    processed_reviews = []
    for ii in reviews:
        if ii != None:
            processed_reviews.append(ii)
    return render_template("review.html",
                           title="Review for {}".format(name),
                           review=processed_reviews)
Exemple #6
0
    def GET(self, id=None):
        if id == "new":
            import time
            i = web.input(lat="0", lon="0", id="r" + str(time.time()))
            if web.ctx.host.startswith("m."):
                return render_mobile.new_review(i.id, i.lat, i.lon)
            else:
                return render_bare.new_review(i.id, i.lat, i.lon)
        if id == None:
            if web.ctx.host.startswith("m."):
                i = web.input(lon=None, lat=None)
                rs = model.get_reviews_point(i.lon, i.lat)
                return render_mobile.reviews(rs, float(i.lon), float(i.lat))

            i = web.input(bbox="0,0,0,0", filter=None)

            if i.filter == "my":
                writer = session.user.name
                notwriter = None
            elif i.filter == "notme":
                writer = None
                notwriter = session.user.name
            elif i.filter == "notanon":
                writer = None
                notwriter = "Anonymous"
            else:
                writer = None
                notwriter = None

            bbox = [float(n) for n in i.bbox.split(",")]
            rs = model.get_reviews(bbox=bbox,
                                   writer=writer,
                                   notwriter=notwriter)
            return json.dumps({
                "status": "ok",
                "message": None,
                "data": [Review(r).dict() for r in rs]
            })
Exemple #7
0
    def GET(self, id=None):
        if id == "new":
            import time
            i = web.input(lat="0", lon="0", id="r"+str(time.time()))
            if web.ctx.host.startswith("m."):
                return render_mobile.new_review(i.id, i.lat, i.lon)
            else:
                return render_bare.new_review(i.id, i.lat, i.lon)
        if id == None:
            if web.ctx.host.startswith("m."):
                i = web.input(lon=None, lat=None)
                rs = model.get_reviews_point(i.lon, i.lat)
                return render_mobile.reviews(rs, float(i.lon), float(i.lat))

            i = web.input(bbox="0,0,0,0", filter=None)

            if i.filter == "my":
                writer = session.user.name
                notwriter = None
            elif i.filter == "notme":
                writer = None
                notwriter = session.user.name
            elif i.filter == "notanon":
                writer = None
                notwriter = "Anonymous"
            else:
                writer = None
                notwriter = None

            bbox = [float(n) for n in i.bbox.split(",")]
            rs = model.get_reviews(bbox=bbox, writer=writer, notwriter=notwriter)
            return json.dumps({
                "status": "ok",
                "message": None,
                "data": [Review(r).dict() for r in rs]
            })
Exemple #8
0
 def GET(self, name="Anonymous"):
     yays = model.get_reviews(writer=name, happy=True)
     nays = model.get_reviews(writer=name, happy=False)
     favs = model.get_reviews(writer=name, favourite=True)
     return render.dashboard(name, yays, nays, favs)
Exemple #9
0
 def GET(self, id):
     """ View single movie """
     movie = model.get_movie(int(id))
     reviews = model.get_reviews(int(id))
     form = Review.form()
     return render.view(movie, form, reviews)
Exemple #10
0
 def GET(self, name="Anonymous"):
     yays = model.get_reviews(writer=name, happy=True)
     nays = model.get_reviews(writer=name, happy=False)
     favs = model.get_reviews(writer=name, favourite=True)
     return render.dashboard(name, yays, nays, favs)