def deploy(request): data = json.loads(ad.get_most_important_events_json()) locations = [] for location in data: locations.append(location[location.keys()[0]]) #groups = 2 #officers = 100 if request.method == 'GET': groups = int(request.GET.get('groups')) officers = int(request.GET.get('officers')) length = len(locations) locations = assignOfficers(locations, officers, groups) officers_assigned = [] for loc in locations: officers_assigned.append(str(loc['officers'])) if length > len(officers_assigned): for i in range(length - len(officers_assigned)): officers_assigned.append('0') locations_json = json.dumps(locations) context_dict = {'locations_json': locations_json, 'locations': locations, 'officers_numbers': json.dumps(officers_assigned), 'groups': groups, 'officers': officers} return render(request, 'deploy.html', context_dict)
def get_locations(request): if request.method == 'GET': data = json.loads(ad.get_most_important_events_json()) locations = [] for location in data: for l in location: locations.append((float(location[l]['lat']), float(location[l]['long']), 10, str(location[l]['most_common']), str(location[l]['affected']))) locations_json = json.dumps(locations) return HttpResponse(locations_json)