Skip to content

Commit

Permalink
Attempt to improve server sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Jan 9, 2015
1 parent c9c97b0 commit f7a4481
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions server.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
import os, sys, json, time, socket
from threading import Thread, RLock
from operator import itemgetter

from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask, request, send_from_directory
Expand Down Expand Up @@ -281,8 +280,38 @@ def removeServer(self, server):
pass

def sort(self):
def server_points(server):
points = 0

# 1 per client
# Only 1/16 per client with a guest or all-numeric name
for name in server["clients_list"]:
if name.startswith("Guest") or \
name.isdigit():
points += 1/16
else:
points += 1

# 1 per month of age, limited to 8
points += min(8, server["game_time"] / (60*60*24*30))

# -8 for unrealistic max_clients
if server["max_clients"] >= 128:
points -= 8

# -8 per second of ping
points -= server["ping"] * 8

# Up to -8 for less than an hour of uptime (penalty linearly decreasing)
HOUR_SECS = 60 * 60
uptime = server["uptime"]
if uptime < HOUR_SECS:
points -= ((HOUR_SECS - uptime) / HOUR_SECS) * 8

return points

with self.lock:
self.list.sort(key=itemgetter("clients", "start"), reverse=True)
self.list.sort(key=server_points, reverse=True)

def purgeOld(self):
with self.lock:
Expand Down Expand Up @@ -339,7 +368,6 @@ def update(self, server):

serverList = ServerList()


if __name__ == "__main__":
app.run(host = app.config["HOST"], port = app.config["PORT"])

0 comments on commit f7a4481

Please sign in to comment.