Пример #1
0
 def test_clustering(self):
     
     generate_clusterable_items()
     from ebgeo.utils.clustering.shortcuts import cluster_all_geoitems
     clusters = cluster_all_geoitems(GeoAbstractModel.objects.\
                                             search_in_area(10,10,15,15), 0)
     self.assertEqual(1, len(clusters))
     clusters2 = cluster_all_geoitems(GeoAbstractModel.objects.\
                                             search_in_area(10,10,15,15), 12)
     self.assertEqual(3, len(clusters2))
Пример #2
0
def get_clusters(request):
    count = request.POST.get("count", 1000)
    offset = request.POST.get("offset", 0)
    zoom_level = request.POST.get("zoom", 2)
    x1 = request.POST.get("x1", False)
    x2 = request.POST.get("x2", False)
    y1 = request.POST.get("y1", False)
    y2 = request.POST.get("y2", False)
    
    
    total_q = GeoAbstractModel.objects.search_in_area(float(x1),
                                                    float(y1),
                                                    float(x2),
                                                    float(y2))
    
    user_id = request.POST.get("user_id", False)
    network = request.POST.get("network", False)
    if user_id:
        total_q = social_query(get_object_or_404(User, pk=user_id), network, total_q)
    
    total_count = total_q.count()
    total = total_q[offset:count]
    
    clusters = cluster_all_geoitems(total, int(zoom_level)+3)
    
    for cluster in clusters:
        pass
        #cluster.set_overlay_html = 
    
    data = {}
    data["type"] = "success"
    data["code"] = 1
    data["clusters"] = [cluster.get_data() for cluster in clusters]
    return HttpResponse(simplejson.dumps(data), status=200,
                        mimetype='application/json')