def category_in_service_area(self, category=Category.objects.get(slug='physical-activity'), location_objects=Location.objects.all(), service_area='health_integration_authority'): print("Setting up area mappings") service_area_mappings = setup_data_set_doubles() boundary = service_area_mappings[service_area] print("Checking for " + service_area + " boundary") service_area_distributions = self.locations_in_service_area(location_objects, boundary) #print("Checking for " + service_area + " boundary") for service_area_name, location_ids in service_area_distributions.items(): if (service_area_name == 'Unmatched'): print("Unmatched IDs: ") for unmatched_location_id in location_ids: print(" ", unmatched_location_id) print("\n"+ service_area_name) services = Service.objects.filter(locations__in=location_ids).distinct() filtered_services = category.filter_by_family(services).distinct() print(" ", category.name+ ":", str(filtered_services.count())) exact_parent_matches = services.filter(categories__name=category) if exact_parent_matches.count() > 0: print(" ", "Specific tags:", str(exact_parent_matches.count())) for c in category.all_children: filtered_services = c.filter_by_family(services) print(" ",str(filtered_services.count()), "categorised as", c.name) if filtered_services.count() > 0: exact_matches = services.filter(categories__name=c.name).distinct() if exact_matches.count() > 0: print(" ", "Specific Tags: " + str(exact_matches.count()))
def handle(self, *args, **options): self.stdout.write("\nGenerating Report\n") self.stderr.write(self.style.SUCCESS('Checking service urls')) print(options) self.verbose = options['verbose'] print("\n---------- Categories in Service Area -----------") self.category_in_service_area() print("\n---------- Location IDs in Regions -----------") location_objects = Location.objects.all() boundaries_data_mappings = setup_data_set_doubles() self.locations_in_boundaries(location_objects, boundaries_data_mappings) print("\n # Geographical Content Report") self.geographical_content_report()
def services_by_location_match_in_service_area(self, service_area_boundary, type): services_by_service_area_region_location_match = {} service_area_regions = [] service_areas_of_type = ServiceArea.objects.filter(type=type) for service_area_region in service_areas_of_type: service_area_regions.append(service_area_region.name) locations_of_services = Location.objects.all() service_area_mappings = setup_data_set_doubles() boundary = service_area_mappings[service_area_boundary] service_area_distributions = self.locations_in_service_area(locations_of_services, boundary) for key, value in service_area_distributions.items(): if key in service_area_regions: services_by_service_area_region_location_match[key] = Service.objects.filter(locations__in=value, organisation__published=True).distinct() return services_by_service_area_region_location_match