Ejemplo n.º 1
0
def extractSourceCodeMetrics(rel_date_list, rel_list, commit_date_dict,
                             category):
    # load metrics
    rel_metric_dict, metric_names = loadMetrics4Releases(category, rel_list)
    # map and compute metric values
    result_list = list()
    i = 0

    bugs = get_bugs.get_all()

    for bug in bugs:
        if DEBUG and i > 5:
            break

        bug_id = bug['id']
        commits, _ = patchanalysis.get_commits_for_bug(bug)

        print bug_id

        # extract metrics
        raw_list = list()
        metric_list = list()
        for commit_id in commits:
            i += 1
            if DEBUG:
                print ' ', commit_id
            # corresponding (prior) release of a commit
            rel_num = correspondingRelease(commit_id, commit_date_dict,
                                           rel_date_list)
            # changed files in a commit
            shell_res = shellCommand(
                'hg -R %s log -r %s --template {files}\t{diffstat}' %
                (HG_REPO_PATH, commit_id)).split('\t')
            raw_changed_files = shell_res[0]
            cpp_changed_files = re.findall(
                r'(\S+\.(?:c|cpp|cc|cxx|h|hpp|hxx)\b)', raw_changed_files)
            # map file/node to metrics
            for a_file in cpp_changed_files:
                metric_dict = rel_metric_dict[rel_num]
                for node in metric_dict:
                    if node in a_file:
                        metrics = metric_dict[node]
                        raw_list.append(metrics)
        # compute average/sum value for a specific attachment
        if len(raw_list):
            df = pd.DataFrame(raw_list,
                              columns=metric_names).apply(pd.to_numeric)
            for metric_name in metric_names:
                metric_list.append(round(df[metric_name].mean(), 2))
            result_list.append([bug_id] + metric_list)
        else:
            result_list.append([bug_id] + [0] * len(metric_names))

    return pd.DataFrame(result_list, columns=['bug_id'] + metric_names)
Ejemplo n.º 2
0
import csv
import locale
from datetime import datetime
from dateutil import relativedelta
from libmozdata.utils import as_utc
import get_bugs
import utils

# The month abbreviation should be in English.
locale.setlocale(locale.LC_TIME, 'C')

if __name__ == '__main__':
    bugs = get_bugs.get_all()
    uplifts = utils.get_uplifts(bugs)

    months = {}

    for uplift in uplifts:
        for channel in utils.uplift_approved_channels(uplift):
            uplift_date = utils.get_uplift_date(uplift, channel)
            if uplift_date > as_utc(datetime(2016, 8, 24)):
                continue
            delta = relativedelta.relativedelta(uplift_date,
                                                as_utc(datetime(2014, 7, 1)))
            delta_num = delta.years * 12 + delta.months
            key = (delta_num, uplift_date.strftime('%b %Y'), channel)
            if key not in months:
                months[key] = 0
            months[key] += 1

    with open('uplift_dates.csv', 'w') as output_file: