def main(input_file, sample_size=50, iters=50, verbose=0, default_out=None, default_port=None):
    """ (-> Path-String (Dictof String Any) Void)
        Collect summary information from the input args by dispatching to the
        appropriate helper function.
        Pretty-print and save results.
    """
    print("Processing '%s'" % input_file)
    summary = None
    tag = util.strip_suffix(input_file).rsplit("/", 1)[-1]
    out_dir = default_out or "%s-%s" % (constants.OUTPUT_DIR, tag)
    #init(out_dir)
    if input_file.endswith(".rktd") or input_file.endswith(".tab"):
        # summary = TabfileSummary(input_file)
        summary = LmnSummary(input_file, out_dir=out_dir)
    elif os.path.isdir(input_file):
        # Sampling mode!
        summary = SrsSummary(input_file, sample_size=sample_size, num_iters=iters)
    else:
        print("Cannot read input file '%s'" % input_file)
        return
    print("Rendering output for '%s'" % summary.project_name)
    out_file = "%s/%s.tex" % (out_dir, tag)
    out_port = default_port or open(out_file, "w")
    summary.render(out_port)
    if default_port is None:
        out_port.close()
    # print("Results saved as '%s'" % out_file)
    return summary
def main(tabfile, dgraph):
    """ (-> Path-String GraphDict Result)
        Input: a .tab file, an overall summary of running all configurations
               of a project.
        Output: a Result object.
    """
    print("Collecting results from ground truth data '%s'" % tabfile)
    fname = util.strip_suffix(tabfile).rsplit("/", 1)[-1]
    num_modules = count_modules(tabfile)
    num_configs = 2 ** num_modules
    print("Project contains %s modules (%s configurations)" % (num_modules, num_configs))
    u_raw = all_cells_matching(tabfile, config.is_untyped)
    g_raw = all_cells_matching(tabfile, lambda x: not (config.is_typed(x) or config.is_untyped(x)))
    t_raw = all_cells_matching(tabfile, config.is_typed)
    ugt_violin = plot.violin([u_raw, g_raw, t_raw]
                            ,"%s_untyped-vs-gradual-vs-typed" % fname
                            ,"Configuration"
                            ,"Runtime (ms)"
                            ,xlabels=["untyped","gradual\n(all configs)","typed"]) if u_raw and g_raw and t_raw else None
    # Collect absolute BEST and WORST times+configs
    ten_percent = max(3, min(10, int(0.10 * num_configs)))
    best_cfg_and_times  = best_rows(tabfile
                        ,ten_percent
                        ,lambda acc,tmp: tmp[1] < acc[1]
                        ,lambda row:(row[0], int(statistics.mean([int(x) for x in row[1::]]))))
    worst_cfg_and_times = best_rows(tabfile
                        ,ten_percent
                        ,lambda acc,tmp: acc[1] < tmp[1]
                        ,lambda row:(row[0], int(statistics.mean([int(x) for x in row[1::]]))))
    stats = {
        "title"    : fname
        ,"runs"    : count_runs(tabfile)
        ,"graph"   : dgraph
        ,"ugt"     : {"img" : ugt_violin
                     ,"summary" : {"untyped" : basic_row_stats(u_raw)
                                  ,"gradual" : basic_row_stats(g_raw)
                                  ,"typed"   : basic_row_stats(t_raw)}}
        ,"best"    : [config.basic_stats(v[0], v[1], dgraph)
                      for v in best_cfg_and_times if v is not None]
        ,"worst"   : [config.basic_stats(v[0], v[1], dgraph)
                      for v in worst_cfg_and_times if v is not None]
        ,"bucketed": plot.violin(bucketize(tabfile, config.num_typed_modules, num_modules)
                           ,"%s_by-typed-modules" % fname
                           ,"Number of Typed Modules"
                           ,"Runtime (ms)"
                           ,positions=range(0, 1+num_modules)
                           ,xlabels=range(0, 1+num_modules))
        ,"fixed"   : [plot.double_violin([bucketize(tabfile, config.num_typed_modules, num_modules, pred=lambda cfg: config.untyped_at(cfg, v[0]))
                                    ,bucketize(tabfile, config.num_typed_modules, num_modules, pred=lambda cfg: config.typed_at(cfg, v[0]))]
                                    ,"%s_fixing-%s" % (fname, k)
                                    ,"Number of Typed Modules"
                                    ,"Runtime (ms)"
                                    ,legend=["%s is untyped" % k
                                            ,"%s is typed" % k])
                      for (k,v) in sorted(dgraph.items(), key=lambda item:item[1][0])]
    }
    return stats
 def infer_graph(self, fname):
     """
         Try to find the .graph file associated with `fname`
     """
     prefix = util.strip_suffix(fname)
     gfile1 = "%s.graph" % prefix
     gfile2 = "%s.graph" % prefix.split("-", 1)[0]
     tag = prefix.rsplit("/", 1)[-1]
     gfile3 = "%s.graph" % tag
     gfile4 = "%s/%s.graph" % (tag, tag)
     if os.path.exists(gfile1):
         return gfile1
     elif os.path.exists(gfile2):
         return gfile2
     elif os.path.exists(gfile3):
         return gfile3
     elif os.path.exists(gfile4):
         return gfile4
     else: ## Last resort, try searching for the first result
         return shell.find_file(gfile3)