def combine_validations(items, vkey="validate"):
    """Combine multiple batch validations into validation outputs.
    """
    csvs = set([])
    pngs = set([])
    for v in [x.get(vkey) for x in items]:
        if v and v.get("grading_summary"):
            csvs.add(v.get("grading_summary"))
        if v and v.get("grading_plots"):
            pngs |= set(v.get("grading_plots"))
    if len(csvs) == 1:
        grading_summary = csvs.pop()
    else:
        grading_summary = os.path.join(utils.safe_makedir(os.path.join(dd.get_work_dir(items[0]), vkey)),
                                       "grading-summary-combined.csv")
        with open(grading_summary, "w") as out_handle:
            for i, csv in enumerate(sorted(list(csvs))):
                with open(csv) as in_handle:
                    h = in_handle.readline()
                    if i == 0:
                        out_handle.write(h)
                    for l in in_handle:
                        out_handle.write(l)
    return {"grading_plots": sorted(list(pngs)), "grading_summary": grading_summary}
def combine_validations ( items , vkey = "validate" ) : csvs = set ( [ ] ) pngs = set ( [ ] ) for v in [ x . get ( vkey ) for x in items ] : if v and v . get ( "grading_summary" ) : csvs . add ( v . get ( "grading_summary" ) ) if v and v . get ( "grading_plots" ) : pngs |= set ( v . get ( "grading_plots" ) ) if len ( csvs ) == 1 : grading_summary = csvs . pop ( ) else : grading_summary = os . path . join ( utils . safe_makedir ( os . path . join ( dd . get_work_dir ( items [ 0 ] ) , vkey ) ) , "grading-summary-combined.csv" ) with open ( grading_summary , "w" ) as out_handle : for i , csv in enumerate ( sorted ( list ( csvs ) ) ) : with open ( csv ) as in_handle : h = in_handle . readline ( ) if i == 0 : out_handle . write ( h ) for l in in_handle : out_handle . write ( l ) return { "grading_plots" : sorted ( list ( pngs ) ) , "grading_summary" : grading_summary }
Combine multiple batch validations into validation outputs.