Example #1
0
def cluster_newsitems(qs, radius=26):
    """
    A convenience function for clustering a newsitem queryset.
    """
    return clustering.cluster_scales(
        dict([(ni.id, (ni.location.centroid.x, ni.location.centroid.y))
              for ni in qs if ni.location]),
        radius)
Example #2
0

def timeit(label, f, *args, **kwargs):
    import time, sys
    start = time.time()
    ret_val = f(*args, **kwargs)
    print >> sys.stderr, "%s took %.4f seconds" % (label, time.time() - start)
    return ret_val


def randomize(L):
    import copy, random
    Lprime = copy.copy(L)
    random.shuffle(Lprime)
    return Lprime


def main():
    buffer = 20
    objs = gen_test_objs(rand_seed="foo")
    bunches = timeit("cluster", cluster.buffer_cluster, objs, buffer)
    display(bunches, buffer=buffer, f=print_bunches)


if __name__ == "__main__":
    #main()
    #for bunch in cluster_by_scale(sample.sample_pts, 51, 19200):
    #print "%3d: (%.4f, %.4f)" % (len(bunch.objects), bunch.x, bunch.y)
    from django.utils.simplejson import dumps
    print dumps(cluster_scales(sample.sample_pts, 26), cls=json.ClusterJSON)
Example #3
0
    pylab.show()

def display(bunches, buffer, f=plot_bunches):
    f(bunches, buffer)

def timeit(label, f, *args, **kwargs):
    import time, sys
    start = time.time()
    ret_val = f(*args, **kwargs)
    print >> sys.stderr, "%s took %.4f seconds" % (label, time.time()-start)
    return ret_val

def randomize(L):
    import copy, random
    Lprime = copy.copy(L)
    random.shuffle(Lprime)
    return Lprime

def main():
    buffer = 20
    objs = gen_test_objs(rand_seed="foo")
    bunches = timeit("cluster", cluster.buffer_cluster, objs, buffer)
    display(bunches, buffer=buffer, f=print_bunches)

if __name__ == "__main__":
    #main()
    #for bunch in cluster_by_scale(sample.sample_pts, 51, 19200):
        #print "%3d: (%.4f, %.4f)" % (len(bunch.objects), bunch.x, bunch.y)
    from django.utils.simplejson import dumps
    print dumps(cluster_scales(sample.sample_pts, 26), cls=json.ClusterJSON)