<commit_before>#!/usr/bin/env python3

#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Authors:
# <NAME> <<EMAIL>>, http://caner.candan.fr
#

# http://stackoverflow.com/questions/14952401/creating-double-boxplots-i-e-two-boxes-for-each-x-value

import sys, os
import argparse, logging
import pylab as pl
import numpy as np

logger = logging.getLogger("boxplot")

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='To trace boxplot.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('--prefix', '-p', help='monitor prefix name', default='result')
    parser.add_argument('--islands', '-N', help='number of islands', type=int, default=4)
    parser.add_argument('--times', '-T', help='number of times', type=int, default=10000)
    parser.add_argument('--runs', '-R', help='number of runs', type=int, default=21)

    # if len(sys.argv) < 5:
    #     print("Usage:", os.path.basename(sys.argv[0]), "[MONITOR_PREFIX_NAME] [NUMBER_OF_ISLANDS] [NUMBER_OF_TIMES] [NUMBER_OF_RUNS]")
    #     sys.exit()

    args = parser.parse_args()

    # prefix = sys.argv[1]
    # Ni = int(sys.argv[2])
    # Nt = int(sys.argv[3])
    # Nr = int(sys.argv[4])

    V = []
    for i in range(args.islands):
        files = []
        for r in range(args.runs):
            fn = "%s_%d_monitor_%d" % (args.prefix, r+1, i)
            print("Pre-opening of run files…", fn)
            f = open(fn)
            files += [(fn, f)]
            f.readline() # to ignore first line

        T = []
        for t in range(args.times):
            R = []
            for r in range(args.runs):
                fn, f = files[r]
                nbindi = int(f.readline().split()[2])
                print("Reading…", fn, "with time…", t, "and nbindi", nbindi)
                R += [nbindi]
            T += [R]

        V += [T]

    colors = ['green', 'black', 'orange', 'red', 'blue', 'gray', 'yellow']
    space = .15
    pos = np.linspace(args.islands/2*space, -args.islands/2*space, args.islands).T

    for i in range(args.islands):
        r = pl.boxplot(V[i], positions=[x-pos[i] for x in range(args.times)], widths=0.1)
        for value in r.values(): pl.setp(value, color=colors[i%len(colors)])

    pl.legend(["isl %s (%s)" % (i, colors[i]) for i in range(args.islands)])
    pl.xlabel('Time')
    pl.ylabel('Nb individuals')
    pl.xticks([x for x in range(args.times)])
    pl.xlim(-args.islands/2*space*2, (args.times-1)+args.islands/2*space*2)
    pl.show()<commit_msg>* ../../../scripts/boxplot.py: added more options<commit_after>#!/usr/bin/env python3

#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Authors:
# <NAME> <<EMAIL>>, http://caner.candan.fr
#

# http://stackoverflow.com/questions/14952401/creating-double-boxplots-i-e-two-boxes-for-each-x-value

import argparse, logging

logger = logging.getLogger("boxplot")

def main():
    parser = argparse.ArgumentParser(description='To trace boxplot.',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--prefix', '-p', help='monitor prefix name', default='result')
    parser.add_argument('--islands', '-n', help='number of islands', type=int, default=4)
    parser.add_argument('--times', '-t', help='number of times', type=int, default=10000)
    parser.add_argument('--runs', '-r', help='number of runs', type=int, default=21)
    parser.add_argument('--column', '-c', help='column to select', type=int, default=2)
    parser.add_argument('--notplot', '-np', help='disable plotting', action='store_true')
    parser.add_argument('--space', '-s', help='padding between each boxplot', type=float, default=.15)
    parser.add_argument('--colors', '-C', help='colors used in order to color each boxplot, use a comma to add more than one color', default='green,black,orange,red,blue,gray,yellow')
    args = parser.parse_args()

    V = []
    for i in range(args.islands):
        files = []

        if not args.runs:
            fn = "%s_monitor_%d" % (args.prefix, i)
            print("Pre-opening of run files…", fn)
            f = open(fn)
            files += [(fn, f)]
            f.readline() # to ignore first line
        else:
            for r in range(args.runs):
                fn = "%s_%d_monitor_%d" % (args.prefix, r+1, i)
                print("Pre-opening of run files…", fn)
                f = open(fn)
                files += [(fn, f)]
                f.readline() # to ignore first line

        T = []
        for t in range(args.times):
            R = []
            for r in range(args.runs):
                fn, f = files[r]
                nbindi = int(f.readline().split()[args.column])
                print("Reading…", fn, "with time…", t, "and nbindi", nbindi)
                R += [nbindi]

                print(R)

            T += [R]

        V += [T]

    print(V)

    if not args.notplot:
        import pylab as pl
        import numpy as np

        colors = args.colors.split(',')
        pos = np.linspace(args.islands/2*args.space, -args.islands/2*args.space, args.islands).T

        for i in range(args.islands):
            r = pl.boxplot(V[i], positions=[x-pos[i] for x in range(args.times)], widths=0.1)
            for value in r.values(): pl.setp(value, color=colors[i%len(colors)])

        pl.legend(["isl %s (%s)" % (i, colors[i]) for i in range(args.islands)])
        pl.xlabel('Time')
        pl.ylabel('Nb individuals')
        pl.xticks([x for x in range(args.times)])
        pl.xlim(-args.islands/2*args.space*2, (args.times-1)+args.islands/2*args.space*2)
        pl.show()

# when executed, just run main():
if __name__ == '__main__':
    logger.debug('### script started ###')
    main()
    logger.debug('### script ended ###')
{'fraction_non_alphanumeric': 0.15093525179856115, 'fraction_numerical': 0.01381294964028777, 'mean_word_length': 2.72508038585209, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6229875', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2194, 'n_words': 638}