<commit_before>import matplotlib.pyplot as plt
import numpy as np
import logging
import os

from collections import Counter
from apps.data.users.models import User
from apps.evaluators.MRR.algorithm.models import MRR

logger = logging.getLogger(__name__)


def value_gLine(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Line)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = []
    evaluationMeanValues = []
    evaluationMedianValues = []
    for evaluation in allEvaluations:
        evaluationValues.append(evaluation.value)
        evaluationMeanValues.append(np.mean(evaluationValues))
        evaluationMedianValues.append(np.median(evaluationValues))
    logger.debug(
        "MRR Evaluation -> Mean: "
        + str(evaluationMeanValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Median: "
        + str(evaluationMedianValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
        ' ./files/apps/evaluators/MRR/graphs/'
        + str(songSetLimit)
        + '/algorithm/'
        + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.grid(True)
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.xlabel('ID do execução')
    plt.ylabel('Valor do MRR')
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationValues],
        color='red',
        label='Valor'
    )
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationMeanValues],
        color='green',
        label='Media'
    )
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationMedianValues],
        color='blue',
        label='Mediana'
    )
    plt.legend(loc='best')
    plt.savefig(
        str(directory) + 'value_gLine.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph Line)]")


def value_gScatter(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Scatter)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = []
    evaluationMeanValues = []
    evaluationMedianValues = []
    for evaluation in allEvaluations:
        evaluationValues.append(evaluation.value)
        evaluationMeanValues.append(np.mean(evaluationValues))
        evaluationMedianValues.append(np.median(evaluationValues))
    logger.debug(
        "MRR Evaluation -> Mean: "
        + str(evaluationMeanValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Median: "
        + str(evaluationMedianValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
      './files/apps/evaluators/MRR/graphs/'
      + str(songSetLimit)
      + '/algorithm/'
      + str(at) + '/'
      )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.grid(True)
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.ylabel('Valor MRR')
    plt.xlabel('Valor MRR')
    plt.scatter(
        evaluationValues,
        evaluationValues,
        label='Media: '
        + str(float("{0:.4f}".format(evaluationValues[-1])))
    )
    plt.legend(loc='upper left')
    plt.savefig(
        str(directory)
        + 'value_gScatter.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph Scatter)]")


def value_gBoxPlot(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph BoxPlot)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = [
        (evalution.value)
        for evalution in allEvaluations
    ]
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
      './files/apps/evaluators/MRR/graphs/'
      + str(songSetLimit)
      + '/algorithm/'
      + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.boxplot(evaluationValues, labels='V')
    plt.savefig(
        str(directory)
        + 'value_gBoxPlot.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph BoxPlot)]")


def value_gBar(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Bar)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = [
        float("{0:.4f}".format(evalution.value))
        for evalution in allEvaluations
    ]
    evalutionCountList = Counter(evaluationValues)
    mode = evalutionCountList.most_common(1)[0][0]
    logger.debug('MRR Evaluation -> Mode: ' + str(mode))
    directory = str(
        './files/apps/evaluators/MRR/graphs/'
        + str(songSetLimit)
        + '/algorithm/'
        + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )<commit_msg>alterando diretorio<commit_after>import matplotlib.pyplot as plt
import numpy as np
import logging
import os

from collections import Counter
from apps.data.users.models import User
from apps.evaluators.MRR.algorithm.models import MRR

logger = logging.getLogger(__name__)


def value_gLine(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Line)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = []
    evaluationMeanValues = []
    evaluationMedianValues = []
    for evaluation in allEvaluations:
        evaluationValues.append(evaluation.value)
        evaluationMeanValues.append(np.mean(evaluationValues))
        evaluationMedianValues.append(np.median(evaluationValues))
    logger.debug(
        "MRR Evaluation -> Mean: "
        + str(evaluationMeanValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Median: "
        + str(evaluationMedianValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
        ' files/apps/evaluators/MRR/graphs/'
        + str(songSetLimit)
        + '/algorithm/'
        + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.grid(True)
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.xlabel('ID do execução')
    plt.ylabel('Valor do MRR')
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationValues],
        color='red',
        label='Valor'
    )
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationMeanValues],
        color='green',
        label='Media'
    )
    plt.plot(
        [i for i in range(len(allEvaluations))],
        [evaluation for evaluation in evaluationMedianValues],
        color='blue',
        label='Mediana'
    )
    plt.legend(loc='best')
    plt.savefig(
        str(directory) + 'value_gLine.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph Line)]")


def value_gScatter(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Scatter)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = []
    evaluationMeanValues = []
    evaluationMedianValues = []
    for evaluation in allEvaluations:
        evaluationValues.append(evaluation.value)
        evaluationMeanValues.append(np.mean(evaluationValues))
        evaluationMedianValues.append(np.median(evaluationValues))
    logger.debug(
        "MRR Evaluation -> Mean: "
        + str(evaluationMeanValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Median: "
        + str(evaluationMedianValues[-1])
    )
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
      'files/apps/evaluators/MRR/graphs/'
      + str(songSetLimit)
      + '/algorithm/'
      + str(at) + '/'
      )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.grid(True)
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.ylabel('Valor MRR')
    plt.xlabel('Valor MRR')
    plt.scatter(
        evaluationValues,
        evaluationValues,
        label='Media: '
        + str(float("{0:.4f}".format(evaluationValues[-1])))
    )
    plt.legend(loc='upper left')
    plt.savefig(
        str(directory)
        + 'value_gScatter.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph Scatter)]")


def value_gBoxPlot(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph BoxPlot)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = [
        (evalution.value)
        for evalution in allEvaluations
    ]
    logger.debug(
        "MRR Evaluation -> Run Number: "
        + str(len(evaluationValues))
    )
    directory = str(
      'files/apps/evaluators/MRR/graphs/'
      + str(songSetLimit)
      + '/algorithm/'
      + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
    plt.boxplot(evaluationValues, labels='V')
    plt.savefig(
        str(directory)
        + 'value_gBoxPlot.png'
    )
    plt.close()
    logger.info("[Finish MRR Value (Graph BoxPlot)]")


def value_gBar(songSetLimit, at=5):
    logger.info("[Start MRR Value (Graph Bar)]")
    allEvaluations = []
    for evalution in MRR.objects.filter(at=at):
        if evalution.life.setSize == songSetLimit:
            allEvaluations.append(evalution)
    evaluationValues = [
        float("{0:.4f}".format(evalution.value))
        for evalution in allEvaluations
    ]
    evalutionCountList = Counter(evaluationValues)
    mode = evalutionCountList.most_common(1)[0][0]
    logger.debug('MRR Evaluation -> Mode: ' + str(mode))
    directory = str(
        'files/apps/evaluators/MRR/graphs/'
        + str(songSetLimit)
        + '/algorithm/'
        + str(at) + '/'
    )
    if not os.path.exists(directory):
        os.makedirs(directory)
    plt.figure()
    plt.title(
        'MRR - Mean Reciprocal Rank@'
        + str(at)
        + '\nSet - '
        + str(songSetLimit)
    )
{'fraction_non_alphanumeric': 0.12799310938845823, 'fraction_numerical': 0.002756244616709733, 'mean_word_length': 2.3461095100864555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926635', 'n_tokens_mistral': 3758, 'n_tokens_neox': 3705, 'n_words': 673}