Skip to content

Commit

Permalink
⏪ Revert "🐛 Fix Deputes order by ratio"
Browse files Browse the repository at this point in the history
This reverts commit ca4488b.
  • Loading branch information
Striffly committed Jun 30, 2024
1 parent 780070a commit b054243
Showing 1 changed file with 7 additions and 31 deletions.
38 changes: 7 additions & 31 deletions frontend/src/components/ResultsDeputes.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
import data from "../data/data.json";

export default function ResultsDeputes({ results }) {
const getRatio = (id) => {
const positive = results?.deputesRaw?.[id]?.["+"] || 0;
const negative = results?.deputesRaw?.[id]?.["-"] || 0;

if (negative === 0 && positive > 0) return Number.POSITIVE_INFINITY;
if (negative === 0 && positive === 0) return -Number.POSITIVE_INFINITY;
if (positive === 0) return -1;

return positive / negative;
};

const deputesRatioSort = ([id_a], [id_b]) => {
return getRatio(id_b) - getRatio(id_a);
};

const deputesVotesSort = ([id_a], [id_b]) => {
const sum_a =
(results?.deputesRaw?.[id_a]?.["+"] || 0) +
(results?.deputesRaw?.[id_a]?.["-"] || 0);
const sum_b =
(results?.deputesRaw?.[id_b]?.["+"] || 0) +
(results?.deputesRaw?.[id_b]?.["-"] || 0);
return sum_b - sum_a;
};

return (
<div className="ResultsDeputes">
<div className="ResultsDeputes__explanation">
Expand All @@ -34,12 +9,13 @@ export default function ResultsDeputes({ results }) {
Trié par accords - désaccords.
</div>
{results.deputes
.sort(([id_a], [id_b]) => {
return deputesRatioSort([id_a], [id_b]);
})
.sort(([id_a], [id_b]) => {
return deputesVotesSort([id_a], [id_b]);
})
.sort(
([id_a], [id_b]) =>
results?.deputesRaw?.[id_b]?.["+"] -
results?.deputesRaw?.[id_b]?.["-"] -
(results?.deputesRaw?.[id_a]?.["+"] -
results?.deputesRaw?.[id_a]?.["-"]),
)
.map(([id, approval]) => (
<a
className="Result Result--simple"
Expand Down

0 comments on commit b054243

Please sign in to comment.