Esempio n. 1
0
    def genPop(self):
        m = float(self.grid.pop.max())

        print(m)

        array = np.empty([700, 700, 3])

        class RenderVisitor(object):
            def __init__(self, array):
                self.array = array

            def visit(self, x, y, p, **kwargs):
                n = float(p)
                n /= m

                if p == 0.0:
                    r = 0.6
                    g = 0.8
                    b = 1.0
                else:
                    r = 0.75 - 0.75 * math.sqrt(math.sqrt(n))
                    g = r * 1.1
                    b = r

                self.array[y, x, 0] = r * 255
                self.array[y, x, 1] = g * 255
                self.array[y, x, 2] = b * 255

        self.grid.pop.visit(RenderVisitor(array))
        img = Image.fromarray(array.astype('uint8'), 'RGB')
        img.save('pop.png')  #
        return bottle.static_file("pop.png", root=os.getcwd())
Esempio n. 2
0
def serve_stats(core_stats_file: str, search_stats_file: str):
    response = ""
    try:
        response = bottle.static_file(merge(os.path.dirname(core_stats_file),
                                            core_stats_file, search_stats_file,
                                            "stats.txt"),
                                      root="/")
    except Exception as e:
        print("serve_stats exception: ", e)
    return response
Esempio n. 3
0
def serve_site(html_dir: str, path: str):
    #if path.find(".js") > 0:
    #    bottle.response.headers['Content-Type'] = 'text/javascript'
    #elif path.find(".css") > 0:
    #    bottle.response.headers['Content-Type'] = 'text/css'
    response = ""
    try:
        response = bottle.static_file(resources.textfile(os.path.join(
            html_dir, path),
                                                         as_string=True),
                                      root="/")
    except Exception as e:
        print("seve_site exception: ", e)
    return response
Esempio n. 4
0
 def getPop(self):
     return bottle.static_file("england_grid/resources/images/pop.png",
                               root=os.getcwd())