Skip to content

Commit

Permalink
Add annotations and whip reports to api
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Dec 20, 2024
1 parent f6ac20e commit 16df764
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/votes/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from ..consts import PolicyStatus, RebellionPeriodType
from ..models import (
Agreement,
AgreementAnnotation,
Chamber,
Division,
DivisionAnnotation,
DivisionBreakdown,
DivisionPartyBreakdown,
DivisionsIsGovBreakdown,
Expand All @@ -28,6 +30,7 @@
RebellionRate,
Update,
Vote,
VoteAnnotation,
VoteDistribution,
)
from .helper_models import PairedPolicy, PolicyDisplayGroup, PolicyReport
Expand Down Expand Up @@ -128,13 +131,43 @@ class Meta:
fields = "__all__"


class AgreementAnnotationSchema(ModelSchema):
class Meta:
model = AgreementAnnotation
fields = "__all__"


class DivisionAnnotationSchema(ModelSchema):
class Meta:
model = DivisionAnnotation
fields = "__all__"


class VoteAnnotationSchema(ModelSchema):
class Meta:
model = VoteAnnotation
fields = "__all__"


class DivisionWithInfoSchema(ModelSchema):
votes: list[VoteSchema]
overall_breakdowns: list[DivisionBreakdownSchema]
party_breakdowns: list[DivisionPartyBreakdownSchema]
is_gov_breakdowns: list[DivisionsIsGovBreakdownSchema]
motion: MotionSchema | None
voting_cluster: dict[str, str]
division_annotations: list[DivisionAnnotationSchema]
vote_annotations: list[VoteAnnotationSchema]
whip_reports: list[dict[str, Any]]

@staticmethod
def resolve_whip_reports(obj: Division):
df = obj.whip_report_df()
if df is None:
return []
# for columns, drop to lower case and change spaces to underscores
df.columns = [x.lower().replace(" ", "_") for x in df.columns]
return df.to_dict(orient="records")

@staticmethod
def resolve_voting_cluster(obj: Division):
Expand All @@ -149,6 +182,8 @@ class Meta:


class AgreementSchema(ModelSchema):
agreement_annotations: list[AgreementAnnotationSchema]

class Meta:
model = Agreement
fields = "__all__"
Expand Down

0 comments on commit 16df764

Please sign in to comment.