From 56421820bb976fe85735730b3ba2e32b86b07d6a Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 4 Nov 2018 00:02:48 -0700 Subject: [PATCH] Add pagerank bottom statistic --- src/build.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/build.py b/src/build.py index ca41c0b..39e535a 100644 --- a/src/build.py +++ b/src/build.py @@ -211,17 +211,17 @@ def build_statistics_page(page, articles): for citation in addendum.citations: addendum_title = "{0.title}-T{0.turn}".format(addendum) G.add_edge(addendum_title, citation.target) - rank_by_article = networkx.pagerank(G) + rank_by_article_all = networkx.pagerank(G) players = sorted(set([article.player for article in articles if article.player is not None])) pagerank_by_player = {player: 0 for player in players} for article in articles: if article.player is not None: - pagerank_by_player[article.player] += (rank_by_article[article.title] - if article.title in rank_by_article else 0) + pagerank_by_player[article.player] += (rank_by_article_all[article.title] + if article.title in rank_by_article_all else 0) for addendum in article.addendums: addendum_title = "{0.title}-T{0.turn}".format(addendum) - pagerank_by_player[addendum_title] += (rank_by_article[addendum_title] - if addendum_title in rank_by_article else 0) + pagerank_by_player[addendum_title] += (rank_by_article_all[addendum_title] + if addendum_title in rank_by_article_all else 0) for player in players: pagerank_by_player[player] = round(pagerank_by_player[player], 3) player_rank = reverse_statistics_dict(pagerank_by_player) @@ -258,6 +258,17 @@ def build_statistics_page(page, articles): content += "
\n".join(cited_times_items) content += "\n" + # Lowest pagerank + pageranks = reverse_statistics_dict(rank_by_article) + bot_ranked = list(enumerate(map(lambda x: x[1], pageranks), start=1))[-10:] + # Format the ranks into strings + bot_ranked_items = itemize(bot_ranked) + content += "
\n" + content += "Bottom 10 articles by pagerank:
\n" + content += "
\n".join(bot_ranked_items) + content += "
\n" + + # Fill in the entry skeleton return page.format(title="Statistics", content=content)