def start_main():
    cleanup()

    finalList = []
    teamList = common_lib.get_multiple_col(NBA_POWER_RANKING_CSV_FILE, 0)
    leadingTeamsTuple = get_two_leading_teams_of_true_power_ranking(teamList)
    leadingTeam = leadingTeamsTuple[0]
    secondLeadingTeam = leadingTeamsTuple[1]
    championTeam = get_team_champion_from_html(common_lib.NBA_CHAMPION_HTML_FILE)
    finalsRunnerUpTeam = get_team_finals_runner_up_from_html(common_lib.NBA_CHAMPION_HTML_FILE)


    # Check if file exist.
    data = common_lib.open_file(common_lib.NBA_LEADING_TEAM_CHAMPION_CHECK_CSV_FILE)
    if data == 'FileNotFoundError':
        finalList.append(['YEAR', 'TRUE_POWER_RANK_LEAD_TEAM', 'TRUE_POWER_RANK_SECOND_LEAD_TEAM', 'CHAMPION_TEAM', 'FINALS_RUNNER_UP_TEAM', 'SAME?'])

    # if the program cannot find a championTeam, then print 'No Champion'.
    if not championTeam:
        championTeam = 'No Champion'

    if not finalsRunnerUpTeam:
        finalsRunnerUpTeam = 'No Runner Up'

    # Check if leadingTeam is the same as championTeam
    leadingTeam = change_element_into_str(leadingTeam)
    secondLeadingTeam = change_element_into_str(secondLeadingTeam)
    if leadingTeam.lower() == championTeam.lower():
        sameTeam = True
    elif leadingTeam.lower() == finalsRunnerUpTeam.lower():
        sameTeam = True
    elif secondLeadingTeam.lower() == championTeam.lower():
        sameTeam = True
    elif secondLeadingTeam.lower() == finalsRunnerUpTeam.lower():
        sameTeam = True
    else:
        sameTeam = False

    finalList.append([YEAR, leadingTeam, secondLeadingTeam, championTeam, finalsRunnerUpTeam, sameTeam])
    dataStr = common_lib.convert_list_into_str(finalList)
    dataStr = dataStr + '\n'

    common_lib.append_file(dataStr, common_lib.NBA_LEADING_TEAM_CHAMPION_CHECK_CSV_FILE)
Exemplo n.º 2
0
def start_main():
    list2 = []
    finalList = []

    theList = common_lib.get_multiple_col(NBA_POWER_RANKING_CSV_FILE, 0, 1, 2,
                                          3, 4)

    i = 0
    while i < len(theList):
        teamName = common_lib.parse_the_popped_element_to_return_str(
            theList.pop())
        roadWin = common_lib.parse_the_popped_element_to_return_str(
            theList.pop())
        homeLoss = common_lib.parse_the_popped_element_to_return_str(
            theList.pop())
        pct = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        truePct = common_lib.parse_the_popped_element_to_return_str(
            theList.pop())
        list2.append([teamName, roadWin, homeLoss, pct, truePct])

    # Add column 'PCT_GAP', 'TIER', and 'LABEL' onto header
    list2.reverse()
    header = list2.pop()
    header.append('PCT_GAP')
    header.append('TIER')
    header.append('LABEL')
    header.append('PROJECTION')
    finalList.append(header)

    # Evaluates team's TRUE_PCT to find PCT_GAP, TIER, and LABEL

    # Set initial values up for looping
    length = len(list2)
    tier = 0
    letterTier = chr(
        tier + ord('A'))  # Converts the int to corresponding english alphabet
    labelProjeTuple = assign_label_and_projection_to_tier(letterTier)
    element1 = list2.pop()
    element1.append('0')
    element1.append(str(letterTier))
    element1.append(str(labelProjeTuple[0]))
    element1.append(str(labelProjeTuple[1]))
    list2.append(element1)
    for i in range(length):
        #    for i in range(0,1):
        try:
            # Grab two elements from the list
            element1 = list2.pop()
            element2 = list2.pop()
        except IndexError:
            finalList.append(element2)
            break
        else:
            # Get PCT_GAP
            floatTruePct1 = float(element1[4])
            floatTruePct2 = float(element2[4])
            pctGap = (floatTruePct1 / floatTruePct2) - 1

            # Get TIER
            if pctGap > PCT_GAP_CUTOFF:
                tier += 1
                letterTier = chr(tier + ord('A'))

            # Assign LABEL to corresponding TIER
            labelProjeTuple = assign_label_and_projection_to_tier(letterTier)

            element2.append(str(pctGap))
            element2.append(str(letterTier))
            element2.append(str(labelProjeTuple[0]))
            element2.append(str(labelProjeTuple[1]))
            finalList.append(element1)
            list2.append(element2)

    finalList = common_lib.convert_list_into_str(finalList)
    common_lib.write_file(finalList, NBA_POWER_RANKING_CSV_FILE)
Exemplo n.º 3
0
def start_main():
    list2 = []
    finalList = []

    theList = common_lib.get_multiple_col(NBA_POWER_RANKING_CSV_FILE, 0,1,2,3,4)

    i = 0
    while i < len(theList):
        teamName = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        roadWin = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        homeLoss = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        pct = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        truePct = common_lib.parse_the_popped_element_to_return_str(theList.pop())
        list2.append([teamName, roadWin, homeLoss, pct, truePct])

    # Add column 'PCT_GAP', 'TIER', and 'LABEL' onto header
    list2.reverse()
    header = list2.pop()
    header.append('PCT_GAP')
    header.append('TIER')
    header.append('LABEL')
    header.append('PROJECTION')
    finalList.append(header)

# Evaluates team's TRUE_PCT to find PCT_GAP, TIER, and LABEL

    # Set initial values up for looping
    length = len(list2)
    tier = 0
    letterTier = chr(tier + ord('A')) # Converts the int to corresponding english alphabet
    labelProjeTuple = assign_label_and_projection_to_tier(letterTier)
    element1 = list2.pop()
    element1.append('0')
    element1.append(str(letterTier))
    element1.append(str(labelProjeTuple[0]))
    element1.append(str(labelProjeTuple[1]))
    list2.append(element1)
    for i in range(length):
#    for i in range(0,1):
        try:
            # Grab two elements from the list
            element1 = list2.pop()
            element2 = list2.pop()
        except IndexError:
            finalList.append(element2)
            break
        else:
            # Get PCT_GAP
            floatTruePct1 = float(element1[4])
            floatTruePct2 = float(element2[4])
            pctGap = (floatTruePct1 / floatTruePct2) - 1

            # Get TIER
            if pctGap > PCT_GAP_CUTOFF:
                tier += 1
                letterTier = chr(tier + ord('A'))

            # Assign LABEL to corresponding TIER
            labelProjeTuple = assign_label_and_projection_to_tier(letterTier)

            element2.append(str(pctGap))
            element2.append(str(letterTier))
            element2.append(str(labelProjeTuple[0]))
            element2.append(str(labelProjeTuple[1]))
            finalList.append(element1)
            list2.append(element2)

    finalList = common_lib.convert_list_into_str(finalList)
    common_lib.write_file(finalList, NBA_POWER_RANKING_CSV_FILE)
def sort_true_pct_ranking():
    list2 = []

    # Get values and append the file
    thisList = common_lib.get_multiple_col(common_lib.NBA_STANDING_CSV_FILE, 0, 5, 4, 3)
#######################################
#    thisList = common_lib.get_multiple_col(common_lib.NBA_STANDING_CSV_FILE, 0, 10, 11, 3)
#######################################
    teamName = thisList.pop()
    teamName = common_lib.parse_the_popped_element_to_return_str(teamName)
    homeLoss = thisList.pop()
    homeLoss = common_lib.parse_the_popped_element_to_return_str(homeLoss)
    roadWin = thisList.pop()
    roadWin = common_lib.parse_the_popped_element_to_return_str(roadWin)
    pct = thisList.pop()
    pct = common_lib.parse_the_popped_element_to_return_str(pct)
    truePct = 'TRUE_PCT'
    list2.append([teamName, roadWin, homeLoss, pct, truePct])

    i = 0
    while i < len(thisList):
        teamName = thisList.pop()
        teamName = common_lib.parse_the_popped_element_to_return_str(teamName)
        homeLoss = thisList.pop()
        homeLoss = common_lib.parse_the_popped_element_to_return_str(homeLoss)
        roadWin = thisList.pop()
        roadWin = common_lib.parse_the_popped_element_to_return_str(roadWin)
        pct = thisList.pop()
        pct = common_lib.parse_the_popped_element_to_return_str(pct)
        truePct = float(roadWin) / (float(roadWin) + float(homeLoss))
        truePct = str(truePct)
        list2.append([teamName, roadWin, homeLoss, pct, truePct])

    # Sort by descending true_pct (priority on true_pct, then pct)
    list2.sort(key=lambda x: x[4])
    length = len(list2)
    header = list2.pop()
    list3 = list2
    finalList = []
    finalList.append(header)


    for i in range(length):
        try:
            element1 = list3.pop()
            element2 = list3.pop()
        except IndexError:
            finalList.append(element2)
            break
        else:
            floatTruePct1 = float(element1[3])
            floatTruePct2 = float(element2[3])

            # If true_pct are the same, sort by pct.
            if floatTruePct1 == floatTruePct2:
                floatPct1 = float(element1[4])
                floatPct2 = float(element2[4])

                if floatPct2 > floatPct1:
                    finalList.append(element2)
                    list3.append(element1)
                else:
                    finalList.append(element1)
                    list3.append(element2)
            else:
                finalList.append(element1)
                list3.append(element2)

    # Clean out the lists
    del list2[:]
    del list3[:]
    return finalList
Exemplo n.º 5
0
def sort_true_pct_ranking():
    list2 = []

    # Get values and append the file
    thisList = common_lib.get_multiple_col(common_lib.NBA_STANDING_CSV_FILE, 0,
                                           5, 4, 3)
    #######################################
    #    thisList = common_lib.get_multiple_col(common_lib.NBA_STANDING_CSV_FILE, 0, 10, 11, 3)
    #######################################
    teamName = thisList.pop()
    teamName = common_lib.parse_the_popped_element_to_return_str(teamName)
    homeLoss = thisList.pop()
    homeLoss = common_lib.parse_the_popped_element_to_return_str(homeLoss)
    roadWin = thisList.pop()
    roadWin = common_lib.parse_the_popped_element_to_return_str(roadWin)
    pct = thisList.pop()
    pct = common_lib.parse_the_popped_element_to_return_str(pct)
    truePct = 'TRUE_PCT'
    list2.append([teamName, roadWin, homeLoss, pct, truePct])

    i = 0
    while i < len(thisList):
        teamName = thisList.pop()
        teamName = common_lib.parse_the_popped_element_to_return_str(teamName)
        homeLoss = thisList.pop()
        homeLoss = common_lib.parse_the_popped_element_to_return_str(homeLoss)
        roadWin = thisList.pop()
        roadWin = common_lib.parse_the_popped_element_to_return_str(roadWin)
        pct = thisList.pop()
        pct = common_lib.parse_the_popped_element_to_return_str(pct)
        truePct = float(roadWin) / (float(roadWin) + float(homeLoss))
        truePct = str(truePct)
        list2.append([teamName, roadWin, homeLoss, pct, truePct])

    # Sort by descending true_pct (priority on true_pct, then pct)
    list2.sort(key=lambda x: x[4])
    length = len(list2)
    header = list2.pop()
    list3 = list2
    finalList = []
    finalList.append(header)

    for i in range(length):
        try:
            element1 = list3.pop()
            element2 = list3.pop()
        except IndexError:
            finalList.append(element2)
            break
        else:
            floatTruePct1 = float(element1[3])
            floatTruePct2 = float(element2[3])

            # If true_pct are the same, sort by pct.
            if floatTruePct1 == floatTruePct2:
                floatPct1 = float(element1[4])
                floatPct2 = float(element2[4])

                if floatPct2 > floatPct1:
                    finalList.append(element2)
                    list3.append(element1)
                else:
                    finalList.append(element1)
                    list3.append(element2)
            else:
                finalList.append(element1)
                list3.append(element2)

    # Clean out the lists
    del list2[:]
    del list3[:]
    return finalList