本文整理汇总了Python中us.get_congress_dates函数的典型用法代码示例。如果您正苦于以下问题:Python get_congress_dates函数的具体用法?Python get_congress_dates怎么用?Python get_congress_dates使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_congress_dates函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: membersoverview
def membersoverview(request):
def get_current_members(role_type, delegates, by_party):
qs = PersonRole.objects.filter(
role_type=role_type,
current=True,
state__in=set(s for s, t in stateapportionment.items() if (t != "T") ^ delegates)
)
if by_party:
return qs.values('party').annotate(count=Count('party')).order_by('-count')
else:
return qs.count()
congress_current = (CURRENT_CONGRESS, get_congress_dates(CURRENT_CONGRESS)[0])
congress_previous = (CURRENT_CONGRESS-1, get_congress_dates(CURRENT_CONGRESS-1)[1])
return {
"statelist": statelist,
"senate_by_party": get_current_members(RoleType.senator, False, True),
"senate_vacancies": 100-get_current_members(RoleType.senator, False, False),
"house_by_party": get_current_members(RoleType.representative, False, True),
"house_vacancies": 435-get_current_members(RoleType.representative, False, False),
"house_delegate_vacancies": 6-get_current_members(RoleType.representative, True, False),
"congress_current": congress_current,
"congress_previous": congress_previous,
}
示例2: compute_productivity
def compute_productivity(congress, days_in):
corresponding_day = get_congress_dates(congress)[0] + days_in
# laws
enacted_bills = Bill.objects.filter(
congress=congress,
current_status__in=BillStatus.final_status_passed_bill,
current_status_date__lte=corresponding_day)
#enacted_bills = (enacted_bills.filter(title__contains="Appropriations") | enacted_bills.filter(title__contains="Authorization")).distinct()
enacted_bills = list(enacted_bills)
enacted_bills_count = len(enacted_bills)
enacted_bill_pages = 0
enacted_bill_words = 0
enacted_bill_pages_missing = 0
for b in enacted_bills:
try:
pp = load_bill_text(b, None, mods_only=True).get("numpages")
except IOError:
pp = None
if pp is None:
enacted_bill_pages_missing += 1
continue
pp = int(pp.replace(" pages", ""))
enacted_bill_pages += pp
wds = len(load_bill_text(b, None, plain_text=True).split(" "))
enacted_bill_words += wds
if congress < 103: enacted_bill_pages = "(no data)"
if congress < 103: enacted_bill_words = "(no data)"
# votes
house_votes = Vote.objects.filter(
congress=congress,
created__lte=corresponding_day,
chamber=CongressChamber.house).count()
senate_votes = Vote.objects.filter(
congress=congress,
created__lte=corresponding_day,
chamber=CongressChamber.senate).count()
# power
congress_same_party = party_control[congress][0] == party_control[congress][1]
branches_same_party = (party_control[congress][0] == party_control[congress][1]) and (party_control[congress][0] == party_control[congress][2])
#
timespan = "%d (%d-%d)" % (congress, get_congress_dates(congress)[0].year, get_congress_dates(congress)[1].year-1)
row = [timespan, enacted_bills_count, enacted_bill_pages, enacted_bill_words, house_votes, senate_votes, "Yes" if congress_same_party else "No", "Yes" if branches_same_party else "No"]
W.writerow(row)
示例3: bill_details
def bill_details(request, congress, type_slug, number):
# pre-load info
bill = load_bill_from_url(congress, type_slug, number)
text_info = bill.get_text_info(with_citations=True)
from stakeholder.models import BillPosition
stakeholder_posts = bill.stakeholder_positions\
.filter(post__stakeholder__verified=True)\
.select_related("post", "post__stakeholder")\
.order_by('-created')
def add_position_return_post(bp): bp.post.position = bp.position; return bp.post
stakeholder_posts = [add_position_return_post(bp) for bp in stakeholder_posts]
# context
return {
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"subtitle": get_secondary_bill_title(bill, bill.titles),
"current": bill.congress == CURRENT_CONGRESS,
"dead": bill.congress != CURRENT_CONGRESS and bill.current_status not in BillStatus.final_status_obvious,
"feed": bill.get_feed(),
"prognosis": bill.get_prognosis_with_details(),
"text_info": text_info,
"text_incorporation": fixup_text_incorporation(bill.text_incorporation),
"show_media_bar": not bill.original_intent_replaced and bill.sponsor and bill.sponsor.has_photo() and text_info and text_info.get("has_thumbnail"),
"stakeholder_posts": stakeholder_posts,
}
示例4: build_info
def build_info():
feeds = [f for f in Feed.get_simple_feeds() if f.category == "federal-bills"]
groups = [
( g[0], # title
g[1], # text 1
g[2], # text 2
"/congress/bills/browse?status=" + ",".join(str(s) for s in g[4]), # link
load_bill_status_qs(g[4]).count(), # count in category
load_bill_status_qs(g[4]).order_by('-current_status_date')[0:6], # top 6 in this category
)
for g in bill_status_groups ]
dhg_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
sfs_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=5)).filter(senate_floor_schedule_postdate__gt=F('current_status_date'))
coming_up = list(dhg_bills | sfs_bills)
coming_up.sort(key = lambda b : b.docs_house_gov_postdate if (b.docs_house_gov_postdate and (not b.senate_floor_schedule_postdate or b.senate_floor_schedule_postdate < b.docs_house_gov_postdate)) else b.senate_floor_schedule_postdate, reverse=True)
start, end = get_congress_dates(CURRENT_CONGRESS)
end_year = end.year if end.month > 1 else end.year-1 # count January finishes as the prev year
current_congress_years = '%d-%d' % (start.year, end.year)
current_congress = ordinal(CURRENT_CONGRESS)
return {
"feeds": feeds,
"total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
"current_congress_years": current_congress_years,
"current_congress": current_congress,
"groups": groups,
"coming_up": coming_up,
"subjects": subject_choices(),
"BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.referred, BillStatus.reported),
}
示例5: get_roles_of_people
def get_roles_of_people(congressnumber):
congress_dates = get_congress_dates(congressnumber)
return PersonRole.objects.filter(
role_type__in=(RoleType.senator, RoleType.representative),
startdate__lt=congress_dates[1], # start dates of next congress are on this day too
enddate__gt=congress_dates[0] # end dates from previous congress are on this day too
).select_related("person")\
.order_by('-startdate') # so we put people in the right list by their most recent term
示例6: bill_summaries
def bill_summaries(request, congress, type_slug, number):
bill = load_bill_from_url(congress, type_slug, number)
return {
"bill_subpage": "Summary",
"bill": bill,
"congressdates": get_congress_dates(bill.congress),
"text_info": bill.get_text_info(with_citations=True), # for the header tabs
}
示例7: bill_text
def bill_text(request, congress, type_slug, number, version=None):
if version == "":
version = None
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
from .billtext import load_bill_text, get_bill_text_versions
try:
textdata = load_bill_text(bill, version)
except IOError:
textdata = None
# Get a list of the alternate versions of this bill.
alternates = None
is_latest = True
if textdata:
alternates = []
for v in get_bill_text_versions(bill):
try:
alternates.append(load_bill_text(bill, v, mods_only=True))
except IOError:
pass
alternates.sort(key = lambda mods : mods["docdate"])
if len(alternates) > 0:
is_latest = False
if textdata["doc_version"] == alternates[-1]["doc_version"]:
is_latest = True
# Get a list of related bills.
from .billtext import get_current_version
related_bills = []
for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]:
try:
rbv = get_current_version(rb)
if not (rb, rbv) in related_bills: related_bills.append((rb, rbv))
except IOError:
pass # text not available
for btc in BillTextComparison.objects.filter(bill1=bill).exclude(bill2=bill):
if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2))
for btc in BillTextComparison.objects.filter(bill2=bill).exclude(bill1=bill):
if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1))
return {
"bill_subpage": "Text",
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"textdata": textdata,
"version": version,
"is_latest": is_latest,
"alternates": alternates,
"related_bills": related_bills,
"days_old": (datetime.datetime.now().date() - bill.current_status_date).days,
"is_on_bill_text_page": True, # for the header tabs
}
示例8: bill_details
def bill_details(request, congress, type_slug, number):
bill = load_bill_from_url(congress, type_slug, number)
return {
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"subtitle": get_secondary_bill_title(bill, bill.titles),
"current": bill.congress == CURRENT_CONGRESS,
"dead": bill.congress != CURRENT_CONGRESS and bill.current_status not in BillStatus.final_status_obvious,
"feed": bill.get_feed(),
"text_info": get_text_info(bill),
}
示例9: analysis_methodology
def analysis_methodology(request):
from settings import CURRENT_CONGRESS
from person.models import RoleType
from bill.models import BillType
from us import get_congress_dates
import json
from person.analysis import load_sponsorship_analysis2
def make_chart_series(role_type):
data = load_sponsorship_analysis2(CURRENT_CONGRESS, role_type, None)
if not data: return None
ret = { }
for p in data["all"]:
ret.setdefault(p["party"], {
"type": "party",
"party": p["party"],
"data": [],
})["data"].append({
"x": float(p["ideology"]),
"y": float(p["leadership"]),
"name": p["name"],
})
ret = list(ret.values())
ret.sort(key = lambda s : len(s["data"]), reverse=True)
data = dict(data) # clone before modifying, just in case
data["series"] = json.dumps(ret)
return data
import bill.prognosis
import bill.prognosis_model
import bill.prognosis_model_test
prognosis_factors = sorted([dict(v) for v in bill.prognosis_model.factors.values()],
key = lambda m : m["count"], reverse=True)
for v in prognosis_factors:
v["factors"] = sorted(v["factors"].values(), key = lambda f : f["regression_beta"], reverse=True)
prognosis_test = sorted(bill.prognosis_model_test.model_test_results.values(),
key = lambda v : v["count"], reverse=True)
return {
"ideology": lambda : { # defer until cache miss
"house": make_chart_series(RoleType.representative),
"senate": make_chart_series(RoleType.senator),
},
"current_congress": CURRENT_CONGRESS,
"prognosis_training_congress": bill.prognosis_model.congress,
"prognosis_training_congress_dates": get_congress_dates(bill.prognosis_model.congress),
"prognosis_factors": prognosis_factors,
"prognosis_test": prognosis_test,
"prognosis_testing_traincongress": bill.prognosis_model_test.train_congress,
"prognosis_testing_testcongress": bill.prognosis_model_test.test_congress,
}
示例10: load_majority_party
def load_majority_party(congress):
majority_party = { }
start, end = get_congress_dates(congress)
for rt, bts in (
(RoleType.senator, (BillType.senate_bill, BillType.senate_resolution, BillType.senate_concurrent_resolution, BillType.senate_joint_resolution)),
(RoleType.representative, (BillType.house_bill, BillType.house_resolution, BillType.house_concurrent_resolution, BillType.house_joint_resolution))
):
p = PersonRole.objects.filter(startdate__lte=end, enddate__gte=start, role_type=rt).values("party").annotate(count=Count("id")).order_by("-count")[0]["party"]
for bt in bts:
majority_party[bt] = p
return majority_party
示例11: build_info
def build_info():
# feeds about all legislation that we offer the user to subscribe to
feeds = [f for f in Feed.get_simple_feeds() if f.category == "federal-bills"]
# info about bills by status
groups = [
( g[0], # title
g[1], # text 1
g[2], # text 2
"/congress/bills/browse?status=" + ",".join(str(s) for s in g[4]) + "&sort=-current_status_date", # link
load_bill_status_qs(g[4]).count(), # count in category
load_bill_status_qs(g[4]).order_by('-current_status_date')[0:6], # top 6 in this category
)
for g in bill_status_groups ]
# legislation coming up
dhg_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
sfs_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=5)).filter(senate_floor_schedule_postdate__gt=F('current_status_date'))
coming_up = list(dhg_bills | sfs_bills)
coming_up.sort(key = lambda b : b.docs_house_gov_postdate if (b.docs_house_gov_postdate and (not b.senate_floor_schedule_postdate or b.senate_floor_schedule_postdate < b.docs_house_gov_postdate)) else b.senate_floor_schedule_postdate, reverse=True)
# top tracked bills
top_bills = Feed.objects\
.filter(feedname__startswith='bill:')\
.filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
top_bills = top_bills\
.annotate(count=Count('tracked_in_lists'))\
.order_by('-count')\
.values('feedname', 'count')\
[0:25]
top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])), bf["count"]) for bf in top_bills]
# current congrss years
start, end = get_congress_dates(CURRENT_CONGRESS)
end_year = end.year if end.month > 1 else end.year-1 # count January finishes as the prev year
current_congress_years = '%d-%d' % (start.year, end.year)
current_congress = ordinal(CURRENT_CONGRESS)
return {
"feeds": feeds,
"total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
"current_congress_years": current_congress_years,
"current_congress": current_congress,
"groups": groups,
"coming_up": coming_up,
"top_tracked_bills": top_bills,
"subjects": subject_choices(),
"BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.referred, BillStatus.reported),
}
示例12: build_info
def build_info():
# feeds about all legislation that we offer the user to subscribe to
feeds = [f for f in Feed.get_simple_feeds() if f.category == "federal-bills"]
# info about bills by status
groups = [
( g[0], # title
g[1], # text 1
g[2], # text 2
"/congress/bills/browse?status=" + ",".join(str(s) for s in g[4]) + "&sort=-current_status_date", # link
load_bill_status_qs(g[4]).count(), # count in category
load_bill_status_qs(g[4]).order_by('-current_status_date')[0:6], # top 6 in this category
)
for g in bill_status_groups ]
# legislation coming up
dhg_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, docs_house_gov_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=10)).filter(docs_house_gov_postdate__gt=F('current_status_date'))
sfs_bills = Bill.objects.filter(congress=CURRENT_CONGRESS, senate_floor_schedule_postdate__gt=datetime.datetime.now() - datetime.timedelta(days=5)).filter(senate_floor_schedule_postdate__gt=F('current_status_date'))
coming_up = list((dhg_bills | sfs_bills).order_by('scheduled_consideration_date'))
# top tracked bills
top_bills = Feed.objects\
.filter(feedname__startswith='bill:')\
.filter(feedname__regex='^bill:[hs][jcr]?%d-' % CURRENT_CONGRESS)
top_bills = top_bills\
.annotate(count=Count('tracked_in_lists'))\
.order_by('-count')\
.values('feedname', 'count')\
[0:25]
top_bills = [(Bill.from_feed(Feed.from_name(bf["feedname"])), bf["count"]) for bf in top_bills]
# trending bills
trf = Feed.get_trending_feeds()
trf = [Feed.objects.get(id=f) for f in trf]
trending_bill_feeds = [f for f in trf if f.feedname.startswith("bill:")]
return {
"feeds": feeds,
"total": Bill.objects.filter(congress=CURRENT_CONGRESS).count(),
"current_congress": CURRENT_CONGRESS,
"current_congress_dates": get_congress_dates(CURRENT_CONGRESS),
"groups": groups,
"coming_up": coming_up,
"top_tracked_bills": top_bills,
"trending_bill_feeds": trending_bill_feeds,
"subjects": subject_choices(),
"BILL_STATUS_INTRO": (BillStatus.introduced, BillStatus.reported),
}
示例13: bill_text
def bill_text(request, congress, type_slug, number, version=None):
if version == "":
version = None
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
from billtext import load_bill_text, bill_gpo_status_codes
try:
textdata = load_bill_text(bill, version)
except IOError:
textdata = None
# Get a list of the alternate versions of this bill.
alternates = None
if textdata:
alternates = []
for v in bill_gpo_status_codes:
try:
alternates.append(load_bill_text(bill, v, mods_only=True))
except IOError:
pass
alternates.sort(key = lambda mods : mods["docdate"])
# Get a list of related bills.
from billtext import get_current_version
related_bills = []
for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]:
try:
rbv = get_current_version(rb)
if not (rb, rbv) in related_bills: related_bills.append((rb, rbv))
except IOError:
pass # text not available
for btc in BillTextComparison.objects.filter(bill1=bill).exclude(bill2=bill):
if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2))
for btc in BillTextComparison.objects.filter(bill2=bill).exclude(bill1=bill):
if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1))
return {
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"textdata": textdata,
"version": version,
"alternates": alternates,
"related_bills": related_bills,
}
示例14: bill_text
def bill_text(request, congress, type_slug, number, version=None):
if int(congress) < 103:
raise Http404("Bill text is not available before the 103rd congress.")
if version == "":
version = None
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
from billtext import load_bill_text, bill_gpo_status_codes
try:
textdata = load_bill_text(bill, version)
except IOError:
textdata = None
# Get a list of the alternate versions of this bill.
alternates = None
if textdata:
alternates = []
for v in bill_gpo_status_codes:
fn = "data/us/bills.text/%s/%s/%s%d%s.mods.xml" % (bill.congress, BillType.by_value(bill.bill_type).xml_code, BillType.by_value(bill.bill_type).xml_code, bill.number, v)
if os.path.exists(fn):
alternates.append(load_bill_text(bill, v, mods_only=True))
alternates.sort(key = lambda mods : mods["docdate"])
# Get a list of related bills.
related_bills = []
for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]:
if not (rb, "") in related_bills: related_bills.append((rb, ""))
for btc in BillTextComparison.objects.filter(bill1=bill):
if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2))
for btc in BillTextComparison.objects.filter(bill2=bill):
if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1))
return {
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"textdata": textdata,
"version": version,
"alternates": alternates,
"related_bills": related_bills,
}
示例15: bill_statistics
def bill_statistics(request):
# Get the count of bills by status and by Congress.
counts_by_congress = []
for c in xrange(93, CURRENT_CONGRESS+1):
total = Bill.objects.filter(congress=c).count()
if total == 0: continue # during transitions between Congresses
counts_by_congress.append({
"congress": c,
"dates": get_congress_dates(c),
"counts": [ ],
"total": total,
})
for g in bill_status_groups:
t = load_bill_status_qs(g[4], congress=c).count()
counts_by_congress[-1]["counts"].append(
{ "count": t,
"percent": "%0.0f" % float(100.0*t/total),
"link": "/congress/bills/browse?congress=%s&status=%s" % (c, ",".join(str(s) for s in g[4])),
} )
counts_by_congress.reverse()
# When does activity occur within the session cycle?
if settings.DATABASES['default']['ENGINE'] != 'django.db.backends.sqlite3':
from django.db import connection
def pull_time_stat(field, where, cursor):
historical = False
cursor.execute("SELECT YEAR(%s) - congress*2 - 1787, MONTH(%s), COUNT(*) FROM bill_bill WHERE congress>=93 AND congress%s%d AND %s GROUP BY YEAR(%s) - congress*2, MONTH(%s)" % (field, field, "<" if historical else "=", CURRENT_CONGRESS, where, field, field))
activity = [{ "x": r[0]*12 + (r[1]-1), "count": r[2], "year": r[0] } for r in cursor.fetchall()]
total = sum(m["count"] for m in activity)
for i, m in enumerate(activity): m["cumulative_count"] = m["count"]/float(total) + (0.0 if i==0 else activity[i-1]["cumulative_count"])
for m in activity: m["count"] = round(m["count"] / (CURRENT_CONGRESS-96), 1)
for m in activity: m["cumulative_count"] = round(m["cumulative_count"] * 100.0)
return activity
with connection.cursor() as cursor:
activity_introduced_by_month = pull_time_stat('introduced_date', "1", cursor)
activity_enacted_by_month = pull_time_stat('current_status_date', "current_status IN (%d,%d,%d)" % (int(BillStatus.enacted_signed), int(BillStatus.enacted_veto_override), int(BillStatus.enacted_tendayrule)), cursor)
else:
activity_introduced_by_month = []
activity_enacted_by_month = []
return {
"groups2": bill_status_groups,
"counts_by_congress": counts_by_congress,
"activity": (("Bills and Resolutions Introduced", activity_introduced_by_month),
("Bills and Joint Resolutions Enacted", activity_enacted_by_month) )
}