Example #1
0
def increase_coverage(upto=5000):
    """Save `upto` unprocessed San Francisco tags"""
    from more_query import get_top_tags
    sup = persistent.load_var('supported')
    more = get_top_tags(upto, 'nsf_tag.dat')
    already = [v[0] for v in sup]
    addition = set(more).difference(set(already))
    persistent.save_var('addition', addition)
Example #2
0
#! /usr/bin/python2
# vim: set fileencoding=utf-8
import more_query as mq

if __name__ == '__main__':
    sf = mq.get_top_tags(300)
    us = mq.get_top_tags(300, 'us_tags.dat')
    ca = mq.get_top_tags(300, 'ca_tags.dat')
    sfca = [s for s in sf if s in ca]
    sfus = [s for s in sf if s in us]
    sfusca = [s for s in sfca if s in us]
Example #3
0
    import matplotlib.colors as colors
    matplotlib.use('PDF')
    import matplotlib.pyplot as plt
    plt.figure(dpi=200)

    H = read_entropy()
    colormap_ = cm.ScalarMappable(
        colors.Normalize(min(H.values()), max(H.values())), 'Blues')
    font0 = FontProperties()
    pos = {'horizontalalignment': 'center', 'verticalalignment': 'center'}
    font0.set_size(1.4)
    for w, c in zip(words, coords):
        plt.plot(c[0], c[1], '.', ms=5, c=to_css_hex(colormap_.to_rgba(H[w])))
        if label:
            plt.text(c[0],
                     c[1],
                     w,
                     fontproperties=font0,
                     rotation=randint(-28, 28),
                     **pos)
    plt.axis('off')
    plt.savefig('red.pdf', format='pdf', transparent=True)


if __name__ == '__main__':
    import more_query as mq
    data = mq.sio.loadmat('MDS1.mat')['A']
    words = mq.get_top_tags(mq.np.size(data, 0), 'nsf_tag.dat')
    coords = [(p[0], p[1]) for p in data]
    tag_cloud(words, coords, True)
Example #4
0
    bx, by, tx, ty = [float(v) for v in request.POST.getlist('coords[]')]
    long_step = (bbox[3] - bbox[1]) / k
    lat_step = (bbox[2] - bbox[0]) / k
    x0 = bbox[1]
    y0 = bbox[0]
    bx, tx = (bx, tx) if tx > bx else (tx, bx)
    by, ty = (by, ty) if ty > by else (ty, by)
    return '\n'.join([
        u'{}: {:.4f}'.format(t, float(v)) for t, v in get_best_tags(
            box(x0 + bx * long_step, y0 + by * lat_step, x0 +
                tx * long_step, y0 + ty * lat_step))
    ])
    # for t, v in get_best_tags(Point(x0+x*long_step,
    #                                 y0+y*lat_step))])


@post('/cover')
def cover():
    n = int(request.POST.get('n'))
    w = int(request.POST.get('w'))
    h = int(request.POST.get('h'))
    overlap = request.POST.get('overlap') == 'true'
    return js_some(d, n, w, h, overlap=overlap)


t = persistent.load_var('disc/all')
top = get_top_tags(500, 'nsf_tag.dat')
supported = [v[0] for v in persistent.load_var('supported')][:600]
d = top_discrepancy(t, supported)
run(host='localhost', port=8080, debug=True, reloader=True)
Example #5
0
    from matplotlib.font_manager import FontProperties
    import matplotlib
    import matplotlib.cm as cm
    import matplotlib.colors as colors

    matplotlib.use("PDF")
    import matplotlib.pyplot as plt

    plt.figure(dpi=200)

    H = read_entropy()
    colormap_ = cm.ScalarMappable(colors.Normalize(min(H.values()), max(H.values())), "Blues")
    font0 = FontProperties()
    pos = {"horizontalalignment": "center", "verticalalignment": "center"}
    font0.set_size(1.4)
    for w, c in zip(words, coords):
        plt.plot(c[0], c[1], ".", ms=5, c=to_css_hex(colormap_.to_rgba(H[w])))
        if label:
            plt.text(c[0], c[1], w, fontproperties=font0, rotation=randint(-28, 28), **pos)
    plt.axis("off")
    plt.savefig("red.pdf", format="pdf", transparent=True)


if __name__ == "__main__":
    import more_query as mq

    data = mq.sio.loadmat("MDS1.mat")["A"]
    words = mq.get_top_tags(mq.np.size(data, 0), "nsf_tag.dat")
    coords = [(p[0], p[1]) for p in data]
    tag_cloud(words, coords, True)
Example #6
0
    # y =  float(request.POST.get('y'))
    bx, by, tx, ty = [float(v) for v in request.POST.getlist('coords[]')]
    long_step = (bbox[3] - bbox[1])/k
    lat_step = (bbox[2] - bbox[0])/k
    x0 = bbox[1]
    y0 = bbox[0]
    bx, tx = (bx, tx) if tx > bx else (tx, bx)
    by, ty = (by, ty) if ty > by else (ty, by)
    return '\n'.join([u'{}: {:.4f}'.format(t, float(v))
                      for t, v in get_best_tags(box(x0+bx*long_step,
                                                    y0+by*lat_step,
                                                    x0+tx*long_step,
                                                    y0+ty*lat_step))])
                      # for t, v in get_best_tags(Point(x0+x*long_step,
                      #                                 y0+y*lat_step))])


@post('/cover')
def cover():
    n = int(request.POST.get('n'))
    w = int(request.POST.get('w'))
    h = int(request.POST.get('h'))
    overlap = request.POST.get('overlap') == 'true'
    return js_some(d, n, w, h, overlap=overlap)

t = persistent.load_var('disc/all')
top = get_top_tags(500, 'nsf_tag.dat')
supported = [v[0] for v in persistent.load_var('supported')][:600]
d = top_discrepancy(t, supported)
run(host='localhost', port=8080, debug=True, reloader=True)