<commit_before>from core import cached_pathfinder
import sys, time
import scipy.stats as spst
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from numpy.random import normal
from pylab import *
from scipy.stats import gaussian_kde

def violin_plot(ax,data,pos, bp=False):
    '''
    create violin plots on an axis
    '''
    dist = max(pos)-min(pos)
    w = min(0.15*max(dist,1.0),0.5)
    for d,p in zip(data,pos):
        k = gaussian_kde(d) #calculates the kernel density
        m = k.dataset.min() #lower bound of violin
        M = k.dataset.max() #upper bound of violin
        x = arange(m,M,(M-m)/100.) # support for violin
        v = k.evaluate(x) #violin profile (density curve)
        v = v/v.max()*w #scaling the violin to the available space
        ax.fill_betweenx(x,p,v+p,facecolor='b',alpha=0.2)
        ax.fill_betweenx(x,p,-v+p,facecolor='b',alpha=0.2)
    if bp:
        ax.boxplot(data,notch=0,positions=pos,vert=1, whis=1)

def plot(cpf = cached_pathfinder.CachedPathFinder()):
    total_paths = cpf.loadStoredPaths(max=None)
    #print(total_paths)
    #print(cpf.path_execution_times)
    
    x = list()
    y = list()
    topop = set()
    et = cpf.path_execution_times
    et.pop(len(cpf.path_execution_times))
    for length in et:
        if len(et[length]) > 1:
            for execution_time in et[length]:
                x.append(length)
                y.append(execution_time)
        else:
            topop.add(length)
    
    for pop in topop:
        cpf.path_execution_times.pop(pop)
        
    #print (x)
    #print (y)

    fig = Figure(figsize=(7,6))
    
    # Create a canvas and add the figure to it.
    canvas = FigureCanvas(fig)
    
    # Create a subplot.
    ax = fig.add_subplot(111)
    
    # Set the title.
    ax.set_title('Execution time in function of path length (n = %s)' % total_paths,fontsize=12)
    
    # Set the X Axis label.
    ax.set_xlabel('(steps)',fontsize=9)
    
    # Set the Y Axis label.
    ax.set_ylabel('(ms)',fontsize=9)
    
    ax.set_yscale('log')
    
    #ax.set_ylim([0,(np.int(np.max(y)/10000)+1)*10000])
    ax.set_xlim([0,(np.int(np.max(x))+1)])
    
    # Display Grid.
    ax.grid(True,linestyle='-',color='0.75')
    
    # Generate the Scatter Plot.
    # ax.scatter(x,y,s=4,color='tomato')
    
    # fake up some more data
    datas = list()
    w = 0.5
    
    for length in et:
        sorted = np.sort(et[length])
        spread = sorted
        center = ones(len(sorted)) * np.median(sorted)
        data = concatenate((spread, center), 0)
        data.shape = (-1, 1)
        datas.append(data)
    
    violin_plot(ax,list(et.values()),range(1,len(et)+1),bp=True)
        
    # Making a 2-D array only works if all the columns are the
    # same length.  If they are not, then use a list instead.
    # This is actually more efficient because boxplot converts
    # a 2-D array into a list of vectors internally anyway.
    # multiple box plots on one figure
    # ax.boxplot(datas,0,'rx',1,1.99)
    
    
    try:
        path = "/tmp/scatter_{0}_{1}.png".format(hash(time.time()),np.random.randint(10000))
        canvas.print_figure(path)
    except:
        pass
        #print (sys.exc_info())
    return path<commit_msg>fix, creating tons of plots, changed to 1<commit_after>from core import cached_pathfinder
import sys, time
import scipy.stats as spst
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from numpy.random import normal
from pylab import *
from scipy.stats import gaussian_kde

def violin_plot(ax,data,pos, bp=False):
    '''
    create violin plots on an axis
    '''
    dist = max(pos)-min(pos)
    w = min(0.15*max(dist,1.0),0.5)
    for d,p in zip(data,pos):
        k = gaussian_kde(d) #calculates the kernel density
        m = k.dataset.min() #lower bound of violin
        M = k.dataset.max() #upper bound of violin
        x = arange(m,M,(M-m)/100.) # support for violin
        v = k.evaluate(x) #violin profile (density curve)
        v = v/v.max()*w #scaling the violin to the available space
        ax.fill_betweenx(x,p,v+p,facecolor='b',alpha=0.2)
        ax.fill_betweenx(x,p,-v+p,facecolor='b',alpha=0.2)
    if bp:
        ax.boxplot(data,notch=0,positions=pos,vert=1, whis=1)

def plot(cpf = cached_pathfinder.CachedPathFinder()):
    total_paths = cpf.loadStoredPaths(max=None)
    #print(total_paths)
    #print(cpf.path_execution_times)
    
    x = list()
    y = list()
    topop = set()
    et = cpf.path_execution_times
    et.pop(len(cpf.path_execution_times))
    for length in et:
        if len(et[length]) > 1:
            for execution_time in et[length]:
                x.append(length)
                y.append(execution_time)
        else:
            topop.add(length)
    
    for pop in topop:
        cpf.path_execution_times.pop(pop)
        
    #print (x)
    #print (y)

    fig = Figure(figsize=(7,6))
    
    # Create a canvas and add the figure to it.
    canvas = FigureCanvas(fig)
    
    # Create a subplot.
    ax = fig.add_subplot(111)
    
    # Set the title.
    ax.set_title('Execution time in function of path length (n = %s)' % total_paths,fontsize=12)
    
    # Set the X Axis label.
    ax.set_xlabel('(steps)',fontsize=9)
    
    # Set the Y Axis label.
    ax.set_ylabel('(ms)',fontsize=9)
    
    ax.set_yscale('log')
    
    #ax.set_ylim([0,(np.int(np.max(y)/10000)+1)*10000])
    ax.set_xlim([0,(np.int(np.max(x))+1)])
    
    # Display Grid.
    ax.grid(True,linestyle='-',color='0.75')
    
    # Generate the Scatter Plot.
    # ax.scatter(x,y,s=4,color='tomato')
    
    # fake up some more data
    datas = list()
    w = 0.5
    
    for length in et:
        sorted = np.sort(et[length])
        spread = sorted
        center = ones(len(sorted)) * np.median(sorted)
        data = concatenate((spread, center), 0)
        data.shape = (-1, 1)
        datas.append(data)
    
    violin_plot(ax,list(et.values()),range(1,len(et)+1),bp=True)
        
    # Making a 2-D array only works if all the columns are the
    # same length.  If they are not, then use a list instead.
    # This is actually more efficient because boxplot converts
    # a 2-D array into a list of vectors internally anyway.
    # multiple box plots on one figure
    # ax.boxplot(datas,0,'rx',1,1.99)
    
    
    try:
        #path = "/tmp/scatter_{0}_{1}.png".format(hash(time.time()),np.random.randint(10000))
        path = "/tmp/scatter.png"
        canvas.print_figure(path)
    except:
        pass
        #print (sys.exc_info())
    return path
{'fraction_non_alphanumeric': 0.12622495246453122, 'fraction_numerical': 0.019452976451660085, 'mean_word_length': 2.5356773526370215, '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': '6879727', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2384, 'n_words': 580}