Esempio n. 1
0
    def index(self):
        if not self.logged_in_user_id:
            print("Cannot view account page, must login")
            self.redirect("/account/signin")
        """Account homepage loads after each user registers.  After the first user registers (which will be the 
        admin user, check to see if the database is empty and if so, redirect to the new_install service process"""
        if GameDayService.admin_check() is None:
            self.redirect("/admin/new_install")

        # data / service access
        account_details = AccountService.get_account_info(
            self.logged_in_user_id)
        seasons_played = AccountService.seasons_played(self.logged_in_user_id)
        account_date = AccountService.get_account_date(self.logged_in_user_id)

        picks_due = GameDayService.picks_due()
        time_due = GameDayService.time_due()

        # return the model
        return {
            "account": account_details,
            "seasons": seasons_played,
            "account_date": account_date,
            "picks_due": picks_due,
            "time_due": time_due,
        }
Esempio n. 2
0
    def season(self):
        """View the standings for a given season from the user choosing in the bullet list in index"""
        vm = StandingsPointsViewModel()
        vm.from_dict(self.data_dict)

        season = self.request.matchdict["id"]
        season_year = pendulum.parse(season)

        current_standings = StandingsService.display_weekly_standings(season)

        session = DbSessionFactory.create_session()

        date_query = (session.query(WeeklyPlayerResults.update_date).order_by(
            WeeklyPlayerResults.update_date.desc()).first())

        if date_query is None:
            self.redirect("/home")

        else:

            if TimeService.get_time() > GameDayService.last_game_date():
                date_updated = "Final Standings"

            elif TimeService.get_time() < GameDayService.season_opener_date():
                date_updated = "Season Has Not Started"

            else:
                date = str(date_query[0])
                date_convert = pendulum.from_format(date, "YYYY-MM-DD")
                string_date = date_convert.format("MMMM Do YYYY")

                date_updated = "Standings through " + string_date

            return {
                "current_standings": current_standings,
                "season": season,
                "date_updated": date_updated,
            }

        session.close()
Esempio n. 3
0
    def index(self):
        """GET request for the admin homepage.  If the database is empty, redirect to new_install"""
        session = DbSessionFactory.create_session()
        su__query = (
            session.query(Account.id)
            .filter(Account.is_super_user == 1)
            .filter(Account.id == self.logged_in_user_id)
            .first()
        )

        if su__query is None:
            print("You must be an administrator to view this page")
            self.redirect("/home")

        get_first_name = (
            session.query(Account.first_name)
            .filter(Account.id == self.logged_in_user_id)
            .first()
        )
        first_name = get_first_name[0]

        season_info = session.query(SeasonInfo).all()

        if GameDayService.admin_check() is None:
            self.redirect("/admin/new_season")

        else:

            season_start_date = GameDayService.season_opener_date()
            picks_due = GameDayService.picks_due()
            time_due = GameDayService.time_due()

            # Use the string above in a Pendulum instance and get the time deltas needed
            now_time = TimeService.get_time()

            days = GameDayService.delta_days()
            hours = GameDayService.delta_hours()
            minutes = GameDayService.delta_minutes()

            return {
                "picks_due": picks_due,
                "time_due": time_due,
                "days": days,
                "hours": hours,
                "minutes": minutes,
                "first_name": first_name,
                "season_info": season_info,
            }

        session.close()
Esempio n. 4
0
    def submit_player_picks(self):

        if not self.logged_in_user_id:
            print("Cannot view picks page, you must be logged in")
            self.redirect("/account/signin")

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

        season_info = session.query(SeasonInfo).all()

        season_start_date = GameDayService.season_opener_date()
        picks_due = GameDayService.picks_due()
        time_due = GameDayService.time_due()

        # Do not change this for testing - change in TimeService
        now_time = TimeService.get_time()

        # Check if the season has already started
        if now_time > season_start_date:
            print("Too late!  The season has already started.")
            self.redirect("/picks/too-late")

        else:

            days = GameDayService.delta_days()
            hours = GameDayService.delta_hours()
            minutes = GameDayService.delta_minutes()
            current_datetime = now_time.to_day_datetime_string()

            # Check if user has already submitted picks

            user_query = (session.query(PlayerPicks.user_id).filter(
                PlayerPicks.user_id == self.logged_in_user_id).filter(
                    PlayerPicks.season == season).first())

            if user_query is None:

                # Data / Service access
                al_east_list = PlayerPicksService.get_division_team_list(0, 1)
                al_central_list = PlayerPicksService.get_division_team_list(
                    0, 2)
                al_west_list = PlayerPicksService.get_division_team_list(0, 3)

                nl_east_list = PlayerPicksService.get_division_team_list(1, 1)
                nl_central_list = PlayerPicksService.get_division_team_list(
                    1, 2)
                nl_west_list = PlayerPicksService.get_division_team_list(1, 3)

                # Pass the P as the pitcher position and the query to get the list != P
                al_batter_list = PlayerPicksService.get_hitter_list(0, "P")
                nl_batter_list = PlayerPicksService.get_hitter_list(1, "P")

                # List of all Pitchers
                al_pitcher_list = PlayerPicksService.get_pitcher_list(0, "P")
                nl_pitcher_list = PlayerPicksService.get_pitcher_list(1, "P")

                # List of all teams to pick the Wild Card from each league
                al_wildcard_list = PlayerPicksService.get_al_wildcard()
                nl_wildcard_list = PlayerPicksService.get_nl_wildcard()

                # Create a range of 0-162 for players to pick how many wins the Twins will finish with
                twins_wins_pick_list = list(range(0, 163))

                # Get the user ID
                user_id = self.logged_in_user_id
                get_first_name = (session.query(Account.first_name).filter(
                    Account.id == self.logged_in_user_id).first())
                first_name = get_first_name[0]

                # Return the models
                return {
                    "season": season,
                    "user_id": user_id,
                    "first_name": first_name,
                    "al_east": al_east_list,
                    "al_central": al_central_list,
                    "al_west": al_west_list,
                    "nl_east": nl_east_list,
                    "nl_central": nl_central_list,
                    "nl_west": nl_west_list,
                    "al_hitter_list": al_batter_list,
                    "nl_hitter_list": nl_batter_list,
                    "al_pitcher_list": al_pitcher_list,
                    "nl_pitcher_list": nl_pitcher_list,
                    "al_wildcard_list": al_wildcard_list,
                    "nl_wildcard_list": nl_wildcard_list,
                    "twins_wins_pick_list": twins_wins_pick_list,
                    "picks_due": picks_due,
                    "time_due": time_due,
                    "days": days,
                    "hours": hours,
                    "minutes": minutes,
                    "current_datetime": current_datetime,
                    "season_info": season_info,
                }

            else:
                print("You have already submitted picks for this season")
                self.redirect("/picks/change-picks")

            session.close()
Esempio n. 5
0
    def change_player_picks_post(self):
        vm = PlayerPicksViewModel()
        vm.from_dict(self.request.POST)

        # Pass a player's picks to the service to be inserted in the db

        session = DbSessionFactory.create_session()
        season_row = (session.query(
            SeasonInfo.current_season).filter(SeasonInfo.id == "1").first())
        season = season_row.current_season
        vm.user_id = self.logged_in_user_id
        vm.season = season

        now_time = TimeService.get_time()

        if GameDayService.season_opener_date() < now_time:
            total_changes = CountService.change_picks_count(
                vm.user_id,
                vm.season,
                vm.al_east_winner_pick,
                vm.al_east_second_pick,
                vm.al_east_last_pick,
                vm.al_central_winner_pick,
                vm.al_central_second_pick,
                vm.al_central_last_pick,
                vm.al_west_winner_pick,
                vm.al_west_second_pick,
                vm.al_west_last_pick,
                vm.nl_east_winner_pick,
                vm.nl_east_second_pick,
                vm.nl_east_last_pick,
                vm.nl_central_winner_pick,
                vm.nl_central_second_pick,
                vm.nl_central_last_pick,
                vm.nl_west_winner_pick,
                vm.nl_west_second_pick,
                vm.nl_west_last_pick,
                vm.al_losses_pick,
                vm.nl_losses_pick,
                vm.al_wins_pick,
                vm.nl_wins_pick,
                vm.al_hr_pick,
                vm.nl_hr_pick,
                vm.al_ba_pick,
                vm.nl_ba_pick,
                vm.al_rbi_pick,
                vm.nl_rbi_pick,
                vm.al_saves_pick,
                vm.nl_saves_pick,
                vm.al_era_pick,
                vm.nl_era_pick,
                vm.al_wildcard1_pick,
                vm.nl_wildcard1_pick,
                vm.al_wildcard2_pick,
                vm.nl_wildcard2_pick,
            )

            print(now_time, "Total number of changes is", total_changes)

            if total_changes >= 15:
                self.redirect("/picks/too-many")

            else:

                PlayerPicksService.change_player_picks(
                    vm.al_east_winner_pick,
                    vm.al_east_second_pick,
                    vm.al_east_last_pick,
                    vm.al_central_winner_pick,
                    vm.al_central_second_pick,
                    vm.al_central_last_pick,
                    vm.al_west_winner_pick,
                    vm.al_west_second_pick,
                    vm.al_west_last_pick,
                    vm.nl_east_winner_pick,
                    vm.nl_east_second_pick,
                    vm.nl_east_last_pick,
                    vm.nl_central_winner_pick,
                    vm.nl_central_second_pick,
                    vm.nl_central_last_pick,
                    vm.nl_west_winner_pick,
                    vm.nl_west_second_pick,
                    vm.nl_west_last_pick,
                    vm.al_hr_pick,
                    vm.nl_hr_pick,
                    vm.al_rbi_pick,
                    vm.nl_rbi_pick,
                    vm.al_ba_pick,
                    vm.nl_ba_pick,
                    vm.al_saves_pick,
                    vm.nl_saves_pick,
                    vm.al_era_pick,
                    vm.nl_era_pick,
                    vm.al_wildcard1_pick,
                    vm.al_wildcard2_pick,
                    vm.nl_wildcard1_pick,
                    vm.nl_wildcard2_pick,
                    vm.al_wins_pick,
                    vm.nl_wins_pick,
                    vm.al_losses_pick,
                    vm.nl_losses_pick,
                    vm.user_id,
                )
        else:

            PlayerPicksService.change_player_picks(
                vm.al_east_winner_pick,
                vm.al_east_second_pick,
                vm.al_east_last_pick,
                vm.al_central_winner_pick,
                vm.al_central_second_pick,
                vm.al_central_last_pick,
                vm.al_west_winner_pick,
                vm.al_west_second_pick,
                vm.al_west_last_pick,
                vm.nl_east_winner_pick,
                vm.nl_east_second_pick,
                vm.nl_east_last_pick,
                vm.nl_central_winner_pick,
                vm.nl_central_second_pick,
                vm.nl_central_last_pick,
                vm.nl_west_winner_pick,
                vm.nl_west_second_pick,
                vm.nl_west_last_pick,
                vm.al_hr_pick,
                vm.nl_hr_pick,
                vm.al_rbi_pick,
                vm.nl_rbi_pick,
                vm.al_ba_pick,
                vm.nl_ba_pick,
                vm.al_saves_pick,
                vm.nl_saves_pick,
                vm.al_era_pick,
                vm.nl_era_pick,
                vm.al_wildcard1_pick,
                vm.al_wildcard2_pick,
                vm.nl_wildcard1_pick,
                vm.nl_wildcard2_pick,
                vm.al_wins_pick,
                vm.nl_wins_pick,
                vm.al_losses_pick,
                vm.nl_losses_pick,
                vm.user_id,
            )

        # Log that a user changed picks

        self.log.notice("Picks changed by {}.".format(
            self.logged_in_user.email))

        get_first_name = (session.query(Account.first_name).filter(
            Account.id == self.logged_in_user_id).first())
        first_name = get_first_name[0]

        get_last_name = (session.query(Account.last_name).filter(
            Account.id == self.logged_in_user_id).first())
        last_name = get_last_name[0]

        message = f"Picks updated by MLBPool2 user:  {first_name} {last_name}"
        print(message)

        SlackService.send_message(message)

        session.close()

        # redirect
        self.redirect("/account")
Esempio n. 6
0
    def change_player_picks(self):

        if not self.logged_in_user_id:
            print("Cannot view picks page, you must be logged in")
            self.redirect("/account/signin")

        # Check if user has already submitted picks

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

        user_query = (session.query(PlayerPicks.user_id).filter(
            PlayerPicks.user_id == self.logged_in_user_id).filter(
                PlayerPicks.season == season).first())

        find_changes = CountService.find_changes(self.logged_in_user_id)

        if user_query is None:

            print("You have not submitted picks for this season")
            self.redirect("/picks/submit-picks")

        elif find_changes is True:
            print(find_changes)
            self.redirect("/picks/too-late-break")

        else:

            now_time = TimeService.get_time()

            if (now_time < GameDayService.season_opener_date()
                    and GameDayService.all_star_break(now_time) is False):

                self.redirect("/picks/too-late")

            elif (now_time > GameDayService.season_opener_date()
                  and GameDayService.all_star_break(now_time) is False):

                self.redirect("/picks/too-late")

            else:

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

                # Data / Service access
                al_east_list = PlayerPicksService.get_division_team_list(0, 1)
                al_central_list = PlayerPicksService.get_division_team_list(
                    0, 2)
                al_west_list = PlayerPicksService.get_division_team_list(0, 3)

                nl_east_list = PlayerPicksService.get_division_team_list(1, 1)
                nl_central_list = PlayerPicksService.get_division_team_list(
                    1, 2)
                nl_west_list = PlayerPicksService.get_division_team_list(1, 3)

                # Pass the P as the pitcher position and the query to get the list != P
                al_batter_list = PlayerPicksService.get_hitter_list(0, "P")
                nl_batter_list = PlayerPicksService.get_hitter_list(1, "P")

                # List of all Pitchers
                al_pitcher_list = PlayerPicksService.get_pitcher_list(0, "P")
                nl_pitcher_list = PlayerPicksService.get_pitcher_list(1, "P")

                # List of all teams to pick the Wild Card from each league
                al_wildcard_list = PlayerPicksService.get_al_wildcard()
                nl_wildcard_list = PlayerPicksService.get_nl_wildcard()

                # Create a range of 0-162 for players to pick how many wins the Twins will finish with
                twins_wins_pick_list = list(range(0, 163))

                # Get the user ID
                user_id = self.logged_in_user_id
                get_first_name = (session.query(Account.first_name).filter(
                    Account.id == self.logged_in_user_id).first())
                first_name = get_first_name[0]

                # Get the original picks the player made
                all_picks = ViewPicksService.display_picks(
                    self.logged_in_user_id, season)

                # Return the models
                return {
                    "season": season,
                    "user_id": user_id,
                    "first_name": first_name,
                    "al_east": al_east_list,
                    "al_central": al_central_list,
                    "al_west": al_west_list,
                    "nl_east": nl_east_list,
                    "nl_central": nl_central_list,
                    "nl_west": nl_west_list,
                    "al_hitter_list": al_batter_list,
                    "nl_hitter_list": nl_batter_list,
                    "al_pitcher_list": al_pitcher_list,
                    "nl_pitcher_list": nl_pitcher_list,
                    "al_wildcard_list": al_wildcard_list,
                    "nl_wildcard_list": nl_wildcard_list,
                    "twins_wins_pick_list": twins_wins_pick_list,
                    "all_picks": all_picks,
                }

            session.close()