コード例 #1
0
ファイル: views.py プロジェクト: DarthDippy/mapusaurus
def loan_originations(request):
    """Get loan originations for a given lender, county combination. This
    ignores year for the moment."""
    lender_id = request.GET.get('lender')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    geoids = get_censustract_geoids(request)
    action_taken = action_taken_param.split(',')
    if lender_hierarchy == 'true':
        lenders = get_related_lenders(lender_id)
        if len(lenders[0]) == 0:
            return HttpResponseRequest("No other lenders found in hierarchy. Invalid lender")
        if geoids and lenders and action_taken:
            query = HMDARecord.objects.filter(
                # actions 7-8 are preapprovals to ignore
                property_type__in=[1,2], owner_occupancy=1, lien_status=1,
                lender__in=lenders[0], action_taken__in=action_taken
            ).filter(geoid_id__in=geoids).values(
                'geoid', 'geoid__census2010households__total'
            ).annotate(volume=Count('geoid'))
            return query
    elif lender_hierarchy == 'false' and geoids and lender_id and action_taken:
        query = HMDARecord.objects.filter(
            # actions 7-8 are preapprovals to ignore
            property_type__in=[1,2], owner_occupancy=1, lien_status=1,
            lender=lender_id, action_taken__in=action_taken
        ).filter(geoid_id__in=geoids).values(
            'geoid', 'geoid__census2010households__total'
        ).annotate(volume=Count('geoid'))
        return query
    else:
        return HttpResponseBadRequest("Missing one of lender, action_taken and county or geoid.")
コード例 #2
0
def race_summary(request):
    """Race summary statistics"""
    geoids = get_censustract_geoids(request)
    if geoids:
        query = Census2010RaceStats.objects.filter(geoid_id__in=geoids)
        return query
    else:
        return HttpResponseBadRequest("Missing geoid or county")
コード例 #3
0
ファイル: views.py プロジェクト: DarthDippy/mapusaurus
def race_summary(request):
    """Race summary statistics"""
    geoids = get_censustract_geoids(request)
    if geoids:
        query = Census2010RaceStats.objects.filter(geoid_id__in=geoids)
        return query
    else:
        return HttpResponseBadRequest("Missing geoid or county")
コード例 #4
0
def loan_originations(request):
    institution_id = request.GET.get('lender')
    metro = request.GET.get('metro')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    peers = request.GET.get('peers')
    geoids = get_censustract_geoids(request)
    institution_selected = Institution.objects.get(pk=institution_id)
    metro_selected = Geo.objects.filter(geo_type=Geo.METRO_TYPE,
                                        geoid=metro).first()
    if action_taken_param:
        action_taken_selected = [
            param for param in action_taken_param.split(',')
        ]
    else:
        action_taken_selected = []
    if geoids and action_taken_selected:
        query = HMDARecord.objects.filter(
            property_type__in=[1, 2],
            owner_occupancy=1,
            lien_status=1,
            action_taken__in=action_taken_selected,
            geo_id__in=geoids)
        if lender_hierarchy == 'true':
            hierarchy_list = LenderHierarchy.objects.filter(
                organization_id=institution_selected.lenderhierarchy_set.get(
                ).organization_id)
            if len(hierarchy_list) > 0:
                query = query.filter(institution__in=[
                    item.institution for item in hierarchy_list
                ])
            else:
                query = query.filter(institution=institution_selected)
        elif peers == 'true':
            peer_list = get_peer_list(institution_selected, metro_selected)
            if len(peer_list) > 0:
                query = query.filter(
                    institution__in=[item.institution for item in peer_list])
            else:
                query = query.filter(institution=institution_selected)
        else:
            query = query.filter(institution=institution_selected)
    elif geoids:
        query = HMDARecord.objects.filter(property_type__in=[1, 2],
                                          owner_occupancy=1,
                                          lien_status=1,
                                          geo__geoid__in=geoids,
                                          institution=institution_selected)
    else:
        return HttpResponseBadRequest("Missing geoid.")
    query = query.values(
        'geo_id',
        'geo__census2010households__total').annotate(volume=Count('geo_id'))
    return query
コード例 #5
0
ファイル: views.py プロジェクト: sephcoster/mapusaurus
def race_summary(request):
    """Race summary statistics"""
    northEastLat = request.GET.get('neLat')
    northEastLon = request.GET.get('neLon', [])
    southWestLat = request.GET.get('swLat', [])
    southWestLon = request.GET.get('swLon', [])

    geoids = get_censustract_geoids(request, northEastLat, northEastLon, southWestLat, southWestLon)
    if geoids:
        query = Census2010RaceStats.objects.filter(geoid_id__in=geoids)
        return query
    else:
        return HttpResponseBadRequest("Missing geoid or county")
コード例 #6
0
ファイル: views.py プロジェクト: grapesmoker/mapusaurus
def loan_originations(request):
    institution_id = request.GET.get('lender')
    metro = request.GET.get('metro')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    peers = request.GET.get('peers')
    geoids = get_censustract_geoids(request)
    institution_selected = Institution.objects.filter(
        pk=institution_id).first()
    metro_selected = Geo.objects.filter(geo_type=Geo.METRO_TYPE,
                                        geoid=metro).first()
    action_taken_selected = action_taken_param.split(',')
    if geoids and action_taken_selected:
        query = HMDARecord.objects.filter(
            property_type__in=[1, 2],
            owner_occupancy=1,
            lien_status=1,
            action_taken__in=action_taken_selected)
        if lender_hierarchy == 'true':
            hierarchy_list = institution_selected.get_lender_hierarchy(
                False, False)
            if len(hierarchy_list) > 0:
                query = query.filter(institution__in=hierarchy_list)
            else:
                query = query.filter(institution__in=institution_selected)
        elif peers == 'true':
            peer_list = institution_selected.get_peer_list(
                metro_selected, False, False)
            if len(peer_list) > 0:
                query = query.filter(institution__in=peer_list)
            else:
                query = query.filter(institution=institution_selected)
        else:
            query = query.filter(institution=institution_selected)
        query = query.filter(geo__geoid__in=geoids)
    else:
        return HttpResponseBadRequest(
            "Missing one of lender, action_taken, lat/lon bounds or geoid.")
    query = query.values('geo__geoid',
                         'geo__census2010households__total').annotate(
                             volume=Count('geo__geoid'))
    return query
コード例 #7
0
ファイル: views.py プロジェクト: DarthDippy/mapusaurus
def loan_originations(request):
    """Get loan originations for a given lender, county combination. This
    ignores year for the moment."""
    lender_id = request.GET.get('lender')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    geoids = get_censustract_geoids(request)
    action_taken = action_taken_param.split(',')
    if lender_hierarchy == 'true':
        lenders = get_related_lenders(lender_id)
        if len(lenders[0]) == 0:
            return HttpResponseRequest(
                "No other lenders found in hierarchy. Invalid lender")
        if geoids and lenders and action_taken:
            query = HMDARecord.objects.filter(
                # actions 7-8 are preapprovals to ignore
                property_type__in=[1, 2],
                owner_occupancy=1,
                lien_status=1,
                lender__in=lenders[0],
                action_taken__in=action_taken).filter(
                    geoid_id__in=geoids).values(
                        'geoid',
                        'geoid__census2010households__total').annotate(
                            volume=Count('geoid'))
            return query
    elif lender_hierarchy == 'false' and geoids and lender_id and action_taken:
        query = HMDARecord.objects.filter(
            # actions 7-8 are preapprovals to ignore
            property_type__in=[1, 2],
            owner_occupancy=1,
            lien_status=1,
            lender=lender_id,
            action_taken__in=action_taken).filter(geoid_id__in=geoids).values(
                'geoid', 'geoid__census2010households__total').annotate(
                    volume=Count('geoid'))
        return query
    else:
        return HttpResponseBadRequest(
            "Missing one of lender, action_taken and county or geoid.")
コード例 #8
0
ファイル: views.py プロジェクト: sephcoster/mapusaurus
def loan_originations(request):
    """Get loan originations for a given lender, county combination. This
    ignores year for the moment."""
    northEastLat = request.GET.get('neLat')
    northEastLon = request.GET.get('neLon', [])
    southWestLat = request.GET.get('swLat', [])
    southWestLon = request.GET.get('swLon', [])

    geoids = get_censustract_geoids(request, northEastLat, northEastLon, southWestLat, southWestLon)
 
    lender = request.GET.get('lender', [])
    action_taken_param = request.GET.get('action_taken', [])
    action_taken = action_taken_param.split(',')
    if geoids and lender and action_taken:
        query = HMDARecord.objects.filter(
            # actions 7-8 are preapprovals to ignore
            property_type__in=[1,2], owner_occupancy=1, lien_status=1,
            lender=lender, action_taken__in=action_taken
        ).filter(geoid_id__in=geoids).values(
            'geoid', 'geoid__census2010households__total'
        ).annotate(volume=Count('geoid'))
        return query
    else:
        return HttpResponseBadRequest("Missing one of lender, action_taken and county or geoid.")