smari / voting

A simulator for voting systems.
27 stars 10 forks source link

`constituencies` not part of /api/capabilities/ response #11

Closed busla closed 7 years ago

busla commented 7 years ago

Hey all,

Fixed a few issues to get the frontend working, see https://github.com/smari/voting/pull/10

The bakend doesn´t seem to return the constituency array required for the frontend to render VotesTable.

The setPreset func asks for a constituency property which is not part of the response:

https://github.com/smari/voting/blob/master/voting/static/js/ui.js#L584

Output from /api/capabilities/

{
  "key": 1,
  "rules": {},
  "election_rules": {
    "primary_divider": "dhondt",
    "adjustment_divider": "dhondt",
    "adjustment_threshold": 0.05,
    "adjustment_method": "icelandic-law",
    "constituency_seats": [
      7,
      9,
      9,
      11,
      9,
      9
    ],
    "constituency_adjustment_seats": [
      1,
      1,
      1,
      2,
      2,
      2
    ],
    "constituency_names": [
      "Norðvestur",
      "Norðaustur",
      "Suður",
      "Suðvestur",
      "Reykjavík suður",
      "Reykjavík norður"
    ],
    "parties": [
      "A",
      "B",
      "D",
      "G",
      "H",
      "I",
      "J",
      "K",
      "L",
      "M",
      "R",
      "S",
      "T",
      "V",
      "Þ"
    ],
    "votes": [
      [
        792,
        6104,
        4282,
        208,
        0,
        161,
        774,
        0,
        251,
        326,
        0,
        2122,
        328,
        1470,
        537
      ],
      [
        1537,
        8173,
        5327,
        296,
        0,
        241,
        306,
        0,
        313,
        0,
        0,
        2505,
        460,
        3733,
        716
      ],
      [
        1202,
        9265,
        7596,
        703,
        0,
        786,
        412,
        0,
        431,
        0,
        0,
        2734,
        904,
        1582,
        1269
      ],
      [
        4687,
        10944,
        15608,
        925,
        0,
        1838,
        188,
        0,
        1241,
        0,
        0,
        6932,
        1927,
        3995,
        2541
      ],
      [
        3790,
        5931,
        9466,
        575,
        55,
        1394,
        161,
        222,
        1025,
        0,
        54,
        5007,
        1163,
        4279,
        2179
      ],
      [
        3576,
        5759,
        8187,
        556,
        71,
        1289,
        181,
        0,
        1398,
        0,
        64,
        4996,
        1073,
        5493,
        2407
      ]
    ],
    "simulate": false,
    "debug": false,
    "show_entropy": false,
    "output": "simple"
  },
  "simulation_rules": {
    "simulate": false,
    "simulation_count": 100,
    "simulation_variate": "beta"
  },
  "presets": [
    {
      "name": "Icelandic Parliament election 2013",
      "action": "election",
      "election_rules": {
        "primary_divider": "dhondt",
        "adjustment_divider": "dhondt",
        "adjustment_threshold": 0.05,
        "adjustment_method": "icelandic-law",
        "constituency_seats": [
          7,
          9,
          9,
          11,
          9,
          9
        ],
        "constituency_adjustment_seats": [
          1,
          1,
          1,
          2,
          2,
          2
        ],
        "constituency_names": [
          "Norðvestur",
          "Norðaustur",
          "Suður",
          "Suðvestur",
          "Reykjavík suður",
          "Reykjavík norður"
        ],
        "parties": [
          "A",
          "B",
          "D",
          "G",
          "H",
          "I",
          "J",
          "K",
          "L",
          "M",
          "R",
          "S",
          "T",
          "V",
          "Þ"
        ],
        "votes": [
          [
            792,
            6104,
            4282,
            208,
            0,
            161,
            774,
            0,
            251,
            326,
            0,
            2122,
            328,
            1470,
            537
          ],
          [
            1537,
            8173,
            5327,
            296,
            0,
            241,
            306,
            0,
            313,
            0,
            0,
            2505,
            460,
            3733,
            716
          ],
          [
            1202,
            9265,
            7596,
            703,
            0,
            786,
            412,
            0,
            431,
            0,
            0,
            2734,
            904,
            1582,
            1269
          ],
          [
            4687,
            10944,
            15608,
            925,
            0,
            1838,
            188,
            0,
            1241,
            0,
            0,
            6932,
            1927,
            3995,
            2541
          ],
          [
            3790,
            5931,
            9466,
            575,
            55,
            1394,
            161,
            222,
            1025,
            0,
            54,
            5007,
            1163,
            4279,
            2179
          ],
          [
            3576,
            5759,
            8187,
            556,
            71,
            1289,
            181,
            0,
            1398,
            0,
            64,
            4996,
            1073,
            5493,
            2407
          ]
        ],
        "simulate": false,
        "debug": false,
        "show_entropy": false,
        "output": "simple"
      }
    }
  ],
  "capabilities": {
    "adjustment_methods": {
      "alternating-scaling": "Alternating-Scaling Method",
      "icelandic-law": "Icelandic law 24/2000 (Kosningar til Alþingis)",
      "monge": "Monge algorithm",
      "relative-inferiority": "Relative Inferiority Method",
      "relative-superiority": "Relative Superiority Method"
    },
    "divider_rules": {
      "dhondt": "D'Hondt's method",
      "sainte-lague": "Sainte-Laguë method",
      "swedish": "Nordic Sainte-Laguë variant"
    }
  },
  "capabilities_loaded": true,
  "votes": []
}
busla commented 7 years ago

Ok, seems that constituencies is now constituency_names

busla commented 7 years ago

.. and I was wrong, I´m mixing up presets and adding data with the form. I haven´t touched the form and only trying to get the presets work.

The constituency object is built when added in the UI but not when loading a preset, so no wonder why it´s not there.

busla commented 7 years ago

Closing since rendering preset data in the UI is more of an uncompleted task.