Example #1
0
def get_study_region_info(request):
    """
    For a given study region id, retrieve
    total population, total grid count and bounding box

    :param sr_id: study region id

    :return: json object containing tot_pop, tot_grid_count, bounding_box
    """
    sr_id = request.GET.get('sr_id')
    if sr_id:
        try:
            sr_id = int(sr_id)
        except ValueError:
            msg = 'Please provide a valid (numeric) study region id'
            response = HttpResponse(msg, status="400")
            return response
    else:
        msg = 'Please provide a study region id (numeric parameter sr_id)'
        response = HttpResponse(msg, status="400")
        return response
    StudyRegionInfoRecord = namedtuple(
        'StudyRegionInfoRecord', 'tot_pop tot_grid_count bounding_box')
    sr_info = []
    for info in map(StudyRegionInfoRecord._make, util._get_study_region_info(
            sr_id)):
        sr_info.append(dict(info._asdict()))
        assert len(sr_info) == 1, ('_get_study_region_info(sr_id) returned '
                                   '%d rows. It should return one') % len(sr_info)
    response_data = json.dumps(sr_info[0])
    response = HttpResponse(response_data, mimetype='text/json')
    return response
Example #2
0
def get_study_region_info(request):
    """
    For a given study region id, retrieve
    total population, total grid count and bounding box

    :param sr_id: study region id

    :return: json object containing tot_pop, tot_grid_count, bounding_box
    """
    sr_id = request.GET.get('sr_id')
    if sr_id:
        try:
            sr_id = int(sr_id)
        except ValueError:
            msg = 'Please provide a valid (numeric) study region id'
            response = HttpResponse(msg, status="400")
            return response
    else:
        msg = 'Please provide a study region id (numeric parameter sr_id)'
        response = HttpResponse(msg, status="400")
        return response
    StudyRegionInfoRecord = namedtuple('StudyRegionInfoRecord',
                                       'tot_pop tot_grid_count bounding_box')
    sr_info = []
    for info in map(StudyRegionInfoRecord._make,
                    util._get_study_region_info(sr_id)):
        sr_info.append(dict(info._asdict()))
        assert len(
            sr_info) == 1, ('_get_study_region_info(sr_id) returned '
                            '%d rows. It should return one') % len(sr_info)
    response_data = json.dumps(sr_info[0])
    response = HttpResponse(response_data, mimetype='text/json')
    return response
Example #3
0
def _tot_grid_count_valid(sr_id):
    StudyRegionInfoRecord = namedtuple("StudyRegionInfoRecord", "tot_pop tot_grid_count bounding_box")
    sr_info = []
    for info in map(StudyRegionInfoRecord._make, util._get_study_region_info(sr_id)):
        sr_info.append(dict(info._asdict()))
        assert len(sr_info) == 1, ("_get_study_region_info(sr_id) returned " "%d rows. It should return one") % len(
            sr_info
        )
    sr_info = sr_info[0]
    if sr_info["tot_grid_count"] > settings.EXPOSURE_MAX_TOT_GRID_COUNT:
        msg = (
            "The export can not be performed because the "
            "total grid count for study region id %s exceeds the "
            "threshold (%s > %s)"
        ) % (sr_id, sr_info["tot_grid_count"], settings.EXPOSURE_MAX_TOT_GRID_COUNT)
        return False, msg
    return True, ""
Example #4
0
def _tot_grid_count_valid(sr_id):
    StudyRegionInfoRecord = namedtuple('StudyRegionInfoRecord',
                                       'tot_pop tot_grid_count bounding_box')
    sr_info = []
    for info in map(StudyRegionInfoRecord._make,
                    util._get_study_region_info(sr_id)):
        sr_info.append(dict(info._asdict()))
        assert len(
            sr_info) == 1, ('_get_study_region_info(sr_id) returned '
                            '%d rows. It should return one') % len(sr_info)
    sr_info = sr_info[0]
    if sr_info['tot_grid_count'] > settings.EXPOSURE_MAX_TOT_GRID_COUNT:
        msg = ('The export can not be performed because the '
               'total grid count for study region id %s exceeds the '
               'threshold (%s > %s)') % (sr_id, sr_info['tot_grid_count'],
                                         settings.EXPOSURE_MAX_TOT_GRID_COUNT)
        return False, msg
    return True, ''