Esempio n. 1
0
def get_commit_data_of_user(changesets):
    """
    Parses commits into individual user commits with
    parsed timestamps. Helper function for commits_linegraph()
    """
    user_commits = {}
    for commit in changesets:
        author = commit['parsed_author']
        timestamp = bitmethods.to_unix_time(commit['timestamp'])
        if author not in user_commits:
            user_commits[author] = []
        user_commits[author].append(timestamp)
    return user_commits
Esempio n. 2
0
 def test_to_unix_time(self, mock_datetime, mock_time):
     mock_datetime.return_value = ''
     mock_time.return_value = ''
     self.timestamp = ''
     self.assertEqual(bitmethods.to_unix_time(self.timestamp), 1000)
Esempio n. 3
0
def commits_linegraph(changesets=None, count=50):
    """
    Bitbucket has a inconsistent design where if your repo has
    less than 50 commits, they are returned in oldest commits first.
    If your repo has more than 50 commits, the commits are returned
    in most recent commits first.

    Algorithm to parse commits linegraph
    1. Get the timestamp of first and most recent commit
    2. Split the x-axis regions into date ranges
    3. For each commit, parse each user's timestamp to unix time
    4. Create a data series for each user based on date ranges

    Improvements:
    ** [done] Fix nb_element issue
    1. [done] Refactoring into smaller functions
    2. [done] Optimize number of elements

    ** Fix backwards order of linegraph for < 50 commits
    ** Fix cutoff date end
    3. Improve search algorithm

    Returns:
        Dictionary
    """
    # Fixed issues with count of 1 or less
    if not count:
        return {}

    # Initialize start and end timestamp
    start_time, end_time = 0, 0

    # Handle bitbucket's inconsistent commits ordering
    if count <= 50:
        start_time = bitmethods.to_unix_time(changesets[0]['timestamp'])
        end_time = bitmethods.to_unix_time(changesets[-1]['timestamp'])
    else:
        start_time = bitmethods.to_unix_time(changesets[-1]['timestamp'])
        end_time = bitmethods.to_unix_time(changesets[0]['timestamp'])

    # Set limit on amount of time regions
    nb_element = (end_time-start_time)/(86400*1000)
    if nb_element > 60:
        nb_element = 60
    elif nb_element < 10:
        nb_element = 10

    # Get xdata for time range of commits
    step = (end_time - start_time) / nb_element
    xdata = [x for x in range(start_time, end_time, step)]

    # Get commit data with user as its own y data
    user_commits = get_commit_data_of_user(changesets)
    user_series = tally_data_series(xdata, user_commits, nb_element)

    tooltip_date = "%b %d %Y"
    extra_serie = {"tooltip": {"y_start": "Pushed ", "y_end": " commits"},
                    "date_format": tooltip_date}

    # Add each user commit breakdown into chart data
    chartdata = {'x': xdata, 'extra1': extra_serie }
    user_count = 0
    for user in user_series:
        user_count += 1
        ydata = user_series[user]
        string_count = str(user_count)
        chartdata['name'+string_count] = user
        chartdata['y'+string_count] = ydata
        chartdata['extra'+string_count] = extra_serie

    charttype = "lineChart"
    chartcontainer = 'linechart_container'

    return {
        'charttype': charttype,
        'chartdata': chartdata,
        'chartcontainer': chartcontainer,
        'extra': {
            'x_is_date': True,
            'x_axis_format': '%b %d',
            'tag_script_js': True,
            'jquery_on_ready': False,
            }}