# 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/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/time_service.py
# class TimeService:
#     @staticmethod
#     def get_time():
#         """Create a service to get the time - there were too many instances of getting the current time in
#         the codebase making testing difficult."""
#         # Change now_time for testing
#         # Use this one for production:
#         now_time = pendulum.now(tz=pendulum.timezone("America/New_York"))
#         # Use this one for testing:
#         # now_time = pendulum.datetime(2018, 9, 18, 6, 21, tz='America/New_York')
# 
#         return now_time
# 
#     @staticmethod
#     def get_week():
#         session = DbSessionFactory.create_session()
#         season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
# 
#         season_start = pendulum.parse(season_row.season_start_date)
# 
#         diff = TimeService.get_time() - season_start
#         week = int((diff.days / 7) + 1)
# 
#         return week


from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.seasoninfo import SeasonInfo
from nflpool.services.time_service import TimeService
            sqlstr += "AND t1.rank = pts.place"

            session.execute(sqlstr)
            session.commit()
            conf += 1

        # type 9 points - wildcard
        sqlstr = (
            "INSERT INTO WeeklyPlayerResults (pick_id, season, week, points_earned) "
        )
        sqlstr += (
            "SELECT p.pick_id, w.season, w.week, pts.points*p.multiplier as points_earned "
            "from PlayerPicks p, WeeklyTeamStats w, PickTypePoints pts "
        )
        sqlstr += "WHERE p.pick_type = 9 "
        sqlstr += "AND p.pick_type = pts.pick_type_id "
        sqlstr += "AND w.conference_rank in (5,6) "
        sqlstr += "AND w.team_id = p.team_id "
        sqlstr += "AND w.season = " + str(season) + " "
        sqlstr += "AND w.week = " + str(week)

        session.execute(sqlstr)
        session.commit()

        session.close()

    @staticmethod
    def all_seasons_played():
        """This method is used to get a list of all seasons played and display on the Standings index page
        for players to click through to see the season standings / points scored by player"""

# 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/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/time_service.py
# class TimeService:
#     @staticmethod
#     def get_time():
#         """Create a service to get the time - there were too many instances of getting the current time in
#         the codebase making testing difficult."""
#         # Change now_time for testing
#         # Use this one for production:
#         now_time = pendulum.now(tz=pendulum.timezone("America/New_York"))
#         # Use this one for testing:
#         # now_time = pendulum.datetime(2018, 9, 18, 6, 21, tz='America/New_York')
# 
#         return now_time
# 
#     @staticmethod
#     def get_week():
#         session = DbSessionFactory.create_session()
#         season_row = session.query(SeasonInfo).filter(SeasonInfo.id == "1").first()
# 
#         season_start = pendulum.parse(season_row.season_start_date)
# 
#         diff = TimeService.get_time() - season_start
#         week = int((diff.days / 7) + 1)
# 
#         return week


# Path: nflpool/services/standings_service.py
from nflpool.data.dbsession import DbSessionFactory
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.seasoninfo import SeasonInfo
from nflpool.services.time_service import TimeService

            sqlstr += "AND t1.rank = pts.place"

            session.execute(sqlstr)
            session.commit()
            conf += 1

        # type 9 points - wildcard
        sqlstr = (
            "INSERT INTO WeeklyPlayerResults (pick_id, season, week, points_earned) "
        )
        sqlstr += (
            "SELECT p.pick_id, w.season, w.week, pts.points*p.multiplier as points_earned "
            "from PlayerPicks p, WeeklyTeamStats w, PickTypePoints pts "
        )
        sqlstr += "WHERE p.pick_type = 9 "
        sqlstr += "AND p.pick_type = pts.pick_type_id "
        sqlstr += "AND w.conference_rank in (5,6) "
        sqlstr += "AND w.team_id = p.team_id "
        sqlstr += "AND w.season = " + str(season) + " "
        sqlstr += "AND w.week = " + str(week)

        session.execute(sqlstr)
        session.commit()

        session.close()

    @staticmethod
    def all_seasons_played():
        """This method is used to get a list of all seasons played and display on the Standings index page
        for players to click through to see the season standings / points scored by player"""

        session = DbSessionFactory.create_session()