]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Move MapCapTime and PlayerCapTime to models.
authorAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jan 2016 22:36:56 +0000 (17:36 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sat, 16 Jan 2016 22:36:56 +0000 (17:36 -0500)
The more I thought about it, the more I think that these two classes should
live inside the models module. They are nothing more than models for views. So
what if they aren't object-relational!

xonstat/models.py
xonstat/views/map.py
xonstat/views/player.py

index a8de35a489fc77815ea5334ceb2b1e60ee99c999..e34a2950c6fd0ce4087cb0897bc3ebcdf1558a57 100644 (file)
@@ -333,6 +333,62 @@ class PlayerGroups(object):
         return "<PlayerGroups(%s, %s)>" % (self.player_id, self.group_name)
 
 
+class MapCapTime(object):
+    """Fastest flag capture times per map, assembled from a SQLAlchemy query"""
+    def __init__(self, row):
+        self.fastest_cap          = row.fastest_cap
+        self.create_dt            = row.create_dt
+        self.create_dt_epoch      = timegm(row.create_dt.timetuple())
+        self.create_dt_fuzzy      = pretty_date(row.create_dt)
+        self.player_id            = row.player_id
+        self.player_nick          = row.player_nick
+        self.player_nick_stripped = strip_colors(row.player_nick)
+        self.player_nick_html     = html_colors(row.player_nick)
+        self.game_id              = row.game_id
+        self.server_id            = row.server_id
+        self.server_name          = row.server_name
+
+    def to_dict(self):
+        return {
+            "fastest_cap"          : self.fastest_cap.total_seconds(),
+            "create_dt_epoch"      : self.create_dt_epoch,
+            "create_dt_fuzzy"      : self.create_dt_fuzzy,
+            "player_id"            : self.player_id,
+            "player_nick"          : self.player_nick,
+            "player_nick_stripped" : self.player_nick_stripped,
+            "game_id"              : self.game_id,
+            "server_id"            : self.server_id,
+            "server_name"          : self.server_name,
+            }
+
+
+class PlayerCapTime(object):
+    """Fastest flag capture times per player, assembled from a SQLAlchemy query"""
+    def __init__(self, row):
+        self.fastest_cap = row.fastest_cap
+        self.create_dt = row.create_dt
+        self.create_dt_epoch = timegm(row.create_dt.timetuple())
+        self.create_dt_fuzzy = pretty_date(row.create_dt)
+        self.player_id = row.player_id
+        self.game_id = row.game_id
+        self.map_id = row.map_id
+        self.map_name = row.map_name
+        self.server_id = row.server_id
+        self.server_name = row.server_name
+
+    def to_dict(self):
+        return {
+            "fastest_cap" : self.fastest_cap.total_seconds(),
+            "create_dt_epoch": self.create_dt_epoch,
+            "create_dt_fuzzy": self.create_dt_fuzzy,
+            "game_id":self.game_id,
+            "map_id": self.map_id,
+            "map_name": self.map_name,
+            "server_id": self.server_id,
+            "server_name": self.server_name,
+            }
+
+
 def initialize_db(engine=None):
     DBSession.configure(bind=engine)
     Base.metadata.bind = engine
index a10073d58620d40b3e762f40d3ad7e959c25438e..f43ee35efd17b88bb12db01ef8f56d519f85e906 100644 (file)
@@ -164,33 +164,6 @@ def map_info_json(request):
     return [{'status':'not implemented'}]
 
 
-class MapCapTime(object):
-    def __init__(self, row):
-        self.fastest_cap          = row.fastest_cap
-        self.create_dt            = row.create_dt
-        self.create_dt_epoch      = timegm(row.create_dt.timetuple())
-        self.create_dt_fuzzy      = pretty_date(row.create_dt)
-        self.player_id            = row.player_id
-        self.player_nick          = row.player_nick
-        self.player_nick_stripped = strip_colors(row.player_nick)
-        self.player_nick_html     = html_colors(row.player_nick)
-        self.game_id              = row.game_id
-        self.server_id            = row.server_id
-        self.server_name          = row.server_name
-
-    def to_dict(self):
-        return {
-            "fastest_cap"          : self.fastest_cap.total_seconds(),
-            "create_dt_epoch"      : self.create_dt_epoch,
-            "create_dt_fuzzy"      : self.create_dt_fuzzy,
-            "player_id"            : self.player_id,
-            "player_nick"          : self.player_nick,
-            "player_nick_stripped" : self.player_nick_stripped,
-            "game_id"              : self.game_id,
-            "server_id"            : self.server_id,
-            "server_name"          : self.server_name,
-            }
-
 def map_captimes_data(request):
     map_id = int(request.matchdict['id'])
 
index a751acea4d5ea17f951e78ecb511ed0318753f06..5f6cba2a422276c0b7aff84a7c74089550a2f615 100644 (file)
@@ -973,31 +973,6 @@ def player_elo_info_text(request):
     }
 
 
-class PlayerCapTime(object):
-    def __init__(self, row):
-        self.fastest_cap = row.fastest_cap
-        self.create_dt = row.create_dt
-        self.create_dt_epoch = timegm(row.create_dt.timetuple())
-        self.create_dt_fuzzy = pretty_date(row.create_dt)
-        self.player_id = row.player_id
-        self.game_id = row.game_id
-        self.map_id = row.map_id
-        self.map_name = row.map_name
-        self.server_id = row.server_id
-        self.server_name = row.server_name
-
-    def to_dict(self):
-        return {
-            "fastest_cap" : self.fastest_cap.total_seconds(),
-            "create_dt_epoch": self.create_dt_epoch,
-            "create_dt_fuzzy": self.create_dt_fuzzy,
-            "game_id":self.game_id,
-            "map_id": self.map_id,
-            "map_name": self.map_name,
-            "server_id": self.server_id,
-            "server_name": self.server_name,
-            }
-
 def player_captimes_data(request):
     player_id = int(request.matchdict['player_id'])
     if player_id <= 2: