def plot_increasingPerturbation_percentageSuccess(path,
                                                  filename,
                                                  output,
                                                  subject,
                                                  indexN,
                                                  indexLoc,
                                                  columnLoc,
                                                  offsetStart=0):
    '''
    this function is used to generate the plot of the increasing magnitudes and random rates.
    '''

    lines = [line.rstrip('\n') for line in open(path + "/" + filename)]

    labelOfN = ' '.join(lines[indexN].split()).split(" ")[0]
    if "IntegerMagnitudeSys" == output:
        n = ' '.join(lines[indexN].split()).split(" ")[3:]
    else:
        n = [0.0] + (' '.join(lines[indexN].split()).split(" ")[3:])

    numberOfLocation = int(' '.join(lines[indexLoc].split()).split(" ")[0])

    percAll = []
    nAll = []
    callAll = []
    perturbAll = []
    indicesLocation = []
    i = 8 + offsetStart

    while i < (numberOfLocation * len(n)) + 1:  #numberOfLocation:

        perc = []
        my_n = []
        my_call = 0
        my_perturb = 0

        for line in lines[i:i + len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(
                ',', '.'))
            if point == point:
                perc.append(point)
            else:
                perc.append(float(100.0))
            my_call += int(' '.join(
                line.split()).split(" ")[5 + offsetStart].replace(',', '.'))
            my_perturb += int(' '.join(
                line.split()).split(" ")[6 + offsetStart].replace(',', '.'))
            my_n.append(n[lines[i:i + len(n)].index(line)])

        if perc not in percAll and len(perc) > 0 and [p == p for p in perc]:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[columnLoc]
            indicesLocation.append(indexOfLocation)
            percAll.append(perc)
            nAll.append(my_n)
            callAll.append(my_call)
            perturbAll.append(my_perturb)

        i += len(n)

    sortedPerc, indicesLocation = [
        list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation),
                                          key=lambda pair: -pair[0][-1]))
    ]
    sortedPerc, callAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, callAll), key=lambda pair: -pair[0][-1]))
    ]
    sortedPerc, perturbAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][-1]))
    ]
    percAll, nAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, nAll), key=lambda pair: -pair[0][-1]))
    ]

    indexToCutAll = []
    for i in range(len(percAll)):
        indexToCut = len(percAll[i]) - 1
        while indexToCut > 1:
            if percAll[i][indexToCut] == percAll[i][indexToCut - 1]:
                indexToCut -= 1
            else:
                break
        indexToCutAll.append(indexToCut +
                             1 if indexToCut < len(percAll[i]) else indexToCut)

    indexToCut = max(indexToCutAll)

    sortedPerc, indicesLocation = [
        list(x) for x in zip(*sorted(zip(percAll, indicesLocation),
                                     key=lambda pair: -pair[0][0]))
    ]
    sortedPerc, callAll = [
        list(x) for x in zip(
            *sorted(zip(percAll, callAll), key=lambda pair: -pair[0][0]))
    ]
    sortedPerc, perturbAll = [
        list(x) for x in zip(
            *sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][0]))
    ]
    percAll, nAll = [
        list(x)
        for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][0]))
    ]

    print(len(nAll))

    fig = plt.figure()
    ax = fig.add_axes((.1, .4, .8, .5))
    for i in range(len(percAll)):
        cut = min(indexToCut, len(percAll[i]))
        color = colors_manager.getColor(int(indicesLocation[i]))
        plt.plot(nAll[i][:cut],
                 percAll[i][:cut],
                 marker='x',
                 label=str(indicesLocation[i] + " " + str(int(percAll[i][0])) +
                           " %"),
                 color=color)
    plt.xlabel(labelOfN)
    plt.ylabel("% success")
    box = ax.get_position()
    txt = ""
    for line in lines[0:7]:
        txt += line + "\n"
    width = 8
    txt += '{0:{width}} {1:{width}} {2:{width}}'.format("Loc",
                                                        "#Call",
                                                        "#Perturbation",
                                                        width=width)
    txt += '\n'
    for i in range(len(callAll)):
        txt += '{0:{width}} {1:{width}} {2:{width}}'.format(indicesLocation[i],
                                                            str(callAll[i]),
                                                            str(perturbAll[i]),
                                                            width=width)
        txt += '\n'

    text = fig.text(.1, -.45, txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig(path + "/img/" + output + "_plot.jpeg",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output + "_plot.pdf",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    ax.set_xscale('log')
    fig.savefig(path + "/img/" + output + "_plot_logscale.pdf",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output + "_plot_logscale.jpeg",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')

    fig = plt.figure()

    percOverAllLoc = []
    for i in range(len(percAll[0])):
        perc = 0.0
        for j in range(len(percAll)):
            perc += percAll[j][i]
        percOverAllLoc.append(float(float(perc) / float(len(percAll[j]))))

    plt.plot(n, percOverAllLoc, marker='x', label="% success")

    plt.xlabel(labelOfN)
    plt.ylabel("% success")

    box = ax.get_position()
    txt = "Aggregation of the whole results over locations."
    text = fig.text(.1, -.1, txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

    fig.savefig(path + "/img/" + output + "plotAll.pdf",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')

    plt.close(fig)
def scatterPlotSuccessNumPerturb(path, filename, output, subject):
    lines = [line.rstrip('\n') for line in open(path + "/" + filename)]

    n = [0.0] + ' '.join(lines[4].split()).split(" ")[3:]
    stepi = len(n)
    numberOfLocation = int(' '.join(lines[2].split()).split(" ")[0])

    repeat = int(' '.join(lines[5].split()).split(" ")[0])
    nbTask = int(' '.join(lines[6].split()).split(" ")[0])

    nbExec = float(repeat * nbTask)

    percAll = []
    nbPerturbAll = []
    labelsAll = []
    indicesLocation = []
    nbCallAll = []
    i = 9

    while i < (numberOfLocation * len(n)) + 1:  #numberOfLocation:

        perc = []
        label = []
        nbPerturb = []
        nbCall = []

        for line in lines[i:i + len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(
                ',', '.'))
            if point == point:
                perc.append(point)
                nbPerturb.append(
                    int(' '.join(line.split()).split(" ")[7].replace(',',
                                                                     '.')))
                nbCall.append(
                    int(' '.join(line.split()).split(" ")[6].replace(',',
                                                                     '.')))

        label.append(
            str(' '.join(lines[i].split()).split(" ")[0].replace(',', '.')))
        label.append(
            str(' '.join(lines[i +
                               (len(n)) / 2].split()).split(" ")[0].replace(
                                   ',', '.')))
        label.append(
            str(' '.join(lines[i + len(n) - 1].split()).split(" ")[0].replace(
                ',', '.')))

        if not perc in percAll and not len(perc) == 0:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[2]
            indicesLocation.append(indexOfLocation)

            labelsAll.append(label)
            nbPerturbAll.append(nbPerturb)
            percAll.append(perc)
            nbCallAll.append(nbCall)

        i += stepi

    sortedPerc, indicesLocation = [
        list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation),
                                          key=lambda pair: -pair[0][-1]))
    ]
    sortedPerc, nbPerturbAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, nbPerturbAll), key=lambda pair: -pair[0][-1]))
    ]
    percAll, nbCallAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, nbCallAll), key=lambda pair: -pair[0][-1]))
    ]

    sortedPerc, indicesLocation = [
        list(x) for x in zip(*sorted(zip(percAll, indicesLocation),
                                     key=lambda pair: -pair[0][0]))
    ]
    sortedPerc, nbPerturbAll = [
        list(x) for x in zip(
            *sorted(zip(percAll, nbPerturbAll), key=lambda pair: -pair[0][0]))
    ]
    percAll, nbCallAll = [
        list(x) for x in zip(
            *sorted(zip(percAll, nbCallAll), key=lambda pair: -pair[0][0]))
    ]

    fig = plt.figure()
    ax = fig.add_axes((.1, .4, .8, .5))
    for i in range(len(percAll)):
        mid = len(percAll[i]) / 2
        color = colors_manager.getColor(int(indicesLocation[i]))
        x = [
            float(
                float(nbPerturbAll[i][len(nbPerturbAll[i]) -
                                      len(percAll[i]):][z]) / nbExec)
            for z in range(
                len(nbCallAll[i][len(nbCallAll[i]) - len(percAll[i]):]))
        ]
        plt.plot(x,
                 percAll[i],
                 color=color,
                 marker='x',
                 label=str(indicesLocation[i] + " " + str(int(percAll[i][0])) +
                           " %"))
        for z in [0, -1, mid]:
            x = float(float(nbPerturbAll[i][z]) / nbExec)
            ax.annotate(labelsAll[i][z if z != mid else 1],
                        xy=(x, percAll[i][z]),
                        xytext=(0.5, 5),
                        textcoords='offset points',
                        size=5)

    plt.xlabel("Avg perturbation per exec")
    plt.ylabel("% success")
    plt.title(subject)

    txt = "Annotation are the probability rate of enaction\n"
    for line in lines[0:7]:
        txt += line + "\n"
    text = fig.text(.1, -.1, txt)

    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig(path + "/img/" + output + "scatterPlotSuccessNumPerturb.pdf",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output + "scatterPlotSuccessNumPerturb.jpeg",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    ax.set_xscale('symlog')
    fig.savefig(path + "/img/" + output +
                "scatterPlotSuccessNumPerturb_log.pdf",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output +
                "scatterPlotSuccessNumPerturb_log.jpeg",
                bbox_extra_artists=(lgd, text),
                bbox_inches='tight')
    plt.close(fig)
def plot(subject, type):

    print(subject, type)

    lines = [line.rstrip('\n') for line in open("results/"+subject+"/"+type+"_RandomExplorer_analysis_graph_data.txt")]

    numberOfLocation = int(' '.join(lines[7].split()).split(" ")[0])
    n = [0.0]  + (' '.join(lines[3].split()).split(" ")[3:])
    repeat = int(' '.join(lines[4].split()).split(" ")[0])
    i = 9

    percAll=[]
    nAll=[]
    callAll=[]
    perturbAll=[]
    indicesLocation=[]
    percAll=[]
    xaxis=[]

    while i < (numberOfLocation*len(n)) + 1:

        perc=[]
        my_n = []
        my_x = []
        my_call = 0
        my_perturb = 0

        for line in lines[i:i+len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(',','.'))
            if point == point:
                perc.append(point)
            else:
                perc.append(float(100.0))
            my_call += int(' '.join(line.split()).split(" ")[6].replace(',','.'))
            my_perturb += int(' '.join(line.split()).split(" ")[7].replace(',','.'))
            my_x.append(int(' '.join(line.split()).split(" ")[7].replace(',','.')) / repeat)
            my_n.append(n[lines[i:i+len(n)].index(line)])

        if perc not in percAll and len(perc) > 0 and [p == p for p in perc]:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[2]
            indicesLocation.append(indexOfLocation)
            percAll.append(perc)
            nAll.append(my_n)
            callAll.append(my_call)
            perturbAll.append(my_perturb)
            xaxis.append(my_x)

        i+=len(n)


    sortedPerc, indicesLocation = [list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][-1]))]
    sortedPerc, callAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, callAll), key=lambda pair: -pair[0][-1]))]
    sortedPerc, perturbAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][-1]))]
    sortedPerc, xaxis = [list(x)[:10] for x in zip(*sorted(zip(percAll,xaxis), key=lambda pair: -pair[0][-1]))]
    percAll, nAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][-1]))]

    sortedPerc, indicesLocation = [list(x) for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][0]))]
    sortedPerc, callAll = [list(x) for x in zip(*sorted(zip(percAll, callAll), key=lambda pair: -pair[0][0]))]
    sortedPerc, perturbAll = [list(x) for x in zip(*sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][0]))]
    sortedPerc, xaxis = [list(x) for x in zip(*sorted(zip(percAll, xaxis), key=lambda pair: -pair[0][0]))]
    percAll, nAll = [list(x) for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][0]))]

    fig = plt.figure()
    ax = fig.add_axes((.1,.4,.8,.5))
    for i in range(len(percAll)):
        color = colors_manager.getColor(int(indicesLocation[i]))
        plt.plot(xaxis[i], percAll[i], marker='x', label=str(indicesLocation[i]+ " " + str(int(percAll[i][0])) + " %"), color=color)
    plt.xlabel("#perturbation per exec")
    plt.ylabel("% success")
    box = ax.get_position()
    txt = ""
    for line in lines[0:7]:
        txt += line +"\n"
    width = 8
    txt+= '{0:{width}} {1:{width}} {2:{width}}'.format("Loc","#Call", "#Perturbation", width=width)
    txt+='\n'
    for i in range(len(callAll)):
        txt+='{0:{width}} {1:{width}} {2:{width}}'.format(indicesLocation[i],str(callAll[i]),str(perturbAll[i]), width=width)
        txt+='\n'

    text = fig.text(.1,-.45,txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig("results/"+subject+"/img/"+type+"_PerturPerExecution_plot.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    fig.savefig("results/"+subject+"/img/"+type+"_PerturPerExecution_plot.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    ax.set_xscale('log')
    fig.savefig("results/"+subject+"/img/"+type+"_PerturPerExecution_plot_logscale.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    fig.savefig("results/"+subject+"/img/"+type+"_PerturPerExecution_plot_logscale.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')
def scatterPlotSuccessNumPerturb(path, filename, output, subject):
     lines = [line.rstrip('\n') for line in open(path+"/"+filename)]

     n = [0.0] + ' '.join(lines[4].split()).split(" ")[3:]
     stepi = len(n)
     numberOfLocation = int(' '.join(lines[2].split()).split(" ")[0])

     repeat = int(' '.join(lines[5].split()).split(" ")[0])
     nbTask = int(' '.join(lines[6].split()).split(" ")[0])

     nbExec = float(repeat * nbTask)

     percAll=[]
     nbPerturbAll=[]
     labelsAll=[]
     indicesLocation=[]
     nbCallAll=[]
     i = 9

     while i < (numberOfLocation*len(n))+1:#numberOfLocation:

        perc=[]
        label=[]
        nbPerturb=[]
        nbCall=[]

        for line in lines[i:i+len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(',','.'))
            if point == point:
                perc.append(point)
                nbPerturb.append(int(' '.join(line.split()).split(" ")[7].replace(',','.')))
                nbCall.append(int(' '.join(line.split()).split(" ")[6].replace(',','.')))

        label.append(str(' '.join(lines[i].split()).split(" ")[0].replace(',','.')))
        label.append(str(' '.join(lines[i+(len(n))/2].split()).split(" ")[0].replace(',','.')))
        label.append(str(' '.join(lines[i+len(n)-1].split()).split(" ")[0].replace(',','.')))

        if not perc in percAll and not len(perc) == 0:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[2]
            indicesLocation.append(indexOfLocation)

            labelsAll.append(label)
            nbPerturbAll.append(nbPerturb)
            percAll.append(perc)
            nbCallAll.append(nbCall)

        i+=stepi

     sortedPerc, indicesLocation = [list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][-1]))]
     sortedPerc, nbPerturbAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, nbPerturbAll), key=lambda pair: -pair[0][-1]))]
     percAll, nbCallAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, nbCallAll), key=lambda pair: -pair[0][-1]))]

     sortedPerc, indicesLocation = [list(x) for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][0]))]
     sortedPerc, nbPerturbAll = [list(x) for x in zip(*sorted(zip(percAll, nbPerturbAll), key=lambda pair: -pair[0][0]))]
     percAll, nbCallAll = [list(x) for x in zip(*sorted(zip(percAll, nbCallAll), key=lambda pair: -pair[0][0]))]

     fig = plt.figure()
     ax = fig.add_axes((.1,.4,.8,.5))
     for i in range(len(percAll)):
         mid = len(percAll[i]) / 2
         color = colors_manager.getColor(int(indicesLocation[i]))
         x = [float(float(nbPerturbAll[i][len(nbPerturbAll[i])-len(percAll[i]):][z]) / nbExec)
              for z in range(len(nbCallAll[i][len(nbCallAll[i])-len(percAll[i]):]))]
         plt.plot(x , percAll[i], color=color, marker='x', label=str(indicesLocation[i]+" "+ str(int(percAll[i][0]))+ " %"))
         for z in [0,-1,mid]:
            x = float( float(nbPerturbAll[i][z]) / nbExec)
            ax.annotate(labelsAll[i][z if z != mid else 1], xy = (x, percAll[i][z]),
                        xytext=(0.5, 5), textcoords='offset points', size=5)

     plt.xlabel("Avg perturbation per exec")
     plt.ylabel("% success")
     plt.title(subject)

     txt = "Annotation are the probability rate of enaction\n"
     for line in lines[0:7]:
         txt += line +"\n"
     text = fig.text(.1,-.1,txt)

     box = ax.get_position()
     ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
     lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
     fig.savefig(path+"/img/"+output+"scatterPlotSuccessNumPerturb.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
     fig.savefig(path+"/img/"+output+"scatterPlotSuccessNumPerturb.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')
     ax.set_xscale('symlog')
     fig.savefig(path+"/img/"+output+"scatterPlotSuccessNumPerturb_log.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
     fig.savefig(path+"/img/"+output+"scatterPlotSuccessNumPerturb_log.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')
     plt.close(fig)
def plot_increasingPerturbation_percentageSuccess(path, filename, output, subject, indexN, indexLoc, columnLoc, offsetStart=0):

    '''
    this function is used to generate the plot of the increasing magnitudes and random rates.
    '''

    lines = [line.rstrip('\n') for line in open(path+"/"+filename)]


    labelOfN = ' '.join(lines[indexN].split()).split(" ")[0]
    if "IntegerMagnitudeSys" == output:
        n =  ' '.join(lines[indexN].split()).split(" ")[3:]
    else:
        n = [0.0]  + (' '.join(lines[indexN].split()).split(" ")[3:])

    numberOfLocation = int(' '.join(lines[indexLoc].split()).split(" ")[0])

    percAll=[]
    nAll=[]
    callAll=[]
    perturbAll=[]
    indicesLocation=[]
    i = 8 + offsetStart

    while i < (numberOfLocation*len(n)) + 1:#numberOfLocation:

        perc=[]
        my_n = []
        my_call = 0
        my_perturb = 0

        for line in lines[i:i+len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(',','.'))
            if point == point:
                perc.append(point)
            else:
                perc.append(float(100.0))
            my_call += int(' '.join(line.split()).split(" ")[5+offsetStart].replace(',','.'))
            my_perturb += int(' '.join(line.split()).split(" ")[6+offsetStart].replace(',','.'))
            my_n.append(n[lines[i:i+len(n)].index(line)])


        if perc not in percAll and len(perc) > 0 and [p == p for p in perc]:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[columnLoc]
            indicesLocation.append(indexOfLocation)
            percAll.append(perc)
            nAll.append(my_n)
            callAll.append(my_call)
            perturbAll.append(my_perturb)

        i+=len(n)

    sortedPerc, indicesLocation = [list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][-1]))]
    sortedPerc, callAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, callAll), key=lambda pair: -pair[0][-1]))]
    sortedPerc, perturbAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][-1]))]
    percAll, nAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][-1]))]

    indexToCutAll = []
    for i in range(len(percAll)):
        indexToCut = len(percAll[i])-1
        while indexToCut > 1:
            if percAll[i][indexToCut] == percAll[i][indexToCut-1]:
                indexToCut -= 1
            else:
                break;
        indexToCutAll.append(indexToCut+1 if indexToCut < len(percAll[i]) else indexToCut)

    indexToCut = max(indexToCutAll)

    sortedPerc, indicesLocation = [list(x) for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][0]))]
    sortedPerc, callAll = [list(x) for x in zip(*sorted(zip(percAll, callAll), key=lambda pair: -pair[0][0]))]
    sortedPerc, perturbAll = [list(x) for x in zip(*sorted(zip(percAll, perturbAll), key=lambda pair: -pair[0][0]))]
    percAll, nAll = [list(x) for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][0]))]

    print(len(nAll))

    fig = plt.figure()
    ax = fig.add_axes((.1,.4,.8,.5))
    for i in range(len(percAll)):
        cut = min(indexToCut, len(percAll[i]))
        color = colors_manager.getColor(int(indicesLocation[i]))
        plt.plot(nAll[i][:cut], percAll[i][:cut], marker='x', label=str(indicesLocation[i]+ " " + str(int(percAll[i][0])) + " %"), color=color)
    plt.xlabel(labelOfN)
    plt.ylabel("% success")
    box = ax.get_position()
    txt = ""
    for line in lines[0:7]:
        txt += line +"\n"
    width = 8
    txt+= '{0:{width}} {1:{width}} {2:{width}}'.format("Loc","#Call", "#Perturbation", width=width)
    txt+='\n'
    for i in range(len(callAll)):
        txt+='{0:{width}} {1:{width}} {2:{width}}'.format(indicesLocation[i],str(callAll[i]),str(perturbAll[i]), width=width)
        txt+='\n'

    text = fig.text(.1,-.45,txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig(path+"/img/"+output+"_plot.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    fig.savefig(path+"/img/"+output+"_plot.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    ax.set_xscale('log')
    fig.savefig(path+"/img/"+output+"_plot_logscale.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')
    fig.savefig(path+"/img/"+output+"_plot_logscale.jpeg", bbox_extra_artists=(lgd,text), bbox_inches='tight')

    fig = plt.figure()

    percOverAllLoc = []
    for i in range(len(percAll[0])):
        perc = 0.0
        for j in range(len(percAll)):
            perc += percAll[j][i]
        percOverAllLoc.append(float(float(perc) / float(len(percAll[j]))))

    plt.plot(n, percOverAllLoc, marker='x', label="% success")

    plt.xlabel(labelOfN)
    plt.ylabel("% success")

    box = ax.get_position()
    txt = "Aggregation of the whole results over locations."
    text = fig.text(.1,-.1,txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

    fig.savefig(path+"/img/"+output+"plotAll.pdf", bbox_extra_artists=(lgd,text), bbox_inches='tight')

    plt.close(fig)
def plot_increasingNbTask_percentageSuccess(path, filename, output, subject, logscale=False):

    lines = [line.rstrip('\n') for line in open(path+"/"+filename)]

    labelOfN = ' '.join(lines[2].split()).split(" ")[0]
    n = ' '.join(lines[2].split()).split(" ")[3:]
    numberOfLocation = int(' '.join(lines[3].split()).split(" ")[0])



    percAll=[]
    nAll=[]
    indicesLocation=[]

    percSave = []
    nSave = []
    indiceSave = []

    i = 9

    while i < (numberOfLocation*len(n)):#numberOfLocation:

        perc=[]
        my_n = []

        for line in lines[i:i+len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(',','.'))

            if point == point:
                perc.append(point)
            else:
                perc.append(float(100.0))

            my_n.append(n[lines[i:i+len(n)].index(line)])

        if not perc in percAll and len(perc) > 0 and [p == p for p in perc]:#and not perc[1:] == perc[:-1]:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[1]
            indicesLocation.append(indexOfLocation)
            percAll.append(perc)
            nAll.append(my_n)

        i+=len(n)

    sortedPerc, indicesLocation = [list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][-1]))]
    percAll, nAll = [list(x)[:10] for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][-1]))]

    indexToCutAll = []
    for i in range(len(percAll)):
        indexToCut = len(percAll[i])-1
        while indexToCut > 1:
            if abs(percAll[i][indexToCut] - percAll[i][indexToCut-1]) < 0:
                indexToCut -= 1
            else:
                break;
        indexToCutAll.append(indexToCut)

    indexToCut = max(indexToCutAll)

    sortedPerc, indicesLocation = [list(x) for x in zip(*sorted(zip(percAll, indicesLocation), key=lambda pair: -pair[0][0]))]
    percAll, nAll = [list(x) for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][0]))]

    fig = plt.figure()
    ax = fig.add_axes((.1,.4,.8,.5))
    for i in range(len(percAll)):
        cut = len(percAll[i])
        #cut = min(indexToCut, len(percAll[i]))
        color = colors_manager.getColor(int(indicesLocation[i]))
        plt.plot(nAll[i][:cut], percAll[i][:cut], marker='x', color=color, label=str(indicesLocation[i]+ " " + str(int(percAll[i][0])) + " %"))
    plt.xlabel(labelOfN)
    plt.ylabel("% success")
    box = ax.get_position()
    txt = ""
    for line in lines[0:7]:
        txt += line +"\n"
    text = fig.text(.1,-.10,txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.7, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig(path+"/img/"+output+"_plot.pdf", bbox_extra_artists=(text,), bbox_inches='tight')
    fig.savefig(path+"/img/"+output+"_plot.jpeg", bbox_extra_artists=(text,), bbox_inches='tight')
    ax.set_xscale('log')
    fig.savefig(path+"/img/"+output+"_plot_logscale.pdf", bbox_extra_artists=(text,), bbox_inches='tight')
    fig.savefig(path+"/img/"+output+"_plot_logscale.jpeg", bbox_extra_artists=(text,), bbox_inches='tight')
    plt.close(fig)
Example #7
0
def plot_increasingNbTask_percentageSuccess(path,
                                            filename,
                                            output,
                                            subject,
                                            logscale=False):

    lines = [line.rstrip('\n') for line in open(path + "/" + filename)]

    labelOfN = ' '.join(lines[2].split()).split(" ")[0]
    n = ' '.join(lines[2].split()).split(" ")[3:]
    numberOfLocation = int(' '.join(lines[3].split()).split(" ")[0])

    percAll = []
    nAll = []
    indicesLocation = []

    percSave = []
    nSave = []
    indiceSave = []

    i = 9

    while i < (numberOfLocation * len(n)):  #numberOfLocation:

        perc = []
        my_n = []

        for line in lines[i:i + len(n)]:
            point = float(' '.join(line.split()).split(" ")[-1].replace(
                ',', '.'))

            if point == point:
                perc.append(point)
            else:
                perc.append(float(100.0))

            my_n.append(n[lines[i:i + len(n)].index(line)])

        if not perc in percAll and len(perc) > 0 and [
                p == p for p in perc
        ]:  #and not perc[1:] == perc[:-1]:
            indexOfLocation = ' '.join(lines[i].split()).split(" ")[1]
            indicesLocation.append(indexOfLocation)
            percAll.append(perc)
            nAll.append(my_n)

        i += len(n)

    sortedPerc, indicesLocation = [
        list(x)[:10] for x in zip(*sorted(zip(percAll, indicesLocation),
                                          key=lambda pair: -pair[0][-1]))
    ]
    percAll, nAll = [
        list(x)[:10] for x in zip(
            *sorted(zip(percAll, nAll), key=lambda pair: -pair[0][-1]))
    ]

    indexToCutAll = []
    for i in range(len(percAll)):
        indexToCut = len(percAll[i]) - 1
        while indexToCut > 1:
            if abs(percAll[i][indexToCut] - percAll[i][indexToCut - 1]) < 0:
                indexToCut -= 1
            else:
                break
        indexToCutAll.append(indexToCut)

    indexToCut = max(indexToCutAll)

    sortedPerc, indicesLocation = [
        list(x) for x in zip(*sorted(zip(percAll, indicesLocation),
                                     key=lambda pair: -pair[0][0]))
    ]
    percAll, nAll = [
        list(x)
        for x in zip(*sorted(zip(percAll, nAll), key=lambda pair: -pair[0][0]))
    ]

    fig = plt.figure()
    ax = fig.add_axes((.1, .4, .8, .5))
    for i in range(len(percAll)):
        cut = len(percAll[i])
        #cut = min(indexToCut, len(percAll[i]))
        color = colors_manager.getColor(int(indicesLocation[i]))
        plt.plot(nAll[i][:cut],
                 percAll[i][:cut],
                 marker='x',
                 color=color,
                 label=str(indicesLocation[i] + " " + str(int(percAll[i][0])) +
                           " %"))
    plt.xlabel(labelOfN)
    plt.ylabel("% success")
    box = ax.get_position()
    txt = ""
    for line in lines[0:7]:
        txt += line + "\n"
    text = fig.text(.1, -.10, txt)
    plt.title(subject)
    ax.set_position([box.x0, box.y0, box.width * 0.7, box.height])
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    fig.savefig(path + "/img/" + output + "_plot.pdf",
                bbox_extra_artists=(text, ),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output + "_plot.jpeg",
                bbox_extra_artists=(text, ),
                bbox_inches='tight')
    ax.set_xscale('log')
    fig.savefig(path + "/img/" + output + "_plot_logscale.pdf",
                bbox_extra_artists=(text, ),
                bbox_inches='tight')
    fig.savefig(path + "/img/" + output + "_plot_logscale.jpeg",
                bbox_extra_artists=(text, ),
                bbox_inches='tight')
    plt.close(fig)