Parties and Polls

Core features of mapache.

Creating a party

class mapache.core.Party(name, logo_url, short_name=None, full_name=None, extra_names=None, thumbnail_url=None)[source]

Implements a political party.

__init__(name, logo_url, short_name=None, full_name=None, extra_names=None, thumbnail_url=None)[source]

Create political party.

Parameters:
  • name (str) – Name of the party. The preferred name to be used, although other names can be provided. If short_name is not indicated, name will be used to crate an abbreviation.
  • picture_url (Optional[str]) – url to the party logo, the color for the party will be generated from the image.
  • short_name (Optional[List[str]]) – Abbreviation of the party name to be displayed when there is no space for name. Maximum of 7 characters.
  • full_name (Optional[str]) – Official, full name of the part
  • extra_names (Optional[List[str]]) – Any number of extra names of the party to help matching the party to polls (eg. names in different languages).
__str__()[source]

Text for print().

Returns:Party information
Return type:str
__weakref__

list of weak references to the object (if defined)

add_to_coalition(party)[source]

Consider this party a coalition and add a party to it.

When the first party is added this party becomes a coalition. The parties in the coalition will be used to match the party with polls if the opposite is not specified.

Parameters:party (mapache.Party) – party to be added to the coalition
get_all_names()[source]

All names of the party.

Returns:all the names of the party (long, short, extra...)
Return type:(list)
get_coalition()[source]

Return parties being part of the coalition.

Current logo of the party.

Returns:Current logo of the party
Return type:PIL.Image
get_thumbnail(url)[source]

Current thumbnail of the party.

Returns:Current thumbnail of the party
Return type:PIL.Image
match(party_name)[source]

Evaluate how well a name matches this party.

mapache.core._levenshtein_distance is used for the comparison. All names of the party are used in the comparison.

Parameters:party_name (str) – name to be evaluated

Set the logo and updates the party color.

The image is download from url and the color of the party self.color is updated to the principal color of the image

Parameters:url (str) – url to a image with the logo of the party
set_thumbnail(url=None)[source]

Set the thumbnail of the party.

The size of the thumbnail will be 80x80 and squared images are preferred. If no url is provided the logo of the party will be used as the thumbnail.

Parameters:url (Optional[str]) – url to a image with the small logo of the party
show()[source]

Show the information of the party.

Displays the names, parties in the coalition and the logo of the party. The logo is displayed as a matplotlib image.

show_color()[source]

Show the color selected for the party_name.

A patch with the color of the party and its abreviation in white is displayed using matplotlib.

Grouping parties

class mapache.core.PartySet(context_name='')[source]

A group of parties with added funcionality.

A group of parties with name matching capabilities (ie. return the party with the closest name if similar enough) and some visualization tools.

extract(parties)[source]

Create a new PartySet with a subset of the current parties.

Parameters:parties (list [str]) – name of the parties to extract, name matching will be used to find the correct parties
Returns:new group of parties containing those in parties
Return type:PartySet

Creating a poll

class mapache.core.Poll(parties, date, pollster='', error=None)[source]

Grouping polls

class mapache.core.PollsList(name='')[source]