Commit 1967c6dc authored by Dominique Merle's avatar Dominique Merle
Browse files

Improve the merit profiles graph.

Peer-session ! \o/  IOTH
Going to watch Steven's birthdays now.
parent e619d18f
...@@ -13,3 +13,7 @@ Timestamp,Tyran Sanguinaire,Chien,Écologiste Décroissant,Capitaliste Prédateu ...@@ -13,3 +13,7 @@ Timestamp,Tyran Sanguinaire,Chien,Écologiste Décroissant,Capitaliste Prédateu
12/9/2019 11:36:07,à rejeter,passable,assez bien,à rejeter,très bien,passable,insuffisant⋅e,assez bien,bien 12/9/2019 11:36:07,à rejeter,passable,assez bien,à rejeter,très bien,passable,insuffisant⋅e,assez bien,bien
12/10/2019 5:33:59,à rejeter,à rejeter,excellent⋅e,à rejeter,à rejeter,à rejeter,à rejeter,excellent⋅e,assez bien 12/10/2019 5:33:59,à rejeter,à rejeter,excellent⋅e,à rejeter,à rejeter,à rejeter,à rejeter,excellent⋅e,assez bien
12/10/2019 13:50:28,à rejeter,à rejeter,bien,à rejeter,assez bien,à rejeter,à rejeter,bien,insuffisant⋅e 12/10/2019 13:50:28,à rejeter,à rejeter,bien,à rejeter,assez bien,à rejeter,à rejeter,bien,insuffisant⋅e
12/14/2019 1:50:11,à rejeter,excellent⋅e,très bien,à rejeter,insuffisant⋅e,insuffisant⋅e,à rejeter,insuffisant⋅e,passable
1/8/2020 19:52:54,à rejeter,passable,bien,insuffisant⋅e,très bien,passable,insuffisant⋅e,très bien,passable
1/9/2020 0:09:48,à rejeter,à rejeter,excellent⋅e,à rejeter,très bien,à rejeter,à rejeter,très bien,bien
1/11/2020 18:09:23,à rejeter,à rejeter,,à rejeter,passable,à rejeter,à rejeter,insuffisant⋅e,assez bien
...@@ -292,11 +292,11 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None): ...@@ -292,11 +292,11 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None):
:param filename: String, should match `*.png` or `*.pdf`. Paths are allowed. :param filename: String, should match `*.png` or `*.pdf`. Paths are allowed.
""" """
pprint(judgments_tallies) # pprint(judgments_tallies)
pprint("candidates") # pprint("candidates")
pprint(candidates) # pprint(candidates)
pprint("mentions") # pprint("mentions")
pprint(mentions) # pprint(mentions)
bar_girth = 0.62 bar_girth = 0.62
candidates = [c for c in reversed(candidates)] # :(|) oOoK candidates = [c for c in reversed(candidates)] # :(|) oOoK
...@@ -350,6 +350,7 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None): ...@@ -350,6 +350,7 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None):
# vlorp = 0.05 # vlorp = 0.05
barhs = [] barhs = []
legends = [] legends = []
separators = []
ind = [i for i in range(candidates_amount)] ind = [i for i in range(candidates_amount)]
leftOffset = (0,) * candidates_amount leftOffset = (0,) * candidates_amount
judgments_sum = (0,) * candidates_amount judgments_sum = (0,) * candidates_amount
...@@ -358,7 +359,7 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None): ...@@ -358,7 +359,7 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None):
judgments_sum = tuple(p + q for p, q in zip(opinion, judgments_sum)) judgments_sum = tuple(p + q for p, q in zip(opinion, judgments_sum))
judgments_count = max(judgments_sum) judgments_count = max(judgments_sum)
vlorp = judgments_count * 0.003 vlorp = judgments_count * 0.003 * 0
for i, mention in enumerate(mentions): for i, mention in enumerate(mentions):
#print(u"Plotting bars of mention %s…" % mention) #print(u"Plotting bars of mention %s…" % mention)
...@@ -366,9 +367,17 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None): ...@@ -366,9 +367,17 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None):
barh = plt.barh(ind, opinion, bar_girth, left=leftOffset, color=colors[i]) barh = plt.barh(ind, opinion, bar_girth, left=leftOffset, color=colors[i])
barhs.append(barh) barhs.append(barh)
legends.append(barh[0]) legends.append(barh[0])
if i > 0:
for j, offset in enumerate(leftOffset):
separators.append([
(offset, j-0.5),
(offset, j+0.5),
])
# At some point, we should either go full numpy or not at all # At some point, we should either go full numpy or not at all
# The vlorp is a nasty hack to show white separators between colors # The vlorp is a nasty hack to show white separators between colors
leftOffset = tuple(p + q + vlorp for p, q in zip(opinion, leftOffset)) leftOffset = tuple(p + q + (vlorp if p else 0) for p, q in zip(opinion, leftOffset))
# p1 = plt.barh(ind, menMeans, bar_girth) # p1 = plt.barh(ind, menMeans, bar_girth)
# p2 = plt.barh(ind, womenMeans, bar_girth, left=menMeans) # p2 = plt.barh(ind, womenMeans, bar_girth, left=menMeans)
...@@ -392,6 +401,17 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None): ...@@ -392,6 +401,17 @@ def plot_merit_profile(judgments_tallies, candidates, mentions, filename=None):
bbox_to_anchor=(0.5, -0.15), bbox_to_anchor=(0.5, -0.15),
) )
from matplotlib.collections import LineCollection
# lines = [[(10.0,1.0), (0.0,0.0)]]
lc = LineCollection(separators,
colors=((1,1,1,1),),
linewidths=2,
)
# fig, ax = plt.subplots()
# ax.add_collection(lc)
plt.gca().add_collection(lc)
plt.axvline(x=adjusted_width*0.5, linestyle='--') plt.axvline(x=adjusted_width*0.5, linestyle='--')
# ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05, fancybox=True, shadow=True, ncol=5) # ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05, fancybox=True, shadow=True, ncol=5)
......
...@@ -69,8 +69,7 @@ EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT ...@@ -69,8 +69,7 @@ EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT
self.assertEqual(deliberation, ['B', 'D', 'A', 'C']) self.assertEqual(deliberation, ['B', 'D', 'A', 'C'])
def test_plotting_deliberation_with_merit_profiles(self):
def test_plotting_deliberation(self):
mentions = load_mentions_from_string(self.test_mentions) mentions = load_mentions_from_string(self.test_mentions)
judgments = '' judgments = ''
with open("examples/judgments_01.csv") as sample: with open("examples/judgments_01.csv") as sample:
...@@ -78,8 +77,25 @@ EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT ...@@ -78,8 +77,25 @@ EXCELLENT, EXCELLENT, EXCELLENT, EXCELLENT
deliberation, tally = deliberate(judgments, self.test_mentions) deliberation, tally = deliberate(judgments, self.test_mentions)
plot_merit_profile(tally, deliberation, mentions, filename="test_plot.png") plot_merit_profile(tally, deliberation, mentions, filename="test_plot.png")
# self.assertEqual(deliberation, ['B', 'D', 'A', 'C'])
def test_plotting_deliberation_02_with_merit_profiles(self):
# mentions = load_mentions_from_string(self.test_mentions)
mentions = (
u"excellent⋅e",
u"très bien",
u"bien",
u"assez bien",
u"passable",
u"insuffisant⋅e",
u"à rejeter",
)
judgments = ''
with open("examples/judgments_02.csv") as sample:
judgments = "".join(sample.readlines())
deliberation, tally = deliberate(judgments, mentions, skip_cols=1)
filename = "merit_profiles_02.png"
plot_merit_profile(tally, deliberation, mentions, filename=filename)
# def test_raise(self): # def test_raise(self):
# with self.assertRaises(TypeError): # with self.assertRaises(TypeError):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment