# Path: pytrainer/util/color.py
# class Color(object):
#     
#     """A color represented as a 24-bit RGB value."""
#     
#     def __init__(self, rgb_val=0):
#         rgb_val_int = int(rgb_val)
#         if rgb_val_int < 0:
#             raise ValueError("RGB value must not be negative.")
#         if rgb_val_int > 0xffffff:
#             raise ValueError("RGB value must not be greater than 0xffffff.")
#         self._rgb_val = rgb_val_int
#         
#     def _get_rgb_val(self):
#         return self._rgb_val
#     
#     rgb_val = property(_get_rgb_val)
#         
#     def _get_rgba_val(self):
#         return self._rgb_val << 8
#     
#     rgba_val = property(_get_rgba_val)
#     
#     def to_hex_string(self):
#         return "{0:06x}".format(self._rgb_val)
# 
# def color_from_hex_string(hex_string):
#     return Color(int(hex_string, 16))
# 
# Path: pytrainer/lib/ddbb.py
# class DDBB(Singleton):
# class ForcedInteger(TypeDecorator):
#     def __init__(self, url=None):
#     def get_connection_url(self):
#     def connect(self):
#     def disconnect(self):
#     def select(self,table,cells,condition=None, mod=None):
#     def create_tables(self, add_default=True):
#     def drop_tables(self):
#     def create_backup(self):
#     def process_bind_param(self, value, dialect):


from pytrainer.util.color import Color, color_from_hex_string
from pytrainer.lib.ddbb import DeclarativeBase, ForcedInteger
from sqlalchemy import Column, Integer, Float, Unicode, CheckConstraint
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import InvalidRequestError, IntegrityError
import sqlalchemy.types as types
import logging
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


class ColorType(types.TypeDecorator):
    """Sqlalchemy type to convert between CHAR and the Color object"""
    impl = types.CHAR

    def process_bind_param(self, value, dialect):
        return value.to_hex_string()

    def process_result_value(self, value, dialect):
        return color_from_hex_string(value)

class Sport(DeclarativeBase):
    """A type of exercise. For example: "running" or "cycling"."""
    __tablename__ = 'sports'
    color = Column(ColorType(length=6), nullable=False)
    id = Column('id_sports', Integer, primary_key=True, nullable=False)
    max_pace = Column(ForcedInteger, CheckConstraint('max_pace>=0'))
    met = Column(Float, CheckConstraint('met>=0'))
    name = Column(Unicode(length=100), nullable=False, unique=True, index=True)
    weight = Column(Float, CheckConstraint('weight>=0'), nullable=False)

    def __init__(self, **kwargs):
        self.name = u""
        self.weight = 0.0
        self.met = None
        self.max_pace = None

# Path: pytrainer/util/color.py
# class Color(object):
#     
#     """A color represented as a 24-bit RGB value."""
#     
#     def __init__(self, rgb_val=0):
#         rgb_val_int = int(rgb_val)
#         if rgb_val_int < 0:
#             raise ValueError("RGB value must not be negative.")
#         if rgb_val_int > 0xffffff:
#             raise ValueError("RGB value must not be greater than 0xffffff.")
#         self._rgb_val = rgb_val_int
#         
#     def _get_rgb_val(self):
#         return self._rgb_val
#     
#     rgb_val = property(_get_rgb_val)
#         
#     def _get_rgba_val(self):
#         return self._rgb_val << 8
#     
#     rgba_val = property(_get_rgba_val)
#     
#     def to_hex_string(self):
#         return "{0:06x}".format(self._rgb_val)
# 
# def color_from_hex_string(hex_string):
#     return Color(int(hex_string, 16))
# 
# Path: pytrainer/lib/ddbb.py
# class DDBB(Singleton):
# class ForcedInteger(TypeDecorator):
#     def __init__(self, url=None):
#     def get_connection_url(self):
#     def connect(self):
#     def disconnect(self):
#     def select(self,table,cells,condition=None, mod=None):
#     def create_tables(self, add_default=True):
#     def drop_tables(self):
#     def create_backup(self):
#     def process_bind_param(self, value, dialect):


# Path: pytrainer/core/sport.py
from pytrainer.util.color import Color, color_from_hex_string
from pytrainer.lib.ddbb import DeclarativeBase, ForcedInteger
from sqlalchemy import Column, Integer, Float, Unicode, CheckConstraint
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import InvalidRequestError, IntegrityError
import sqlalchemy.types as types
import logging

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


class ColorType(types.TypeDecorator):
    """Sqlalchemy type to convert between CHAR and the Color object"""
    impl = types.CHAR

    def process_bind_param(self, value, dialect):
        return value.to_hex_string()

    def process_result_value(self, value, dialect):
        return color_from_hex_string(value)

class Sport(DeclarativeBase):
    """A type of exercise. For example: "running" or "cycling"."""
    __tablename__ = 'sports'
    color = Column(ColorType(length=6), nullable=False)
    id = Column('id_sports', Integer, primary_key=True, nullable=False)
    max_pace = Column(ForcedInteger, CheckConstraint('max_pace>=0'))
    met = Column(Float, CheckConstraint('met>=0'))
    name = Column(Unicode(length=100), nullable=False, unique=True, index=True)
    weight = Column(Float, CheckConstraint('weight>=0'), nullable=False)

    def __init__(self, **kwargs):
        self.name = u""
        self.weight = 0.0
        self.met = None
        self.max_pace = None

        self.color = Color(0x0000ff)