Skip to content

bohdanbobrowski/pyrlament

pyRLAMENT Library logo

Licence Python GitHub

pyRLAMENT

Python library for visualizing seats in the Sejm of the Republic of Poland. So far still in development. Its main goal is to practice the capabilities of Python on various platforms (web/mobile/desktop).

Dev environment installation

poetry install --with=dev

SeatsCounter:

from pyrlament import SeatsCounter
from pyrlament.data import Party

election2019 = {
    Party(name="PiS", support=43.59, threshold=8),
    Party(name="KO", support=27.4, threshold=8),
    Party(name="Lewica", support=12.56),
    Party(name="PSL", label="Polska 2050-PSL", support=10.8, threshold=8, color="DCB44B"),
    Party(name="Konfederacja", support=6.81),
}
election = SeatsCounter(parties=election2019)
election.count()

As a result of the operation of the count method, the parties parameter will contain information about the seats in the parliament, ex.:

for party in election.parties:
    print(f"{party.name}: {party.seats}")

...should print:

PiS: 235,
KO: 134,
Lewica: 49,
PSL: 30
Konfederacja: 11
Mniejszość niemiecka: 1

SeatsGenerator:

from pyrlament import SeatsGenerator 

g = SeatsGenerator(parties=election.parties)
g.randomize()
with open('pyrlament.svg', 'w') as f:
    f.write(g.svg())

SVG example:

pyRLAMENT example

PNG example:

pyRLAMENT example

Tests coverage

poetry run coverage report --format=markdown
Name Stmts Miss Cover
pyrlament/__init__.py 4 0 100%
pyrlament/configs.py 12 0 100%
pyrlament/counter.py 98 1 99%
pyrlament/data.py 67 0 100%
pyrlament/generator.py 306 104 66%
TOTAL 487 105 78%

Implemented and planned features

Here are my plans (some already implemented) for this library:

  • count seats basing on election support
  • cover code with unit tests
  • 5% and 8% support threshold
  • validate support does not reach 100%
  • draw svg with seats
  • randomise seats colors
  • split seats between parties
  • svg/png output
  • build webapp using Flask
  • improve seats drwaing and placement (it's buggy)
  • command line interface for library
  • build mobile/desktop app using Kivy

Packages

 
 
 

Contributors