| 245 | |
| 246 | |
| 247 | def write_output(f, table, headers, run_count, format="table"): |
| 248 | if format == "csv": |
| 249 | # strip new lines from CSV output |
| 250 | headers = [h.replace("\n", " ") for h in headers] |
| 251 | writer = csv.writer(f) |
| 252 | writer.writerow(headers) |
| 253 | writer.writerows(table) |
| 254 | else: |
| 255 | # First column is name, and then they alternate between counts and durations |
| 256 | summary_count = len(headers) - 2 * run_count - 1 |
| 257 | floatfmt = ("",) + (".0f", ".2f") * run_count + (".2f",) * summary_count |
| 258 | f.write(tabulate.tabulate(table, headers=headers, floatfmt=floatfmt)) |
| 259 | f.write("\n") |
| 260 | |
| 261 | |
| 262 | class Row: |