# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/divisioninfo.py
# class DivisionInfo(SqlAlchemyBase):
#     __tablename__ = "DivisionInfo"
#     division_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     division = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/conferenceinfo.py
# class ConferenceInfo(SqlAlchemyBase):
#     __tablename__ = "ConferenceInfo"
#     conf_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     conference = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/picktypes.py
# class PickTypes(SqlAlchemyBase):
#     __tablename__ = "PickTypes"
#     pick_type_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     name = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/teaminfo.py
# class TeamInfo(SqlAlchemyBase):
#     __tablename__ = "TeamInfo"
#     team_id = sqlalchemy.Column(sqlalchemy.Integer, index=True, primary_key=True)
#     name = sqlalchemy.Column(sqlalchemy.String)
#     city = sqlalchemy.Column(sqlalchemy.String)
#     team_abbr = sqlalchemy.Column(sqlalchemy.String)
#     conference_id = sqlalchemy.Column(sqlalchemy.Integer)
#     division_id = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/player_picks.py
# class PlayerPicks(SqlAlchemyBase):
#     __tablename__ = "PlayerPicks"
#     pick_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     user_id = sqlalchemy.Column(sqlalchemy.String, sqlalchemy.ForeignKey("Account.id"))
#     season = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     date_submitted = sqlalchemy.Column(sqlalchemy.DATETIME)
#     conf_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ConferenceInfo.conf_id")
#     )
#     division_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("DivisionInfo.division_id")
#     )
#     rank = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     multiplier = sqlalchemy.Column(sqlalchemy.Integer, default=1)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ActiveNFLPlayers.player_id")
#     )
#     pick_type = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PickTypes.pick_type_id")
#     )
# 
# Path: nflpool/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.divisioninfo import DivisionInfo
from nflpool.data.conferenceinfo import ConferenceInfo
from nflpool.data.picktypes import PickTypes
from nflpool.data.teaminfo import TeamInfo
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.seasoninfo import SeasonInfo
        session = DbSessionFactory.create_session()

        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
        current_season = season_row.current_season

        txtstr = "UPDATE PlayerPicks SET multiplier=2 WHERE team_id IN "
        txtstr += "(SELECT team_id FROM (select DISTINCT(team_id), COUNT(team_id) AS ct FROM PlayerPicks WHERE "
        midstr = " GROUP BY team_id) WHERE ct=1) "

        condstr = "pick_type=" + str(pick_type) + " AND season=" + str(current_season)

        if conf is not None:
            condstr += " AND conf_id=" + str(conf)
            if div is not None:
                condstr += " AND division_id=" + str(div)
                if rank is not None:
                    condstr += " AND rank=" + str(rank)

        txtstr += condstr + midstr + "AND " + condstr

        #        print(txtstr)

        session.execute(txtstr)
        session.commit()
        session.close()

    @classmethod
    def unique_player_picks(cls, pick_type, conf):
        session = DbSessionFactory.create_session()


# Path: nflpool/data/dbsession.py
# class DbSessionFactory:
#     factory = None
# 
#     # Start a database session at app startup
#     @staticmethod
#     def global_init(db_file):
#         if DbSessionFactory.factory:
#             return
# 
#         if not db_file or not db_file.strip():
#             raise Exception("You must specify a data file.")
# 
#         conn_str = "sqlite:///" + db_file
#         print("Connecting to db with conn string: {}".format(conn_str))
# 
#         engine = sqlalchemy.create_engine(conn_str, echo=False)
# 
#         SqlAlchemyBase.metadata.create_all(engine)
#         DbSessionFactory.factory = sqlalchemy.orm.sessionmaker(bind=engine)
# 
#     @staticmethod
#     def create_session():
#         return DbSessionFactory.factory()
# 
# Path: nflpool/data/divisioninfo.py
# class DivisionInfo(SqlAlchemyBase):
#     __tablename__ = "DivisionInfo"
#     division_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     division = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/conferenceinfo.py
# class ConferenceInfo(SqlAlchemyBase):
#     __tablename__ = "ConferenceInfo"
#     conf_id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
#     conference = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/picktypes.py
# class PickTypes(SqlAlchemyBase):
#     __tablename__ = "PickTypes"
#     pick_type_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     name = sqlalchemy.Column(sqlalchemy.String)
# 
# Path: nflpool/data/teaminfo.py
# class TeamInfo(SqlAlchemyBase):
#     __tablename__ = "TeamInfo"
#     team_id = sqlalchemy.Column(sqlalchemy.Integer, index=True, primary_key=True)
#     name = sqlalchemy.Column(sqlalchemy.String)
#     city = sqlalchemy.Column(sqlalchemy.String)
#     team_abbr = sqlalchemy.Column(sqlalchemy.String)
#     conference_id = sqlalchemy.Column(sqlalchemy.Integer)
#     division_id = sqlalchemy.Column(sqlalchemy.Integer)
# 
# Path: nflpool/data/player_picks.py
# class PlayerPicks(SqlAlchemyBase):
#     __tablename__ = "PlayerPicks"
#     pick_id = sqlalchemy.Column(
#         sqlalchemy.Integer, primary_key=True, autoincrement=True
#     )
#     user_id = sqlalchemy.Column(sqlalchemy.String, sqlalchemy.ForeignKey("Account.id"))
#     season = sqlalchemy.Column(sqlalchemy.Integer, index=True)
#     date_submitted = sqlalchemy.Column(sqlalchemy.DATETIME)
#     conf_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ConferenceInfo.conf_id")
#     )
#     division_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("DivisionInfo.division_id")
#     )
#     rank = sqlalchemy.Column(sqlalchemy.Integer)
#     team_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("TeamInfo.team_id")
#     )
#     multiplier = sqlalchemy.Column(sqlalchemy.Integer, default=1)
#     player_id = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("ActiveNFLPlayers.player_id")
#     )
#     pick_type = sqlalchemy.Column(
#         sqlalchemy.Integer, sqlalchemy.ForeignKey("PickTypes.pick_type_id")
#     )
# 
# Path: nflpool/data/seasoninfo.py
# class SeasonInfo(SqlAlchemyBase):
#     __tablename__ = "SeasonInfo"
#     id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, autoincrement=True)
#     current_season = sqlalchemy.Column(sqlalchemy.Integer)
#     season_start_date = sqlalchemy.Column(sqlalchemy.String)
#     home_team = sqlalchemy.Column(sqlalchemy.String)
#     away_team = sqlalchemy.Column(sqlalchemy.String)


# Path: nflpool/services/unique_picks_service.py
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.divisioninfo import DivisionInfo
from nflpool.data.conferenceinfo import ConferenceInfo
from nflpool.data.picktypes import PickTypes
from nflpool.data.teaminfo import TeamInfo
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.seasoninfo import SeasonInfo

        session = DbSessionFactory.create_session()

        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
        current_season = season_row.current_season

        txtstr = "UPDATE PlayerPicks SET multiplier=2 WHERE team_id IN "
        txtstr += "(SELECT team_id FROM (select DISTINCT(team_id), COUNT(team_id) AS ct FROM PlayerPicks WHERE "
        midstr = " GROUP BY team_id) WHERE ct=1) "

        condstr = "pick_type=" + str(pick_type) + " AND season=" + str(current_season)

        if conf is not None:
            condstr += " AND conf_id=" + str(conf)
            if div is not None:
                condstr += " AND division_id=" + str(div)
                if rank is not None:
                    condstr += " AND rank=" + str(rank)

        txtstr += condstr + midstr + "AND " + condstr

        #        print(txtstr)

        session.execute(txtstr)
        session.commit()
        session.close()

    @classmethod
    def unique_player_picks(cls, pick_type, conf):
        session = DbSessionFactory.create_session()


        season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()