|
|
|
@ -9,7 +9,9 @@ import json
@@ -9,7 +9,9 @@ import json
|
|
|
|
|
from json import JSONEncoder |
|
|
|
|
from datetime import datetime |
|
|
|
|
import pytz |
|
|
|
|
from flask_moment import Moment |
|
|
|
|
|
|
|
|
|
moment = Moment() |
|
|
|
|
|
|
|
|
|
class Role(Enum): |
|
|
|
|
none = 0 |
|
|
|
@ -80,6 +82,9 @@ class Game(db.Model):
@@ -80,6 +82,9 @@ class Game(db.Model):
|
|
|
|
|
lazy='select', |
|
|
|
|
backref=db.backref('game', lazy='joined')) |
|
|
|
|
|
|
|
|
|
def last_player_locations(self): |
|
|
|
|
return [player.last_location(self) for player in self.players if player.locations] |
|
|
|
|
|
|
|
|
|
class Player(UserMixin, db.Model): |
|
|
|
|
""" !Always call set_auth_hash() after creating new instance! """ |
|
|
|
|
__tablename__ = 'player' |
|
|
|
@ -143,10 +148,11 @@ class Player(UserMixin, db.Model):
@@ -143,10 +148,11 @@ class Player(UserMixin, db.Model):
|
|
|
|
|
if not self.locations: |
|
|
|
|
return None |
|
|
|
|
if game is None: |
|
|
|
|
return max(location.timestamp for location in self.locations) |
|
|
|
|
return max(location for location in self.locations) |
|
|
|
|
game_start = game.start_time or datetime.min |
|
|
|
|
game_end = game.end_time or datetime.max |
|
|
|
|
return max(location.timestamp for location in self.locations if location.timestamp > game_start and location.timestamp < game_end) |
|
|
|
|
return max((location for location in self.locations if location.timestamp > game_start and location.timestamp < game_end), |
|
|
|
|
key=lambda location: location.timestamp) |
|
|
|
|
|
|
|
|
|
@login.user_loader |
|
|
|
|
def load_user(id): |
|
|
|
@ -188,6 +194,18 @@ class Location(db.Model):
@@ -188,6 +194,18 @@ class Location(db.Model):
|
|
|
|
|
latitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None),nullable=False) |
|
|
|
|
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False) |
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
|
return f'{self.longitude}, {self.latitude}' |
|
|
|
|
|
|
|
|
|
class LocationEncoder(JSONEncoder): |
|
|
|
|
def default(self, location): |
|
|
|
|
return { |
|
|
|
|
'player_name' : location.player.name, |
|
|
|
|
'longitude' : location.longitude, |
|
|
|
|
'latitude' : location.latitude, |
|
|
|
|
'timestamp_utc' : str(location.timestamp) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class Notification(db.Model): |
|
|
|
|
__tablename__ = 'notification' |
|
|
|
|
id = db.Column(db.Integer, primary_key=True) |
|
|
|
|