swissvotes.models.vote

Attributes

T

StrT

Classes

HasCodes

Poster

encoded_property

A shorthand property to return the label of an encoded value. Requires

localized_property

A shorthand property to return a localized attribute. Requires at least

SwissVote

A single vote as defined by the code book.

Module Contents

class swissvotes.models.vote.HasCodes[source]

Bases: Protocol[T]

codes(attribute: str, /) dict[int | None, T][source]
swissvotes.models.vote.T[source]
swissvotes.models.vote.StrT[source]
class swissvotes.models.vote.Poster[source]

Bases: NamedTuple

thumbnail: str[source]
image: str[source]
url: str | None[source]
label: str[source]
class swissvotes.models.vote.encoded_property(nullable: bool = True)[source]

A shorthand property to return the label of an encoded value. Requires the instance the have a codes-lookup function. Creates the SqlAlchemy Column (with a prefixed underline).

Example:

class MyClass:

value = encoded_property()

def codes(self, attributes):

return {0: ‘None’, 1: ‘One’}

__set_name__(owner: type[HasCodes[T]], name: str) None[source]
__get__(instance: HasCodes[T], owner: type[object]) T | None[source]
class swissvotes.models.vote.localized_property[source]

Bases: Generic[StrT]

A shorthand property to return a localized attribute. Requires at least a xxx_de attribute and falls back to this.

Example:

class MyClass:

value_de = Column(Text) value_fr = Column(Text) value = localized_property()

__set_name__(owner: type[HasSessionManager], name: str) None[source]
__get__(instance: HasSessionManager, owner: type[HasSessionManager]) StrT[source]
class swissvotes.models.vote.SwissVote[source]

Bases: onegov.core.orm.Base, onegov.core.orm.mixins.TimestampMixin, onegov.swissvotes.models.file.LocalizedFiles, onegov.core.orm.mixins.ContentMixin

A single vote as defined by the code book.

There are a lot of columns: - Some general, ready to be used attributes (bfs_number, …) - Encoded attributes, where the raw integer value is stored prefixed with

an underline and the attribute returns a translatable label by using the codes function, e.g. _legal_form, legal_form and codes(' _legal_form').

  • Descriptors, easily accessible by using policy_areas.

  • A lot of lazy loaded, cantonal results only used when importing/exporting the dataset.

  • Recommendations from different parties and assocciations. Internally stored as JSON and easily accessible and group by slogan with recommendations_parties, recommendations_divergent_parties and recommendations_associations.

  • Different localized attachments, some of them indexed for full text search.

  • Metadata from external information sources such as Museum für Gestaltung can be stored in the content or meta field provided by the ContentMixin.

__tablename__ = 'swissvotes'[source]
ORGANIZATION_NO_LONGER_EXISTS = 9999[source]
term: str | None = None[source]
static codes(attribute: str) dict[int | None, str][source]

Returns the codes for the given attribute as defined in the code book.

static metadata_codes(attribute: str) dict[str, str][source]
id: Column[int][source]
bfs_number: Column[Decimal][source]
date: Column[date_t][source]
title_de: Column[str][source]
title_fr: Column[str][source]
title: localized_property[str][source]
short_title_de: Column[str][source]
short_title_fr: Column[str][source]
short_title_en: Column[str | None][source]
short_title: localized_property[str][source]
brief_description_title: Column[str | None][source]
keyword: Column[str | None][source]
legal_form[source]
parliamentary_initiated[source]
initiator_de: Column[str | None][source]
initiator_fr: Column[str | None][source]
initiator[source]
anneepolitique: Column[str | None][source]
bfs_map_de: Column[str | None][source]
bfs_map_fr: Column[str | None][source]
bfs_map_en: Column[str | None][source]
bfs_map[source]
bfs_dashboard_de: Column[str | None][source]
bfs_dashboard_fr: Column[str | None][source]
bfs_dashboard_en: Column[str | None][source]
bfs_dashboard[source]
property bfs_map_host: str | None[source]

Returns the Host of the BFS Map link for CSP.

link_post_vote_poll_de: onegov.core.orm.mixins.dict_property[str | None][source]
link_post_vote_poll_fr: onegov.core.orm.mixins.dict_property[str | None][source]
link_post_vote_poll_en: onegov.core.orm.mixins.dict_property[str | None][source]
link_post_vote_poll[source]
campaign_finances_yea_total: Column[int | None][source]
campaign_finances_nay_total: Column[int | None][source]
campaign_finances_yea_donors_de: onegov.core.orm.mixins.dict_property[str | None][source]
campaign_finances_yea_donors_de[source]
campaign_finances_yea_donors_fr: onegov.core.orm.mixins.dict_property[str | None][source]
campaign_finances_yea_donors_fr[source]
campaign_finances_yea_donors[source]
campaign_finances_nay_donors_de: onegov.core.orm.mixins.dict_property[str | None][source]
campaign_finances_nay_donors_de[source]
campaign_finances_nay_donors_fr: onegov.core.orm.mixins.dict_property[str | None][source]
campaign_finances_nay_donors_fr[source]
campaign_finances_nay_donors[source]
posters_mfg_yea: Column[str | None][source]
posters_mfg_nay: Column[str | None][source]
posters_sa_yea: Column[str | None][source]
posters_sa_nay: Column[str | None][source]
posters_mfg_yea_imgs: onegov.core.orm.mixins.dict_property[dict[str, Any]][source]
posters_mfg_nay_imgs: onegov.core.orm.mixins.dict_property[dict[str, Any]][source]
posters_sa_yea_imgs: onegov.core.orm.mixins.dict_property[dict[str, Any]][source]
posters_sa_nay_imgs: onegov.core.orm.mixins.dict_property[dict[str, Any]][source]
posters(request: onegov.swissvotes.request.SwissvotesRequest) dict[str, list[Poster]][source]
media_ads_total: Column[int | None][source]
media_ads_yea_p: Column[Decimal | None][source]
media_coverage_articles_total: Column[int | None][source]
media_coverage_tonality_total: Column[Decimal | None][source]
descriptor_1_level_1: Column[Decimal | None][source]
descriptor_1_level_2: Column[Decimal | None][source]
descriptor_1_level_3: Column[Decimal | None][source]
descriptor_2_level_1: Column[Decimal | None][source]
descriptor_2_level_2: Column[Decimal | None][source]
descriptor_2_level_3: Column[Decimal | None][source]
descriptor_3_level_1: Column[Decimal | None][source]
descriptor_3_level_2: Column[Decimal | None][source]
descriptor_3_level_3: Column[Decimal | None][source]
policy_areas() list[onegov.swissvotes.models.policy_area.PolicyArea][source]

Returns the policy areas / descriptors of the vote.

result[source]
result_turnout: Column[Decimal | None][source]
result_people_accepted[source]
result_people_yeas_p: Column[Decimal | None][source]
result_cantons_accepted[source]
result_cantons_yeas: Column[Decimal | None][source]
result_cantons_nays: Column[Decimal | None][source]
result_ag_accepted[source]
result_ai_accepted[source]
result_ar_accepted[source]
result_be_accepted[source]
result_bl_accepted[source]
result_bs_accepted[source]
result_fr_accepted[source]
result_ge_accepted[source]
result_gl_accepted[source]
result_gr_accepted[source]
result_ju_accepted[source]
result_lu_accepted[source]
result_ne_accepted[source]
result_nw_accepted[source]
result_ow_accepted[source]
result_sg_accepted[source]
result_sh_accepted[source]
result_so_accepted[source]
result_sz_accepted[source]
result_tg_accepted[source]
result_ti_accepted[source]
result_ur_accepted[source]
result_vd_accepted[source]
result_vs_accepted[source]
result_zg_accepted[source]
result_zh_accepted[source]
number_of_cantons() int[source]
results_cantons() dict[str, list[onegov.swissvotes.models.region.Region]][source]

Returns the results of all cantons.

procedure_number: Column[str | None][source]
position_federal_council[source]
position_parliament[source]
position_national_council[source]
position_national_council_yeas: Column[int | None][source]
position_national_council_nays: Column[int | None][source]
position_council_of_states[source]
position_council_of_states_yeas: Column[int | None][source]
position_council_of_states_nays: Column[int | None][source]
duration_federal_assembly: Column[int | None][source]
duration_initative_collection: Column[int | None][source]
duration_referendum_collection: Column[int | None][source]
signatures_valid: Column[int | None][source]
recommendations: Column[dict[str, int]][source]
recommendations_other_yes_de: Column[str | None][source]
recommendations_other_yes_fr: Column[str | None][source]
recommendations_other_yes[source]
recommendations_other_no_de: Column[str | None][source]
recommendations_other_no_fr: Column[str | None][source]
recommendations_other_no[source]
recommendations_other_counter_proposal_de: Column[str | None][source]
recommendations_other_counter_proposal_de[source]
recommendations_other_counter_proposal_fr: Column[str | None][source]
recommendations_other_counter_proposal_fr[source]
recommendations_other_counter_proposal[source]
recommendations_other_popular_initiative_de[source]
recommendations_other_popular_initiative_fr[source]
recommendations_other_free_de: Column[str | None][source]
recommendations_other_free_fr: Column[str | None][source]
recommendations_other_free[source]
recommendations_divergent: Column[dict[str, Any]][source]
get_recommendation(name: str) str | None[source]

Get the recommendations by name.

get_recommendation_of_existing_parties() dict[str, int][source]

Get only the existing parties as when this vote was conducted

group_recommendations(recommendations: Iterable[tuple[T, int | None]], ignore_unknown: bool = False) dict[str, list[T]][source]

Group the given recommendations by slogan.

get_actors_share(actor: str) int[source]
sorted_actors_list() list[str][source]

Returns a list of actors of the current vote sorted by:

  1. codes for recommendations (strength table)

  2. by electoral share (descending)

It filters out those parties who have no electoral share

recommendations_parties() dict[str, list[onegov.swissvotes.models.actor.Actor]][source]

The recommendations of the parties grouped by slogans.

recommendations_divergent_parties() dict[str, list[tuple[onegov.swissvotes.models.actor.Actor, onegov.swissvotes.models.region.Region]]][source]

The divergent recommendations of the parties grouped by slogans.

recommendations_associations() dict[str, list[onegov.swissvotes.models.actor.Actor]][source]

The recommendations of the associations grouped by slogans.

national_council_election_year: Column[int | None][source]
national_council_share_fdp: Column[Decimal | None][source]
national_council_share_fdp[source]
national_council_share_cvp: Column[Decimal | None][source]
national_council_share_cvp[source]
national_council_share_sps: Column[Decimal | None][source]
national_council_share_sps[source]
national_council_share_svp: Column[Decimal | None][source]
national_council_share_svp[source]
national_council_share_lps: Column[Decimal | None][source]
national_council_share_lps[source]
national_council_share_ldu: Column[Decimal | None][source]
national_council_share_ldu[source]
national_council_share_evp: Column[Decimal | None][source]
national_council_share_evp[source]
national_council_share_csp: Column[Decimal | None][source]
national_council_share_csp[source]
national_council_share_pda: Column[Decimal | None][source]
national_council_share_pda[source]
national_council_share_poch: Column[Decimal | None][source]
national_council_share_poch[source]
national_council_share_gps: Column[Decimal | None][source]
national_council_share_gps[source]
national_council_share_sd: Column[Decimal | None][source]
national_council_share_sd[source]
national_council_share_rep: Column[Decimal | None][source]
national_council_share_rep[source]
national_council_share_edu: Column[Decimal | None][source]
national_council_share_edu[source]
national_council_share_fps: Column[Decimal | None][source]
national_council_share_fps[source]
national_council_share_lega: Column[Decimal | None][source]
national_council_share_lega[source]
national_council_share_kvp: Column[Decimal | None][source]
national_council_share_kvp[source]
national_council_share_glp: Column[Decimal | None][source]
national_council_share_glp[source]
national_council_share_bdp: Column[Decimal | None][source]
national_council_share_bdp[source]
national_council_share_mcg: Column[Decimal | None][source]
national_council_share_mcg[source]
national_council_share_mitte: Column[Decimal | None][source]
national_council_share_mitte[source]
national_council_share_ubrige: Column[Decimal | None][source]
national_council_share_ubrige[source]
national_council_share_yeas: Column[Decimal | None][source]
national_council_share_yeas[source]
national_council_share_nays: Column[Decimal | None][source]
national_council_share_nays[source]
national_council_share_none: Column[Decimal | None][source]
national_council_share_none[source]
national_council_share_empty: Column[Decimal | None][source]
national_council_share_empty[source]
national_council_share_free_vote: Column[Decimal | None][source]
national_council_share_free_vote[source]
national_council_share_neutral: Column[Decimal | None][source]
national_council_share_neutral[source]
national_council_share_unknown: Column[Decimal | None][source]
national_council_share_unknown[source]
has_national_council_share_data() bool[source]

Returns true, if the vote contains national council share data.

Returns true, if a national council year is set and - any aggregated national council share data is present (yeas, nays,

none, empty, free vote, neutral, unknown)

  • or any national council share data of parties with national council share and a recommendation regarding this vote is present

files[source]
voting_text[source]
brief_description[source]
federal_council_message[source]
parliamentary_initiative[source]
parliamentary_committee_report[source]
federal_council_opinion[source]
parliamentary_debate[source]
voting_booklet[source]
easyvote_booklet[source]
resolution[source]
realization[source]
ad_analysis[source]
results_by_domain[source]
foeg_analysis[source]
post_vote_poll[source]
post_vote_poll_methodology[source]
post_vote_poll_dataset[source]
post_vote_poll_dataset_sav[source]
post_vote_poll_dataset_dta[source]
post_vote_poll_codebook[source]
post_vote_poll_codebook_xlsx[source]
post_vote_poll_report[source]
preliminary_examination[source]
campaign_finances_xlsx[source]
campaign_material_yea[source]
campaign_material_nay[source]
campaign_material_other[source]
campaign_material_metadata: Column[dict[str, Any]][source]
searchable_text_de_CH[source]
searchable_text_fr_CH[source]
searchable_text_it_CH[source]
searchable_text_en_US[source]
indexed_files[source]
reindex_files() None[source]

Extract the text from the localized files and the campaign material and save it together with the language. Store the text of the indexed only localized files and all campaign material in the search indexes.

The language is determined as follows: - For the localized files, the language is determined by the locale,

e.g. de_CH -> german.

  • For the campaign material, the campaign metadata is used. If a document is (amongst others) de –> german. If (amongst others,) fr but not de –> french. If (amongst others) it but not de or fr –> italian. In all other cases english.

files_observer(files: list[onegov.swissvotes.models.file.SwissVoteFile]) None[source]
get_file(name: str, locale: str | None = None, fallback: bool = True) onegov.swissvotes.models.file.SwissVoteFile | None[source]

Returns the requested localized file.

Uses the current locale if no locale is given.

Falls back to the default locale if the file is not available in the requested locale.

static search_term_expression(term: str | None) str[source]

Returns the given search term transformed to use within Postgres to_tsquery function.

Removes all unwanted characters, replaces prefix matching, joins word together using FOLLOWED BY.

search(term: str | None = None) list[onegov.swissvotes.models.file.SwissVoteFile][source]

Searches for the given term in the indexed attachments.

Returns a tuple of attribute name and locale which can be used with get_file.