def get(self, request): query_value = request.GET.get('search') filters = request.GET # Search collection collection_results, \ site_results, \ fuzzy_search = GetCollectionAbstract.apply_filter( query_value, filters, ignore_bbox=True) try: collection_ids = list(collection_results.values_list( 'model_pk', flat=True )) records = BiologicalCollectionRecord.objects.filter( pk__in=collection_ids ) serializer = BioCollectionSerializer( records, many=True) return Response(serializer.data) except BiologicalCollectionRecord.DoesNotExist: return HttpResponse( 'Object Does Not Exist', status=status.HTTP_400_BAD_REQUEST )
def get(self, request): try: allowed_taxon = AllowedTaxon() taxon_list = allowed_taxon.get(request.user) records = BiologicalCollectionRecord.objects.filter( validated=False, ready_for_validation=True, taxon_gbif_id__in=taxon_list) paginator = Paginator(records, self.page_limit) page = request.GET.get('page') try: records = paginator.page(page) current_page = int(page) except PageNotAnInteger: records = paginator.page(1) current_page = 1 except EmptyPage: records = paginator.page(paginator.num_pages) current_page = paginator.num_pages serializer = BioCollectionSerializer(records, many=True) response_data = { 'data': serializer.data, 'pagination': { 'current_page': current_page, 'max_page': paginator.num_pages, 'page_limit': self.page_limit } } return Response(response_data) except BiologicalCollectionRecord.DoesNotExist: return HttpResponse('Object Does Not Exist', status=status.HTTP_400_BAD_REQUEST)
def get(self, request): object_pk = request.GET.get('pk', None) try: object = BiologicalCollectionRecord.objects.get(pk=object_pk) serializer = BioCollectionSerializer(object) return Response(serializer.data) except BiologicalCollectionRecord.DoesNotExist: return HttpResponse('Object Does Not Exist', status=status.HTTP_400_BAD_REQUEST)
def clustering_process(self, records, zoom, pix_x, pix_y): """ Iterate records and create point clusters We use a simple method that for every point, that is not within any cluster, calculate it's 'catchment' area and add it to the cluster If a point is within a cluster 'catchment' area increase point count for that cluster and recalculate clusters minimum bbox :param records: list of records. :type records: list :param zoom: zoom level of map :type zoom: int :param pix_x: pixel x of icon :type pix_x: int :param pix_y: pixel y of icon :type pix_y: int """ cluster_points = [] for record in records: # get x,y of site record = record.object x = record.site.geometry_point.x y = record.site.geometry_point.y # check every point in cluster_points for pt in cluster_points: if 'minbbox' not in pt: pt['minbbox'] = pt['bbox'] if within_bbox((x, y), pt['minbbox']): # it's in the cluster 'catchment' area pt['count'] += 1 pt['minbbox'] = update_min_bbox((x, y), pt['minbbox']) break else: # point is not in the catchment area of any cluster x_range, y_range = overlapping_area(zoom, pix_x, pix_y, y) bbox = (x - x_range * 1.5, y - y_range * 1.5, x + x_range * 1.5, y + y_range * 1.5) serializer = BioCollectionSerializer(record) new_cluster = { 'count': 1, 'bbox': bbox, 'coordinates': [x, y], 'record': serializer.data } cluster_points.append(new_cluster) return cluster_points
def get(self, request): filters = request.GET search = CollectionSearch(filters) # Search collection collection_results = search.process_search() try: serializer = BioCollectionSerializer(collection_results, many=True) return Response(serializer.data) except BiologicalCollectionRecord.DoesNotExist: return HttpResponse('Object Does Not Exist', status=status.HTTP_400_BAD_REQUEST)