<commit_before>import numpy as np
from bokeh.charts import Bar, output_file, save
from bokeh.layouts import layout
from bokeh.plotting import figure
from jav.core.javTime import Time


class BuildChart(object):
    def __init__(self, log, config):
        self.log = log
        self.config = config
        self.time = Time(self.log, self.config)

    def build_velocity_days(self, stats_data):
        self.log.info('Generating graph about daily effort')

        # Velocity Days
        x_dates = []
        y_points = []
        y_avg = []
        for scan_day in stats_data:
            x_dates.append(stats_data[scan_day]['datetime'])
            y_points.append(stats_data[scan_day]['points'])
            week_idx = '4'
            if week_idx not in stats_data[scan_day]['anyday']:
                week_idx = 4
            if 'avg' in stats_data[scan_day]['anyday'][week_idx]:
                y_avg.append(stats_data[scan_day]['anyday'][week_idx]['avg'])
            else:
                y_avg.append(0)

        # prepare some data
        data_dates = np.array(x_dates, dtype=np.datetime64)

        # create a new plot with a a datetime axis type
        p = figure(width=1000, height=350, x_axis_type='datetime', tools='save,pan,box_zoom,reset')

        # add renderers
        p.circle(data_dates, y_points, size=4, color='red', alpha=0.4, legend='Story Points')
        p.line(data_dates, y_avg, color='blue', legend='4 Weeks Average')

        # NEW: customize by setting attributes
        p.title.text = 'Daily Velocity'
        p.legend.location = 'top_left'
        p.grid.grid_line_alpha = 0
        p.xaxis.axis_label = 'Days (Monday-Friday)'
        p.yaxis.axis_label = 'Story Points'
        p.ygrid.band_fill_color = 'olive'
        p.ygrid.band_fill_alpha = 0.1

        return p

    def build_velocity_weeks(self, stats_data):
        self.log.info('Generating graph about weekly effort')

        # Velocity Days
        x_dates = []
        y_points = []
        y_avg = []
        y_weeks = []
        for scan_day in stats_data:
            x_dates.append(stats_data[scan_day]['datetime'])
            y_points.append(stats_data[scan_day]['points'])
            y_weeks.append(stats_data[scan_day]['weektxt'])

            if len(stats_data[scan_day]['stats']) > 0:
                week_idx = '4'
                if week_idx not in stats_data[scan_day]['stats']:
                    week_idx = 4
                if 'avg' in stats_data[scan_day]['stats'][week_idx]:
                    y_avg.append(stats_data[scan_day]['stats'][week_idx]['avg'])
                else:
                    y_avg.append(0)

        # prepare some data
        data_dates = np.array(x_dates, dtype=np.datetime64)

        # create a new plot with a a datetime axis type
        p = figure(width=1000, height=350, x_axis_type='datetime', tools='save,pan,box_zoom,reset')

        # add renderers
        p.circle(data_dates, y_points, size=4, color='red', alpha=0.4, legend='Story Points')
        p.line(data_dates, y_avg, color='blue', legend='4 Weeks Average')

        # NEW: customize by setting attributes
        p.title.text = 'Weekly Velocity'
        p.legend.location = 'top_left'
        p.grid.grid_line_alpha = 0
        p.xaxis.axis_label = 'Weeks'
        p.yaxis.axis_label = 'Story Points'
        p.ygrid.band_fill_color = 'olive'
        p.ygrid.band_fill_alpha = 0.1

        return p

    def build_remaining_types(self, stats_data):
        self.log.info('Generating graph about remaining effort per ticket type')

        plot_data = {}<commit_msg>Added bokeh tooltips<commit_after>import numpy as np

from bokeh.charts import Bar, output_file, save
from bokeh.layouts import layout
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool
from jav.core.javTime import Time


class BuildChart(object):
    def __init__(self, log, config):
        self.log = log
        self.config = config
        self.time = Time(self.log, self.config)

    def build_velocity_days(self, stats_data):
        self.log.info('Generating graph about daily effort')

        # Velocity Days
        x_dates = []
        y_points = []
        y_avg = []
        x_dates_display = []
        for scan_day in stats_data:
            x_dates.append(stats_data[scan_day]['datetime'])
            x_dates_display.append(stats_data[scan_day]['datetime'].strftime('%a %b %d, %Y'))
            y_points.append(stats_data[scan_day]['points'])
            week_idx = '4'
            if week_idx not in stats_data[scan_day]['anyday']:
                week_idx = 4
            if 'avg' in stats_data[scan_day]['anyday'][week_idx]:
                y_avg.append(stats_data[scan_day]['anyday'][week_idx]['avg'])
            else:
                y_avg.append(0)

        # prepare some data
        data_dates = np.array(x_dates, dtype=np.datetime64)

        source = ColumnDataSource(
            data=dict(
                x_data_dates=data_dates,
                y_points=y_points,
                y_avg_points=y_avg,
                x_dates_display=x_dates_display
            )
        )

        # Declare tools
        hover = HoverTool(
            tooltips=[
                ('Date', '@x_dates_display'),
                ('Points', '@y_points'),
                ('Average', '@y_avg_points'),
            ]
        )

        # create a new plot with a a datetime axis type
        p = figure(width=1000, height=350, x_axis_type='datetime', tools=['save','pan','box_zoom','reset', hover])

        # add renderers
        p.circle('x_data_dates', 'y_points', size=4, color='red', alpha=0.4, legend='Story Points', source=source)
        p.line('x_data_dates', 'y_avg_points', color='blue', legend='4 Weeks Average', source=source)

        # NEW: customize by setting attributes
        p.title.text = 'Daily Velocity'
        p.legend.location = 'top_left'
        p.grid.grid_line_alpha = 0
        p.xaxis.axis_label = 'Days (Monday-Friday)'
        p.yaxis.axis_label = 'Story Points'
        p.ygrid.band_fill_color = 'olive'
        p.ygrid.band_fill_alpha = 0.1

        return p

    def build_velocity_weeks(self, stats_data):
        self.log.info('Generating graph about weekly effort')

        # Velocity Days
        x_dates = []
        y_points = []
        y_avg = []
        y_weeks = []
        daily_avg = []
        for scan_day in stats_data:
            x_dates.append(stats_data[scan_day]['datetime'])
            y_points.append(stats_data[scan_day]['points'])
            y_weeks.append(stats_data[scan_day]['weektxt'])
            daily_avg.append(round(float(stats_data[scan_day]['points']) / 5, 1))

            if len(stats_data[scan_day]['stats']) > 0:
                week_idx = '4'
                if week_idx not in stats_data[scan_day]['stats']:
                    week_idx = 4
                if 'avg' in stats_data[scan_day]['stats'][week_idx]:
                    y_avg.append(stats_data[scan_day]['stats'][week_idx]['avg'])
                else:
                    y_avg.append(0)

        # prepare some data
        data_dates = np.array(x_dates, dtype=np.datetime64)

        source = ColumnDataSource(
            data=dict(
                x_data_dates=data_dates,
                y_points=y_points,
                y_avg_points=y_avg,
                y_weeks=y_weeks,
                daily_avg=daily_avg,
            )
        )

        # Declare tools
        hover = HoverTool(
            tooltips=[
                ('Week', '@y_weeks'),
                ('Points', '@y_points'),
                ('Avg points per week', '@y_avg_points'),
                ('Avg points per day', '@daily_avg'),
            ]
        )

        # create a new plot with a a datetime axis type
        p = figure(width=1000, height=350, x_axis_type='datetime', tools=['save','pan','box_zoom','reset', hover])

        # add renderers
        #p.circle(data_dates, y_points, size=4, color='red', alpha=0.4, legend='Story Points')
        #p.line(data_dates, y_avg, color='blue', legend='4 Weeks Average')
        p.circle('x_data_dates', 'y_points', size=4, color='red', alpha=0.4, legend='Story Points', source=source)
        p.line('x_data_dates', 'y_avg_points', color='blue', legend='4 Weeks Average', source=source)

        # NEW: customize by setting attributes
        p.title.text = 'Weekly Velocity'
        p.legend.location = 'top_left'
        p.grid.grid_line_alpha = 0
        p.xaxis.axis_label = 'Weeks'
        p.yaxis.axis_label = 'Story Points'
        p.ygrid.band_fill_color = 'olive'
        p.ygrid.band_fill_alpha = 0.1

        return p

    def build_remaining_types(self, stats_data):
        self.log.info('Generating graph about remaining effort per ticket type')

        plot_data = {}
{'fraction_non_alphanumeric': 0.11776083741039936, 'fraction_numerical': 0.00955740129707589, 'mean_word_length': 2.172140021652833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6686436', 'n_tokens_mistral': 2837, 'n_tokens_neox': 2682, 'n_words': 562}