Пример #1
0
def all_ies_chart(div_to_return):

    start_date = datetime.date(2012, 1, 1)
    today = datetime.date(2012, 12, 31)
    #datetime.datetime.today()

    all_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        expenditure_date__gte=start_date,
        expenditure_date__lte=today).extra(
            select={
                'year': 'EXTRACT(year FROM expenditure_date)',
                'week': 'EXTRACT(week FROM expenditure_date)'
            }).values_list('year', 'week').order_by('year', 'week').annotate(
                Sum('expenditure_amount'))

    weekly_ie_summary = summarize_weekly(all_ies)

    return {
        'has_series1': True,
        'series1_data': weekly_ie_summary,
        'series1_title': 'ALL INDEPENDENT EXPENDITURES',
        'has_series2': False,
        'return_div': div_to_return,
    }
Пример #2
0
def senate_all_ie_party_general(div_to_return):
    # all IE spending in the presidential race by partisan intent
    # Dem = Prodem plus antirep etc.
    today = datetime.date(2012, 12, 31)
    start_date = datetime.date(2012, 6, 1)

    all_senate_general_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        candidate__office='S',
        election_type="G",
        expenditure_date__gte=start_date,
        expenditure_date__lte=today).select_related('candidate')

    pro_dem = all_senate_general_ies.filter(
        Q(candidate__party__iexact='DEM', support_oppose='S')
        | Q(candidate__party__iexact='REP', support_oppose='O'))

    pro_rep = all_senate_general_ies.filter(
        Q(candidate__party__iexact='REP', support_oppose='S')
        | Q(candidate__party__iexact='DEM', support_oppose='O'))

    weekly_pro_dem = pro_dem.extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    weekly_pro_rep = pro_rep.extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    weekly_dem = summarize_weekly(weekly_pro_dem)
    weekly_rep = summarize_weekly(weekly_pro_rep)

    return {
        'has_series1': True,
        'series1_data': weekly_dem,
        'series1_title': 'BACKS DEMOCRATS',
        'has_series2': True,
        'series2_title': 'BACKS REPUBLICANS',
        'series2_data': weekly_rep,
        'return_div': div_to_return,
    }
Пример #3
0
def noncommittee_spending_by_affiliation(div_to_return):
    start_date = datetime.date(2012, 6, 1)
    today = datetime.date(2012, 12, 31)

    noncommittee_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        committee__ctype='I',
        expenditure_date__gte=start_date,
        expenditure_date__lte=today).select_related('committee')

    noncommittee_rep = noncommittee_ies.filter(
        committee__political_orientation='R')
    noncommittee_dem = noncommittee_ies.filter(
        committee__political_orientation='D')

    weekly_noncommittee_dem = noncommittee_dem.extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    weekly_noncommittee_rep = noncommittee_rep.extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    weekly_dem = summarize_weekly(weekly_noncommittee_dem)
    weekly_rep = summarize_weekly(weekly_noncommittee_rep)

    today = datetime.datetime.today()

    return {
        'has_series1': True,
        'series1_data': weekly_dem,
        'series1_title': 'NONCOMMITTEES, DEMOCRATIC',
        'has_series2': True,
        'series2_data': weekly_rep,
        'series2_title': 'NONCOMMITTEES, REPUBLICAN',
        'return_div': div_to_return,
    }
Пример #4
0
def superpac_partisan_general_weekly(div_to_return):

    today = datetime.date(2012, 12, 31)
    start_date = datetime.date(2012, 6, 1)

    all_sp_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        election_type="G",
        committee__is_superpac=True,
        expenditure_date__gte=start_date,
        expenditure_date__lte=today).select_related('candidate')

    r_ies = all_sp_ies.filter(committee__political_orientation='R').extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    d_ies = all_sp_ies.filter(committee__political_orientation='D').extra(
        select={
            'year': 'EXTRACT(year FROM expenditure_date)',
            'week': 'EXTRACT(week FROM expenditure_date)'
        }).values_list('year', 'week').order_by('year', 'week').annotate(
            Sum('expenditure_amount'))

    weekly_ie_r_summary = summarize_weekly(r_ies)
    weekly_ie_d_summary = summarize_weekly(d_ies)

    return {
        'has_series1': True,
        'series2_data': weekly_ie_r_summary,
        'series2_title': 'RIGHT-LEANING SUPERPACS',
        'has_series2': True,
        'series1_data': weekly_ie_d_summary,
        'series1_title': 'LEFT-LEANING SUPERPACS',
        'return_div': div_to_return,
    }
Пример #5
0
def superpac_partisan_general(div_to_return):

    r_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        committee__political_orientation='R',
        election_type="G",
        committee__is_superpac=True).extra(
            select={
                'year': 'EXTRACT(year FROM expenditure_date)',
                'week': 'EXTRACT(week FROM expenditure_date)'
            }).values_list('year', 'week').order_by('year', 'week').annotate(
                Sum('expenditure_amount'))

    d_ies = Expenditure.objects.filter(
        superceded_by_amendment=False,
        committee__political_orientation='D',
        election_type="P",
        committee__is_superpac=True).extra(
            select={
                'year': 'EXTRACT(year FROM expenditure_date)',
                'week': 'EXTRACT(week FROM expenditure_date)'
            }).values_list('year', 'week').order_by('year', 'week').annotate(
                Sum('expenditure_amount'))

    today = datetime.date(2012, 12, 31)
    weekly_ie_r_summary = summarize_weekly(r_ies)
    weekly_ie_d_summary = summarize_weekly(d_ies)

    return {
        'has_series1': True,
        'series2_data': weekly_ie_r_summary,
        'series2_title': 'PRIMARY ELECTION REPUBLICAN SUPERPAC SPENDING',
        'has_series2': True,
        'series1_data': weekly_ie_d_summary,
        'series1_title': 'PRIMARY ELECTION DEMOCRATIC SUPERPAC SPENDING',
        'return_div': div_to_return,
    }