def _assertion_roster_mentions(cmt_data_list, roster_file, roster_list, team):
    """
    Function to test assertions for function roster_mentions().
    """
    assertions.assert_cmt_data_list(cmt_data_list)
    assertions.assert_roster_file_format(roster_file)
    assertions.assert_str_list(roster_list)
    assertions.assert_team(team)
def _assertion_mgmt_cmt_sent(classifier, cmt_lvl_rost_ment_reader, global_ID,
    roster_list, mgmt_list, team):
    """ Assertions for function manager_cmt_sentiment() """
    assertions.assert_classifier(classifier)
    assertions.assert_cmt_lvl_ment_file_format(cmt_lvl_rost_ment_reader, roster_list)
    assertions.assert_global_ID(global_ID)
    assertions.assert_str_list(roster_list)
    assertions.assert_str_list(mgmt_list)
    assertions.assert_team(team)
def _assertion_comment_roster_glob(cmt_lvl_ment_file, roster_list, global_ID,
                                   team):
    """
    Function to test assertions for function coach_mentions_glob()
    """
    assertions.assert_cmt_lvl_ment_file_format(cmt_lvl_ment_file, roster_list)
    assertions.assert_str_list(roster_list)
    assertions.assert_global_ID(global_ID)
    assertions.assert_team(team)
def compare_files(machine_code_file, ground_truth_file, roster_list, team):
    """
    Compare the machine_code_file created by nameMatching function comment_players
    to a generated file ground_truth_file to look at the accuracy.
    Calculates the precision and recall of the columns of player mentions for each
    comment and the total precision/recall. Then modify the csv file comment_mentions
    by adding rows at the end of the file with total recall/prec and recall/prec
    for each column. If the recall/prec is "null", that means that due to a divide
    by zero error in calculations, the recall/prec was uncalculable.

    To compare the accuracy, the function creates matrices of each file and adds/
    subtracts them. If an entry has a 2, then the mention of the player in the
    comment is a true positive. When subtracting the matrices, a value of -1
    corresponds to a false positive (the ground truth code doesn't have the player
    mention but the machine code does.) A value of +1 is a false negative
    (the ground truth code has a player mention but the machine code does not.)

    Parameter machine_code_file: a csv file containing individual comments and
    marks for whether or not each comment contains a mention of a player
    Precondition: must be a DataFrame object from the pandas module.

    Parameter ground_truth_file: a csv file contaniing individual comments
    Precondition: must be a DataFrame object from the pandas module. The columns
    global_ID, local_ID, and comment must be the same as comment_file and contain
    the same player headers.

    Parameter roster_list: a list of strings with players to compare the csvfile to.
    Precondition: roster_list must be a list with string entries.

    Parameter team: the basketball team the code is run on.
    Precondition: team is of type string
    """
    assertions.assert_compare_machine_hand(machine_code_file,
                                           ground_truth_file)
    assertions.assert_str_list(roster_list)
    assertions.assert_team(team)
    length = len(machine_code_file)
    matrix_one = _create_matrix(numpy.empty((0, length), int),
                                machine_code_file, roster_list)
    matrix_two = _create_matrix(numpy.empty((0, length), int),
                                ground_truth_file, roster_list)
    matrix_diff = numpy.subtract(matrix_two, matrix_one)
    matrix_sum = numpy.add(matrix_one, matrix_two)
    appendDict = {
        "Calculations": [
            "True Positives", "False Positives", "False Negatives",
            "Precision", "Recall", "Num. of comments"
        ],
        "Total": []
    }

    _add_values(appendDict, matrix_sum, matrix_diff, roster_list)
    df = pandas.DataFrame(appendDict)
    df.to_csv(r'/home/sebastianguo/Documents/Research/Teams/' + team +
              '/precision_and_recall.csv',
              index=False)
def _assertion_coach_mentions_glob(global_ID, agg_rost_ment_file, roster_file,
                                   mgmt_list, sent_dict, result, team):
    """ Function to test assertions for coach_mentions_glob(). """
    assertions.assert_global_ID(global_ID)
    assertions.assert_agg_roster_ment_file_format(agg_rost_ment_file,
                                                  roster_file)
    assertions.assert_roster_file_format(roster_file)
    assertions.assert_str_list(mgmt_list)
    assertions.assert_result(result)
    assertions.assert_team(team)
def _assertion_roster_mentions_glob(global_ID, rost_ment_file, roster_file,
                                    roster_list, team):
    """
    Function to test assertions for function roster_mentions_glob().
    """
    assertions.assert_global_ID(global_ID)
    assertions.assert_roster_ment_by_game_file_format(rost_ment_file)
    assertions.assert_roster_file_format(roster_file)
    assertions.assert_str_list(roster_list)
    assertions.assert_team(team)
def _assertion_comment_roster(raw_data_file, roster_file, roster_list,
                              cmt_data_list, team):
    """
    Function to test assertions for function comment_roster().
    """
    assertions.assert_raw_data_file_format(raw_data_file)
    assertions.assert_roster_file_format(roster_file)
    assertions.assert_str_list(roster_list)
    assertions.assert_cmt_data_list(cmt_data_list)
    assertions.assert_team(team)
Beispiel #8
0
def _assertion_calc_mgmt_stats(global_ID_list, mgmt_list, roster_file, team):
    """ Function to assert assertions for calc_mgmt_stats(). """
    assertions.assert_int_list(global_ID_list)
    assertions.assert_str_list(mgmt_list)
    assertions.assert_roster_file_format(roster_file)
    assertions.assert_team(team)