105 lines
3.1 KiB
Python
105 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright (c) 2017 Tomek Wójcik <tomek@bthlabs.pl>
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
# in the Software without restriction, including without limitation the rights
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
# THE SOFTWARE.
|
|
#
|
|
|
|
"""
|
|
q3stats.models.score
|
|
====================
|
|
|
|
This module contains the ``Score`` model.
|
|
"""
|
|
|
|
import sqlalchemy as sa
|
|
import sqlalchemy.dialects.postgresql as pg
|
|
|
|
from q3stats.database import Base
|
|
|
|
|
|
class Score(Base):
|
|
"""The ``Score`` model."""
|
|
__tablename__ = 'scores'
|
|
|
|
#: ``id INT PRIMARY KEY``
|
|
id = sa.Column(sa.Integer(), primary_key=True)
|
|
|
|
#: ``game_id INT REFERENCES game.id``
|
|
game_id = sa.Column(sa.Integer(), sa.ForeignKey('games.id'), index=True)
|
|
|
|
#: ``player VARCHAR(255)``
|
|
player = sa.Column(sa.String(255), index=True)
|
|
|
|
#: ``score INT``
|
|
score = sa.Column(sa.Integer())
|
|
|
|
#: ``kills INT``
|
|
kills = sa.Column(sa.Integer())
|
|
|
|
#: ``deaths INT``
|
|
deaths = sa.Column(sa.Integer())
|
|
|
|
#: ``sucides INT``
|
|
suicides = sa.Column(sa.Integer())
|
|
|
|
#: ``net INT``
|
|
net = sa.Column(sa.Integer())
|
|
|
|
#: ``damage_taken INT``
|
|
damage_taken = sa.Column(sa.Integer())
|
|
|
|
#: ``damage_given INT``
|
|
damage_given = sa.Column(sa.Integer())
|
|
|
|
#: ``total_health INT``
|
|
total_health = sa.Column(sa.Integer())
|
|
|
|
#: ``total_armor INT``
|
|
total_armor = sa.Column(sa.Integer())
|
|
|
|
#: ``weapons JSON``
|
|
weapons = sa.Column(pg.JSON())
|
|
|
|
#: ``items JSON``
|
|
items = sa.Column(pg.JSON())
|
|
|
|
#: ``powerups JSON``
|
|
powerups = sa.Column(pg.JSON())
|
|
|
|
def to_json(self):
|
|
"""Returns dictionary representation suitable for serializing to
|
|
JSON."""
|
|
return {
|
|
'id': self.id,
|
|
'game_id': self.game_id,
|
|
'player': self.player,
|
|
'score': self.score,
|
|
'kills': self.kills,
|
|
'deaths': self.deaths,
|
|
'suicides': self.suicides,
|
|
'net': self.net,
|
|
'damage_taken': self.damage_taken,
|
|
'damage_given': self.damage_given,
|
|
'total_health': self.total_health,
|
|
'total_armor': self.total_armor,
|
|
'weapons': dict(self.weapons),
|
|
'items': dict(self.items),
|
|
'powerups': dict(self.powerups),
|
|
}
|