@@ -0,0 +1,1933 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Afrom sqlalchemy import and_%0A%0Afrom .common import Base, session_scope%0A%0A%0Aclass Shift(Base):%0A    __tablename__ = 'shifts'%0A    __autoload__ = True%0A%0A    STANDARD_ATTRS = %5B%0A        %22in_game_shift_cnt%22, %22period%22, %22start%22, %22end%22, %22duration%22%0A    %5D%0A%0A    def __init__(self, game_id, team_id, player_id, data_dict):%0A        self.game_id = game_id%0A        self.team_id = team_id%0A        self.player_id = player_id%0A        # shift id is a combination of game id, team id, jersey number%0A        # and shift count%0A        self.shift_id = %22%25d%2503d%2502d%2503d%22 %25 (%0A            game_id, team_id, data_dict%5B'no'%5D, data_dict%5B'in_game_shift_cnt'%5D)%0A        for attr in self.STANDARD_ATTRS:%0A            if attr in data_dict:%0A                setattr(self, attr, data_dict%5Battr%5D)%0A            else:%0A                setattr(self, attr, None)%0A%0A    @classmethod%0A    def find(self, game_id, player_id, in_game_cnt):%0A        with session_scope() as session:%0A            try:%0A                shift = session.query(Shift).filter(%0A                    and_(%0A                        Shift.game_id == game_id,%0A                        Shift.player_id == player_id,%0A                        Shift.in_game_shift_cnt == in_game_cnt%0A                    )).one()%0A            except:%0A                shift = None%0A            return shift%0A%0A    def update(self, other):%0A        for attr in self.STANDARD_ATTRS:%0A            setattr(self, attr, getattr(other, attr))%0A%0A    def __eq__(self, other):%0A        return (%0A            (%0A                self.game_id, self.team_id, self.player_id,%0A                self.in_game_shift_cnt, self.start, self.end,%0A                self.duration%0A                ) == (%0A                other.game_id, other.team_id, other.player_id,%0A                other.in_game_shift_cnt, other.start, other.end,%0A                other.duration%0A            ))%0A%0A    def __ne__(self, other):%0A        return not self == other%0A

Add initial version of shift database item