Beispiel #1
0
    def list_runs(self, search_string=None):
        """
        List all runs in the database. If a search_string is provided, only
        those runs matching the search_string in runcard or runfolder will
        apear
        """
        fields = [
            "rowid", "jobid", "runcard", "runfolder", "date", "jobtype",
            "iseed"
        ]
        dictC = self._db_list(fields, search_string)
        logger.plain("Active runs: " + str(len(dictC)))

        # Could easily be optimised
        offset = 2
        id_width = max(list(len(str(i["rowid"]))
                            for i in dictC) + [2]) + offset
        runcard_width = max(
            list(len(i["runcard"].strip()) for i in dictC) + [7]) + offset
        runname_width = max(
            list(len(i["runfolder"].strip()) for i in dictC) + [7]) + offset
        date_width = max(
            list(len(str(i['date']).split('.')[0].strip())
                 for i in dictC) + [10]) + offset
        misc_width = 7

        header = "|".join([
            "id".center(id_width), "runcard".center(runcard_width),
            "runname".center(runname_width), "date".center(date_width),
            "misc".center(misc_width)
        ])
        logger.plain(header)
        logger.plain("-" * len(header))

        for i in dictC:
            rid = str(i['rowid']).center(id_width)
            ruc = str(i['runcard']).center(runcard_width)
            run = str(i['runfolder']).center(runname_width)
            dat = str(i['date']).split('.')[0].center(date_width)
            misc = str(" " + i['jobtype'])
            jobids = str(i['jobid'])
            initial_seed = str(i['iseed'])
            no_jobs = len(jobids.split(" "))
            if no_jobs > 1:
                if initial_seed and initial_seed != "None":
                    misc += " ({0}, is: {1})".format(no_jobs, initial_seed)
                else:
                    misc += " ({0})".format(no_jobs)
            misc += self._get_computing_element(jobids)
            misc_text = misc.center(misc_width)
            logger.plain("|".join([rid, ruc, run, dat, misc_text]))
Beispiel #2
0
    def get_completion_stats(self, jobid, jobinfo, args):
        from pyHepGrid.src.gnuplot import do_plot
        job_outputs = self.cat_job(jobid, jobinfo, store=True)
        vals = []
        for job_stdout in job_outputs:
            for line in reversed(job_stdout.split("\n")):
                if "Current progress" in line and ".uk" not in line:
                    vals.append(
                        int(line.split("\r")[-1].split()[-1].strip()[:-1]))
                    break
                elif "Commencing" in line:
                    vals.append(0)
                    break
        histogram = sorted(list(
            zip(Counter(vals).keys(),
                Counter(vals).values())),
                           key=lambda x: x[0])
        format_string = "| {0:<4}"
        val_line = "{0:<13}".format("% Completion")
        count_line = "{0:<13}".format("# Jobs")
        for element in histogram:
            val_line += format_string.format(str(element[0]) + "%")
            count_line += format_string.format(element[1])
        divider = "-" * len(val_line)
        logger.plain(val_line)
        logger.plain(divider)
        logger.plain(count_line)

        if not args.gnuplot:
            return

        newvals = []
        newcounts = []
        for i in range(0, 105, 5):
            match = False
            for j in histogram:
                if i == j[0]:
                    newvals.append(j[0])
                    newcounts.append(j[1])
                    match = True
                    break
            if not match:
                newvals.append(i)
                newcounts.append(0)

        do_plot(newvals,
                newcounts,
                title="Completion % Histogram (Unnormalised)",
                xlabel="% Completion",
                ylabel="No. of jobs")
Beispiel #3
0
    def stats_print_setup(self, runcard_info, dbid=""):
        if dbid == "":
            string = ""
        else:
            string = "{0:5} ".format("[{0}]".format(dbid))

        if self.stats_one_line:
            logger.plain("{0}-{1}: ".format(dbid, runcard_info["runcard"]), end="")
            return
        if not header.short_stats:
            string += "=> {0}: {1}".format(runcard_info["runcard"],
                                           runcard_info["runfolder"])
            logger.plain(string)
        else:
            string += "{0:20}: {1:10} ".format(runcard_info["runcard"],
                                               runcard_info["runfolder"])
            logger.plain(string, end="")
Beispiel #4
0
    def print_stats(self, done, wait, run, fail, unk, total):
        total2 = done + wait + run + fail + unk
        time = datetime.datetime.now().strftime("%H:%M:%S %d-%m-%Y")

        if self.stats_one_line:
            string = "Done: [{0}/{1}];\n".format(done, total)
            print(string)
            return

        if header.short_stats:
            def addline(name, val, colour):
                if val > 0:
                    return "{0}{1}: {2:4}  \033[0m".format(colour, name, val)
                else:
                    return  "{0}: {1:4}  ".format(name, val)

            string = addline("Done", done, '\033[92m')
            string += addline("Waiting", wait, '\033[93m')
            string += addline("Running", run, '\033[94m')
            string += addline("Failed", fail, '\033[91m')
            string += "Total: {0:4}".format(total2)
            logger.plain(string)
        else:
            logger.plain(" >> Total number of subjobs: {0:<20} {1}".format(total, time))
            logger.plain("    >> Done:    {0}".format(done))
            logger.plain("    >> Waiting: {0}".format(wait))
            logger.plain("    >> Running: {0}".format(run))
            logger.plain("    >> Failed:  {0}".format(fail))
            logger.plain("    >> Unknown: {0}".format(unk))
            logger.plain("    >> Sum      {0}".format(total2))