Skip to content

Commit

Permalink
List of users with similar Elo scores completed
Browse files Browse the repository at this point in the history
  • Loading branch information
vthorsteinsson committed Jul 28, 2015
1 parent 5c2c740 commit aee45b6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
11 changes: 10 additions & 1 deletion netskrafl.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,18 @@ def _userlist(range_from, range_to):

result = []

def elo_str(elo):
""" Return a string representation of an Elo score, or a hyphen if none """
return unicode(elo) if elo else u"-"

if range_from == u"robots" and not range_to:
# Return the list of available autoplayers
for r in Game.AUTOPLAYERS:
result.append({
"userid": u"robot-" + str(r[2]),
"nick": r[0],
"fullname": r[1],
"human_elo": elo_str(None),
"fav": False,
"chall": False,
"fairplay": False, # The robots don't play fair ;-)
Expand Down Expand Up @@ -239,6 +244,7 @@ def _userlist(range_from, range_to):
"userid": uid,
"nick": lu.nickname(),
"fullname": lu.full_name(),
"human_elo": elo_str(lu.human_elo()),
"fav": False if cuser is None else cuser.has_favorite(uid),
"chall": chall,
"fairplay": lu.fairplay(),
Expand All @@ -258,6 +264,7 @@ def _userlist(range_from, range_to):
"userid": favid,
"nick": fu.nickname(),
"fullname": fu.full_name(),
"human_elo": elo_str(fu.human_elo()),
"fav": True,
"chall": chall,
"fairplay": fu.fairplay(),
Expand All @@ -280,6 +287,7 @@ def _userlist(range_from, range_to):
"userid": uid,
"nick": au.nickname(),
"fullname": au.full_name(),
"human_elo": elo_str(au.human_elo()),
"fav": False if cuser is None else cuser.has_favorite(uid),
"chall": chall,
"fairplay": au.fairplay(),
Expand All @@ -291,7 +299,7 @@ def _userlist(range_from, range_to):
# Return users within a particular nickname range

# The "N:" prefix is a version header
cache_range = "2:" + (range_from or "") + "-" + (range_to or "")
cache_range = "3:" + (range_from or "") + "-" + (range_to or "")

# Start by looking in the cache
i = memcache.get(cache_range, namespace="userlist")
Expand All @@ -316,6 +324,7 @@ def displayable(ud):
"userid": uid,
"nick": ud["nickname"],
"fullname": User.full_name_from_prefs(ud["prefs"]),
"human_elo": elo_str(ud["human_elo"] or User.DEFAULT_ELO),
"fav": False if cuser is None else cuser.has_favorite(uid),
"chall": chall,
"fairplay": User.fairplay_from_prefs(ud["prefs"]),
Expand Down
5 changes: 2 additions & 3 deletions skrafldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def list(cls, nick_from, nick_to, max_len = 100):
prefs = um.prefs,
timestamp = um.timestamp,
ready = um.ready,
ready_timed = um.ready_timed
ready_timed = um.ready_timed,
human_elo = um.human_elo
)
counter += 1
if max_len > 0 and counter >= max_len:
Expand Down Expand Up @@ -267,8 +268,6 @@ def fetch(q, max_len):
# Take as much slack as possible
ix = 0
# Concatenate the two slices into one result and return it
logging.info("Len_lower is {0}, len_higher {1}, half_len {2}, ix {3}"
.format(len_lower, len_higher, half_len, ix))
assert max_len >= (len_lower - ix)
result = lower[ix:] + higher[0:max_len - (len_lower - ix)]
return result
Expand Down
15 changes: 11 additions & 4 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,22 @@ function populateUserList(json) {
(item.chall ? "'" : " grayed'") +
" id='" + chId + "'></span>";
var nick = escapeHtml(item.nick);
var alink = "", aclose = "", info = "", ready = "";
var alink = "", aclose = "", info = "", ready = "", elo = "";
var clsFullname = "list-fullname";
if (isRobot) {
// Mark robots with a cog icon
nick = "<span class='glyphicon glyphicon-cog'></span>&nbsp;" + nick;
// Put a hyperlink on the robot name and description
alink = "<a href='" + newgameUrl(item.userid, false) + "'>";
aclose = "</a>";
// Wider name column for robots
clsFullname = "list-fullname-robot";
}
else {
// Create a link to access user info
info = "<span id='usr" + i + "' class='usr-info'></span>";
// Show Elo points
elo = "<span class='list-human-elo'>" + item.human_elo + "</span>";
}
if (info.length)
info = "<span class='list-info' title='Skoða feril'>" + info + "</span>";
Expand All @@ -348,7 +353,8 @@ function populateUserList(json) {
"<span class='list-fav'>" + fav + "</span>" +
alink +
"<span class='list-nick'>" + nick + "</span>" +
"<span class='list-fullname'>" + ready + escapeHtml(item.fullname) + "</span>" +
"<span class='" + clsFullname + "'>" + ready + escapeHtml(item.fullname) + "</span>" +
elo +
aclose +
info +
"</div>";
Expand Down Expand Up @@ -525,8 +531,9 @@ function refreshUserList(ev) {
/* Range has x-y format */
toRange = range.charAt(2);
}
// Hide the user info button header if listing the robots
// Hide the Elo and user info button headers if listing the robots
$("#usr-list-info").css("visibility", (range == "robots") ? "hidden" : "visible");
$("#usr-list-elo").css("visibility", (range == "robots") ? "hidden" : "visible");
if (range == "elo")
serverQuery("/rating",
{
Expand Down Expand Up @@ -597,7 +604,7 @@ function populateGameList(json) {
"<span class='list-ts'>" + item.ts + "</span>" +
"<span class='list-opp' title='" + fullname + "'>" + opp + "</span>" +
"</a>" +
"<span class='list-info center'>" + info + "</span>" +
"<span class='list-info' title='Skoða feril'>" + info + "</span>" +
"<span class='list-s0'>" + item.sc0 + "</span>" +
"<span class='list-colon'>:</span>" +
"<span class='list-s1'>" + item.sc1 + "</span>" +
Expand Down
30 changes: 22 additions & 8 deletions static/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -1986,11 +1986,29 @@ span.list-opp {

span.list-fullname {
display: inline-block;
width: 468px;
max-width: 468px;
width: 425px;
max-width: 425px;
overflow: hidden;
}

span.list-fullname-robot {
display: inline-block;
width: 470px;
max-width: 470px;
overflow: hidden;
font-style: italic;
}

span.list-human-elo {
display: inline-block;
width: 40px;
max-width: 40px;
text-align: center;
font-weight: bold;
overflow: hidden;
margin-right: 6px;
}

span.list-duration {
display: inline-block;
width: 196px;
Expand All @@ -2003,24 +2021,20 @@ span.list-info-hdr {
display: inline-block;
width: 40px;
max-width: 40px;
text-align: right;
text-align: center;
overflow: hidden;
}

span.list-info {
display: inline-block;
width: 40px;
top: -3px;
text-align: right;
text-align: center;
height: 24px;
line-height: 20px;
overflow: hidden;
}

span.list-info.center {
text-align: center;
}

span.list-rank {
display: inline-block;
width: 32px;
Expand Down
1 change: 1 addition & 0 deletions templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
--></span><!--
--><span class="list-nick">Einkenni</span><!--
--><span class="list-fullname">Nafn og merki</span><!--
--><span class="list-human-elo" id="usr-list-elo">Elo</span><!--
--><span class="list-info-hdr" id="usr-list-info">Ferill</span><!--
--></div>

Expand Down

0 comments on commit aee45b6

Please sign in to comment.