A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.5 KiB

feat: Majority Judgment Polls (2020) Add `Poll` model and `CreatePoll` function. The poll is ineffective, no one can vote. (yet) Add `Judgment` creation and update. There can be at most one judgment per trio of poll, judge and candidate. Each Judge may emit one Judgment per Candidate of a Poll. Mop up and oust a reminiscent bug. Add the Poll Create, Update and Delete forms and logic. We can't tally a Poll yet. Nor can we judge issues. Add the Judgment forms for each Poll of each issue. Everything works so far without javascript. We added CSS like monkeys, until we figure out what to do with it. Use emotes Chromium can print as well. Fix some warnings. Prepare for the far future. Add scoring pseudo-code for fast deliberation. This was entertaining, but it's perhaps wrong, although we can't find any reason why so far. We contacted the world's top specialist on the matter. … Three gods, A, B, and C are called, in no particular order, True, False, and Random. True always speaks truly, False always speaks falsely, but whether Random speaks truly or falsely is a completely random matter. Your task is to determine the identities of A, B, and C by asking three yes-no questions; each question must be put to exactly one god. The gods understand English, but will answer all questions in their own language, in which the words for yes and no are da and ja, in some order. You do not know which word means which. Add a naive tallier. I wish I had a feature suite in Gherkin here… Add some tests to the deliberator and implement them. Still waiting for input from the specialist(s) before delving into implementation details. Use unsigned integers where it makes sense. (or not) Provision more tests for the deliberator. We've got some answers — still confused, though. Implement a very naive deliberator. Fix a fix for the label's hover area. Let's barf as little as possible on existing CSS. Fill the missing judgments as REJECT judgments. This should be optional. Add a battery of tests to GetMedian We're now going to be able to implement it properly, not like the cheap cheat we had so far. Adapt label color to median grade. This is a cheap implementation that will probably need a rewrite for complete support of other gradations. Add more tests to expose the limitations of the current scoring implementation. Now we can work some more on the scoring. Implement a less naive score calculus. So far it holds. The score is a bit long (90chars = 15 chars per possible grade) but it won't get any longer with more judges, unless we have to go over 500 billion judges. Fix poll's CRUD subheaders I18N. Make sure judgments can be emitted with keyboard only. `:focus-within` <3 U CSS Add a basic page to view a poll. Move Poll CSS to LESS. Clean up. Tease about what will come next. Add a repo header nav item for polls. Ideally this whole thing should be a plugin and not a fork. Not sure how to add new Db models and Routes. We'd also need a custom spot in the issue view template, but that can probably be merged upstream. Clean up. We'd love to move the routes to their own file. And then being able to add them via `custom/`. Disable event sourcing until /user/events do not hang for a minute, because it makes browsing gitea rapidly impossible. Add french translations for the polling UI. Rename `Judgment` into `PollJudgment`. After careful consideration, it's probably best to namespace. Also, explicit is better than implicit. :) BREAKING CHANGE: Not sure how the migrations will operate here. This is why it's best to do it now than once we're actually using it. Tweak the poll's labels for mobile with a CSS media query. Thanks @pierre-louis for the bug report ! Review. docs: explicit is better than implicit chore: "missing" is more explicit than "lost" feat: add radial merit profiles, in SVG Ignore the gitea-repositories directory. chore: clean up the radial merit profile SVG template test: expose an issue with the tally The returned amounts for each grade are wrong. How could this happen, you ask? Lack of unit-testing, that's why! (also, shallow copy shenanigans) chore: spacing Still experimenting with the spacing in templates. I know Gitea does not use spaces. My sight is not getting any better, and spacing helps a lot. Yes, I'm already using bigger fonts. test: refine the tests about the critical bug found … so that it does not happen again! fix: elbow grease the copy mechanism to fix The Bug® fix: hide the description if none is provided. Should we mention that it is a bad practice ? It feels like it is. … To deliberate. chore: review naive deliberator feat: add the issue title to the list of issues of a poll Also naive and inefficient, but if we paginate, we'll be ok. And if not, we can probably improve this by batching the queries. fix: remove a debugging tweak that was overlooked Also, remove the need to translate the word `Issue`. Oddly enough, it is never translated by itself, it is only in plural form opr inside a sentence. feat: add the merit profile behind the median grade Usual CSS woes - Really not confident about positioning top and left with `em`. - Z-index shenanigans to skip unexpected offset in positioning, where the absolute of a child in a relative container won't point to top left but to bottom of other child in static (try moving the merit profile below the input.emote, and remove z-indices) Right now the merit profile is shown to all logged in, whether they judged or not. This is not the intended final behavior. Ideally we'd have settings fdr this. chore: clean up before the next stage
2 years ago
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. //"sort"
  7. "testing"
  8. //"time"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestNaiveDeliberator(t *testing.T) {
  12. assert.NoError(t, PrepareTestDatabase())
  13. repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
  14. userAli := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
  15. userBob := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
  16. userCho := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
  17. poll, err := CreatePoll(&CreatePollOptions{
  18. Repo: repo,
  19. Author: userAli,
  20. Subject: "Demand",
  21. })
  22. assert.NoError(t, err)
  23. assert.NotNil(t, poll)
  24. pnd := &PollNaiveDeliberator{}
  25. // No judgments yet
  26. result, err := pnd.Deliberate(poll)
  27. assert.NoError(t, err)
  28. assert.NotNil(t, result)
  29. assert.NotNil(t, result.Poll)
  30. assert.Equal(t, poll, result.Poll)
  31. assert.NotNil(t, result.Tally)
  32. assert.NotNil(t, result.Candidates)
  33. assert.Len(t, result.Candidates, 0)
  34. // Add a Judgment from Ali
  35. // Candidate 1 : SOMEWHAT_GOOD
  36. // Candidate 2 :
  37. judgment, err := CreateJudgment(&CreateJudgmentOptions{
  38. Judge: userAli,
  39. Poll: poll,
  40. Grade: 3,
  41. CandidateID: 1,
  42. })
  43. assert.NoError(t, err)
  44. assert.NotNil(t, judgment)
  45. result, err = pnd.Deliberate(poll)
  46. assert.NoError(t, err)
  47. assert.NotNil(t, result)
  48. assert.NotNil(t, result.Tally)
  49. assert.NotNil(t, result.Candidates)
  50. assert.Len(t, result.Candidates, 1)
  51. // Add a judgment from Bob
  52. // Candidate 1 : PASSABLE SOMEWHAT_GOOD
  53. // Candidate 2 :
  54. judgment, err = CreateJudgment(&CreateJudgmentOptions{
  55. Judge: userBob,
  56. Poll: poll,
  57. Grade: 2,
  58. CandidateID: 1,
  59. })
  60. assert.NoError(t, err)
  61. assert.NotNil(t, judgment)
  62. result, err = pnd.Deliberate(poll)
  63. assert.NoError(t, err)
  64. assert.NotNil(t, result)
  65. assert.NotNil(t, result.Tally)
  66. assert.NotNil(t, result.Candidates)
  67. assert.Len(t, result.Candidates, 1)
  68. assert.Equal(t, uint64(1), result.Candidates[0].Position)
  69. // Add another judgment from Bob
  70. // Candidate 1 : PASSABLE SOMEWHAT_GOOD
  71. // Candidate 2 : GOOD
  72. judgment, err = CreateJudgment(&CreateJudgmentOptions{
  73. Judge: userBob,
  74. Poll: poll,
  75. Grade: 4,
  76. CandidateID: 2,
  77. })
  78. assert.NoError(t, err)
  79. assert.NotNil(t, judgment)
  80. result, err = pnd.Deliberate(poll)
  81. assert.NoError(t, err)
  82. assert.NotNil(t, result)
  83. assert.NotNil(t, result.Candidates)
  84. assert.Len(t, result.Candidates, 2)
  85. assert.Equal(t, uint64(1), result.Candidates[0].Position)
  86. assert.Equal(t, uint64(2), result.Candidates[1].Position)
  87. assert.Equal(t, int64(1), result.Candidates[0].CandidateID)
  88. assert.Equal(t, int64(2), result.Candidates[1].CandidateID)
  89. assert.Equal(t, uint8(2), result.Candidates[0].MedianGrade)
  90. assert.Equal(t, uint8(0), result.Candidates[1].MedianGrade)
  91. // Add another 2 judgments from Cho and one from Ali
  92. // Candidate 1 : PASSABLE SOMEWHAT_GOOD GOOD
  94. judgment, err = CreateJudgment(&CreateJudgmentOptions{
  95. Judge: userCho,
  96. Poll: poll,
  97. Grade: 4,
  98. CandidateID: 1,
  99. })
  100. assert.NoError(t, err)
  101. assert.NotNil(t, judgment)
  102. judgment, err = CreateJudgment(&CreateJudgmentOptions{
  103. Judge: userCho,
  104. Poll: poll,
  105. Grade: 3,
  106. CandidateID: 2,
  107. })
  108. assert.NoError(t, err)
  109. assert.NotNil(t, judgment)
  110. judgment, err = CreateJudgment(&CreateJudgmentOptions{
  111. Judge: userAli,
  112. Poll: poll,
  113. Grade: 3,
  114. CandidateID: 2,
  115. })
  116. assert.NoError(t, err)
  117. assert.NotNil(t, judgment)
  118. result, err = pnd.Deliberate(poll)
  119. assert.NoError(t, err)
  120. assert.NotNil(t, result)
  121. assert.NotNil(t, result.Candidates)
  122. assert.Len(t, result.Candidates, 2)
  123. assert.Equal(t, uint64(1), result.Candidates[0].Position)
  124. assert.Equal(t, uint64(2), result.Candidates[1].Position)
  125. assert.Equal(t, int64(2), result.Candidates[0].CandidateID)
  126. assert.Equal(t, int64(1), result.Candidates[1].CandidateID)
  127. //println("C1", result.Candidates[1].MedianGrade)
  128. assert.Equal(t, uint8(3), result.Candidates[0].MedianGrade)
  129. assert.Equal(t, uint8(3), result.Candidates[1].MedianGrade)
  130. assert.Equal(t, uint64(1), result.Candidates[0].Tally.Grades[4].Amount)
  131. assert.Equal(t, uint64(2), result.Candidates[0].Tally.Grades[3].Amount)
  132. assert.Equal(t, uint64(1), result.Candidates[1].Tally.Grades[2].Amount)
  133. assert.Equal(t, uint64(1), result.Candidates[1].Tally.Grades[3].Amount)
  134. assert.Equal(t, uint64(1), result.Candidates[1].Tally.Grades[4].Amount)
  135. }