Refactor 'author' to 'player' to remove ambiguity about player vs character
This commit is contained in:
parent
e13febb079
commit
4cdf2af13f
|
@ -8,7 +8,7 @@ class LexiconArticle:
|
||||||
A Lexicon article and its metadata.
|
A Lexicon article and its metadata.
|
||||||
|
|
||||||
Members:
|
Members:
|
||||||
author string: the author of the article
|
player string: the player of the article
|
||||||
turn integer: the turn the article was written for
|
turn integer: the turn the article was written for
|
||||||
title string: the article title
|
title string: the article title
|
||||||
title_filesafe string: the title, escaped, used for filenames
|
title_filesafe string: the title, escaped, used for filenames
|
||||||
|
@ -20,11 +20,11 @@ class LexiconArticle:
|
||||||
The last three are filled in by populate().
|
The last three are filled in by populate().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, author, turn, title, content, citations):
|
def __init__(self, player, turn, title, content, citations):
|
||||||
"""
|
"""
|
||||||
Creates a LexiconArticle object with the given parameters.
|
Creates a LexiconArticle object with the given parameters.
|
||||||
"""
|
"""
|
||||||
self.author = author
|
self.player = player
|
||||||
self.turn = turn
|
self.turn = turn
|
||||||
self.title = title
|
self.title = title
|
||||||
self.title_filesafe = utils.titleescape(title)
|
self.title_filesafe = utils.titleescape(title)
|
||||||
|
@ -44,12 +44,12 @@ class LexiconArticle:
|
||||||
if len(headers) != 4:
|
if len(headers) != 4:
|
||||||
print("Header read error")
|
print("Header read error")
|
||||||
return None
|
return None
|
||||||
author_header, turn_header, title_header, content_raw = headers
|
player_header, turn_header, title_header, content_raw = headers
|
||||||
# Validate and sanitize the author header
|
# Validate and sanitize the player header
|
||||||
if not author_header.startswith("# Author:"):
|
if not player_header.startswith("# Player:"):
|
||||||
print("Author header missing or corrupted")
|
print("Player header missing or corrupted")
|
||||||
return None
|
return None
|
||||||
author = author_header[9:].strip()
|
player = player_header[9:].strip()
|
||||||
# Validate and sanitize the turn header
|
# Validate and sanitize the turn header
|
||||||
if not turn_header.startswith("# Turn:"):
|
if not turn_header.startswith("# Turn:"):
|
||||||
print("Turn header missing or corrupted")
|
print("Turn header missing or corrupted")
|
||||||
|
@ -99,7 +99,7 @@ class LexiconArticle:
|
||||||
else:
|
else:
|
||||||
para = "<p>" + para + "</p>\n"
|
para = "<p>" + para + "</p>\n"
|
||||||
content += para
|
content += para
|
||||||
return LexiconArticle(author, turn, title, content, citations)
|
return LexiconArticle(player, turn, title, content, citations)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_from_directory(directory):
|
def parse_from_directory(directory):
|
||||||
|
@ -142,7 +142,7 @@ class LexiconArticle:
|
||||||
if target not in article_by_title:
|
if target not in article_by_title:
|
||||||
article_by_title[target] = LexiconArticle(None, sys.maxsize, target, "<p><i>This entry hasn't been written yet.</i></p>", {})
|
article_by_title[target] = LexiconArticle(None, sys.maxsize, target, "<p><i>This entry hasn't been written yet.</i></p>", {})
|
||||||
# Interlink citations
|
# Interlink citations
|
||||||
if article_by_title[target].author is None:
|
if article_by_title[target].player is None:
|
||||||
article.pcites.add(target)
|
article.pcites.add(target)
|
||||||
else:
|
else:
|
||||||
article.wcites.add(target)
|
article.wcites.add(target)
|
||||||
|
|
42
src/build.py
42
src/build.py
|
@ -13,7 +13,7 @@ def build_contents_page(articles, config):
|
||||||
"""
|
"""
|
||||||
content = ""
|
content = ""
|
||||||
# Article counts
|
# Article counts
|
||||||
phantom_count = len([article for article in articles if article.author is None])
|
phantom_count = len([article for article in articles if article.player is None])
|
||||||
if phantom_count == 0:
|
if phantom_count == 0:
|
||||||
content = "<p>There are <b>{0}</b> entries in this lexicon.</p>\n".format(len(articles))
|
content = "<p>There are <b>{0}</b> entries in this lexicon.</p>\n".format(len(articles))
|
||||||
else:
|
else:
|
||||||
|
@ -22,7 +22,7 @@ def build_contents_page(articles, config):
|
||||||
# Prepare article links
|
# Prepare article links
|
||||||
link_by_title = {article.title : "<a href=\"../article/{1}.html\"{2}>{0}</a>".format(
|
link_by_title = {article.title : "<a href=\"../article/{1}.html\"{2}>{0}</a>".format(
|
||||||
article.title, article.title_filesafe,
|
article.title, article.title_filesafe,
|
||||||
"" if article.author is not None else " class=\"phantom\"")
|
"" if article.player is not None else " class=\"phantom\"")
|
||||||
for article in articles}
|
for article in articles}
|
||||||
# Write the articles in alphabetical order
|
# Write the articles in alphabetical order
|
||||||
content += utils.load_resource("contents.html")
|
content += utils.load_resource("contents.html")
|
||||||
|
@ -47,7 +47,7 @@ def build_contents_page(articles, config):
|
||||||
content += "</ul>\n</div>\n"
|
content += "</ul>\n</div>\n"
|
||||||
# Write the articles in turn order
|
# Write the articles in turn order
|
||||||
content += "<div id=\"turn-order\" style=\"display:none\">\n<ul>\n"
|
content += "<div id=\"turn-order\" style=\"display:none\">\n<ul>\n"
|
||||||
latest_turn = max([article.turn for article in articles if article.author is not None])
|
latest_turn = max([article.turn for article in articles if article.player is not None])
|
||||||
turn_order = sorted(articles, key=lambda a: (a.turn, utils.titlecase(a.title)))
|
turn_order = sorted(articles, key=lambda a: (a.turn, utils.titlecase(a.title)))
|
||||||
check_off = list(turn_order)
|
check_off = list(turn_order)
|
||||||
for turn_num in range(1, latest_turn + 1):
|
for turn_num in range(1, latest_turn + 1):
|
||||||
|
@ -146,7 +146,7 @@ def build_statistics_page(articles, config):
|
||||||
content += "<br>\n".join(map(lambda x: "{0} – {1}".format(x[0]+1, x[1]), ranking[:10]))
|
content += "<br>\n".join(map(lambda x: "{0} – {1}".format(x[0]+1, x[1]), ranking[:10]))
|
||||||
content += "</p>\n"
|
content += "</p>\n"
|
||||||
content += "</div>\n"
|
content += "</div>\n"
|
||||||
# Top numebr of citations made
|
# Top number of citations made
|
||||||
content += "<div class=\"moveable\">\n"
|
content += "<div class=\"moveable\">\n"
|
||||||
content += "<p><u>Most citations made from:</u><br>\n"
|
content += "<p><u>Most citations made from:</u><br>\n"
|
||||||
citation_tally = [(kv[0], len(kv[1])) for kv in cite_map.items()]
|
citation_tally = [(kv[0], len(kv[1])) for kv in cite_map.items()]
|
||||||
|
@ -170,36 +170,38 @@ def build_statistics_page(articles, config):
|
||||||
sorted(cited_count.items(), reverse=True)[:3]))
|
sorted(cited_count.items(), reverse=True)[:3]))
|
||||||
content += "</p>\n"
|
content += "</p>\n"
|
||||||
content += "</div>\n"
|
content += "</div>\n"
|
||||||
# Author pageranks
|
# player pageranks
|
||||||
content += "<div class=\"moveable\">\n"
|
content += "<div class=\"moveable\">\n"
|
||||||
content += "<p><u>Author total page rank:</u><br>\n"
|
content += "<p><u>Player total page rank:</u><br>\n"
|
||||||
authors = sorted(set([article.author for article in articles if article.author is not None]))
|
players = sorted(set([article.player for article in articles if article.player is not None]))
|
||||||
articles_by = {author : [a for a in articles if a.author == author] for author in authors}
|
articles_by = {player : [a for a in articles if a.player == player] for player in players}
|
||||||
author_rank = {author : sum(map(lambda a: ranks[a.title], articles)) for author, articles in articles_by.items()}
|
player_rank = {player : sum(map(lambda a: ranks[a.title], articles)) for player, articles in articles_by.items()}
|
||||||
content += "<br>\n".join(map(
|
content += "<br>\n".join(map(
|
||||||
lambda kv: "{0} – {1}".format(kv[0], round(kv[1], 3)),
|
lambda kv: "{0} – {1}".format(kv[0], round(kv[1], 3)),
|
||||||
sorted(author_rank.items(), key=lambda t:-t[1])))
|
sorted(player_rank.items(), key=lambda t:t[1], reverse=True)))
|
||||||
content += "</p>\n"
|
content += "</p>\n"
|
||||||
content += "</div>\n"
|
content += "</div>\n"
|
||||||
# Author citations made
|
# Player citations made
|
||||||
content += "<div class=\"moveable\">\n"
|
content += "<div class=\"moveable\">\n"
|
||||||
content += "<p><u>Citations made by author</u><br>\n"
|
content += "<p><u>Citations made by player</u><br>\n"
|
||||||
author_cite_count = {author : sum(map(lambda a:len(a.wcites | a.pcites), articles)) for author, articles in articles_by.items()}
|
player_cite_count = {
|
||||||
|
player : sum(map(lambda a:len(a.wcites | a.pcites), articles))
|
||||||
|
for player, articles in articles_by.items()}
|
||||||
content += "<br>\n".join(map(
|
content += "<br>\n".join(map(
|
||||||
lambda kv: "{0} – {1}".format(kv[0], kv[1]),
|
lambda kv: "{0} – {1}".format(kv[0], kv[1]),
|
||||||
sorted(author_cite_count.items(), key=lambda t:-t[1])))
|
sorted(player_cite_count.items(), key=lambda t:t[1], reverse=True)))
|
||||||
content += "</p>\n"
|
content += "</p>\n"
|
||||||
content += "</div>\n"
|
content += "</div>\n"
|
||||||
# Author cited count
|
# player cited count
|
||||||
content += "<div class=\"moveable\">\n"
|
content += "<div class=\"moveable\">\n"
|
||||||
content += "<p><u>Citations made to author</u><br>\n"
|
content += "<p><u>Citations made to player</u><br>\n"
|
||||||
cited_times = {author : 0 for author in authors}
|
cited_times = {player : 0 for player in players}
|
||||||
for article in articles:
|
for article in articles:
|
||||||
if article.author is not None:
|
if article.player is not None:
|
||||||
cited_times[article.author] += len(article.citedby)
|
cited_times[article.player] += len(article.citedby)
|
||||||
content += "<br>\n".join(map(
|
content += "<br>\n".join(map(
|
||||||
lambda kv: "{0} – {1}".format(kv[0], kv[1]),
|
lambda kv: "{0} – {1}".format(kv[0], kv[1]),
|
||||||
sorted(cited_times.items(), key=lambda t:-t[1])))
|
sorted(cited_times.items(), key=lambda t:t[1], reverse=True)))
|
||||||
content += "</p>\n"
|
content += "</p>\n"
|
||||||
content += "</div>\n"
|
content += "</div>\n"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Author: AN
|
# Player: PN
|
||||||
# Turn: 1
|
# Turn: 1
|
||||||
# Title: Example page
|
# Title: Example page
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<p>Lexipython provides support for a limited amount of Markdown-esque formatting.</p>
|
<p>Lexipython provides support for a limited amount of Markdown-esque formatting.</p>
|
||||||
<pre style="background:#eeeeee">
|
<pre style="background:#eeeeee">
|
||||||
# Author: Authorname
|
# Player: PN
|
||||||
# Turn: 1
|
# Turn: 1
|
||||||
# Title: Example page
|
# Title: Example page
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ This is an [[example citation|Phantom page]]. You can also cite a [[phantom page
|
||||||
|
|
||||||
~Dr. X. Amplepage
|
~Dr. X. Amplepage
|
||||||
</pre>
|
</pre>
|
||||||
<p>Each turn, fill out the header with your author information, the current turn, and the title of your entry. It doesn't really matter what the <i>Author</i> field is, except that it must be the same across all articles you write.</p>
|
<p>Each turn, fill out the header with your player information, the current turn, and the title of your entry. The <i>Player</i> field can be anything as long as it's the same for all articles you write (even when they're by different characters). Using your initials is recommended.</p>
|
||||||
<p>Two line breaks begins a new paragraph. A single line break does nothing, unless the line is neded by a double backslash (\\).</p>
|
<p>Two line breaks begins a new paragraph. A single line break does nothing, unless the line is neded by a double backslash (\\).</p>
|
||||||
<p>Text bounded by ** will be bolded: **bold** produces <b>bold</b>. Text bounded by // will be italicized: //italics// produces <i>italics</i>.</p>
|
<p>Text bounded by ** will be bolded: **bold** produces <b>bold</b>. Text bounded by // will be italicized: //italics// produces <i>italics</i>.</p>
|
||||||
<p>To cite another Lexicon entry, use double brackets. Text in double brackets will cite and link to the entry of the same name: [[Example page]] produces <a href="Example_page.html" class="phantom">Example page</a>. Text in double brackets split with a | will alias the link as the left text and link to the entry with the name of the right text: [[this text|Example page]] produces <a href="Example_page.html" class="phantom">this text</a>. <b>You must be precise in the entry title you cite to.</b> Citations to "Example" vs. "The Example" will point to different entries and create different phantoms, and your GM will probably have to clean up after you.</p>
|
<p>To cite another Lexicon entry, use double brackets. Text in double brackets will cite and link to the entry of the same name: [[Example page]] produces <a href="Example_page.html" class="phantom">Example page</a>. Text in double brackets split with a | will alias the link as the left text and link to the entry with the name of the right text: [[this text|Example page]] produces <a href="Example_page.html" class="phantom">this text</a>. <b>You must be precise in the entry title you cite to.</b> Citations to "Example" vs. "The Example" will point to different entries and create different phantoms, and your GM will probably have to clean up after you.</p>
|
||||||
|
|
Loading…
Reference in New Issue