ecclesia
Version:
Framework for political and electoral simulations
1 lines • 1.45 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/election/attribution/metrics.ts"],"sourcesContent":["import { type Counter } from \"@gouvernathor/python/collections\";\nimport { type Simple } from \"../ballots\";\n\nexport interface DisproportionMetric<Party> {\n (p0: {votes: Simple<Party>, seats: Counter<Party>}): number;\n}\n\n/**\n * Returns the mean value (across all candidates) of the absolute difference\n * between the theoretical, (f)ra(c)tional number of seats and the allocated number of seats.\n * The bigger, the less proportional.\n *\n * Compared to a sum or mean of absolute differences of percentage,\n * this\n */\nexport function defaultMetric<Party>(\n { votes, seats }: {\n votes: Simple<Party>,\n seats: Counter<Party>,\n }\n): number {\n const allVotes = votes.total;\n const allSeats = seats.total;\n let suum = 0;\n for (const party of seats.keys()) {\n const partyVotes = votes.get(party)!;\n const partySeats = seats.get(party)!;\n suum += Math.abs(allSeats * partyVotes / allVotes - partySeats);\n }\n return suum / seats.size;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,cACZ,EAAE,OAAO,MAAM,GAIT;AACN,QAAM,WAAW,MAAM;AACvB,QAAM,WAAW,MAAM;AACvB,MAAI,OAAO;AACX,aAAW,SAAS,MAAM,KAAK,GAAG;AAC9B,UAAM,aAAa,MAAM,IAAI,KAAK;AAClC,UAAM,aAAa,MAAM,IAAI,KAAK;AAClC,YAAQ,KAAK,IAAI,WAAW,aAAa,WAAW,UAAU;AAAA,EAClE;AACA,SAAO,OAAO,MAAM;AACxB;","names":[]}