|
| 1 | +import csv |
| 2 | +import sys |
| 3 | +from dateutil.parser import parse as parse_date |
| 4 | +from plotman.log_parser import PlotLogParser |
| 5 | + |
| 6 | +def export(logfilenames, save_to = None): |
| 7 | + if save_to is None: |
| 8 | + __send_to_stdout(logfilenames) |
| 9 | + else: |
| 10 | + __save_to_file(logfilenames, save_to) |
| 11 | + |
| 12 | +def __save_to_file(logfilenames, filename: str): |
| 13 | + with open(filename, 'w') as file: |
| 14 | + __generate(logfilenames, file) |
| 15 | + |
| 16 | +def __send_to_stdout(logfilenames): |
| 17 | + __generate(logfilenames, sys.stdout) |
| 18 | + |
| 19 | +def __generate(logfilenames, out): |
| 20 | + writer = csv.writer(out) |
| 21 | + writer.writerow([ |
| 22 | + 'Plot ID', |
| 23 | + 'Started at', |
| 24 | + 'Date', |
| 25 | + 'Size', |
| 26 | + 'Buffer', |
| 27 | + 'Buckets', |
| 28 | + 'Threads', |
| 29 | + 'Tmp dir 1', |
| 30 | + 'Tmp dir 2', |
| 31 | + 'Phase 1 duration (raw)', |
| 32 | + 'Phase 1 duration', |
| 33 | + 'Phase 1 duration (minutes)', |
| 34 | + 'Phase 1 duration (hours)', |
| 35 | + 'Phase 2 duration (raw)', |
| 36 | + 'Phase 2 duration', |
| 37 | + 'Phase 2 duration (minutes)', |
| 38 | + 'Phase 2 duration (hours)', |
| 39 | + 'Phase 3 duration (raw)', |
| 40 | + 'Phase 3 duration', |
| 41 | + 'Phase 3 duration (minutes)', |
| 42 | + 'Phase 3 duration (hours)', |
| 43 | + 'Phase 4 duration (raw)', |
| 44 | + 'Phase 4 duration', |
| 45 | + 'Phase 4 duration (minutes)', |
| 46 | + 'Phase 4 duration (hours)', |
| 47 | + 'Total time (raw)', |
| 48 | + 'Total time', |
| 49 | + 'Total time (minutes)', |
| 50 | + 'Total time (hours)', |
| 51 | + 'Copy time (raw)', |
| 52 | + 'Copy time', |
| 53 | + 'Copy time (minutes)', |
| 54 | + 'Copy time (hours)', |
| 55 | + 'Filename' |
| 56 | + ]) |
| 57 | + |
| 58 | + parser = PlotLogParser() |
| 59 | + |
| 60 | + for filename in logfilenames: |
| 61 | + info = parser.parse(filename) |
| 62 | + |
| 63 | + if info.is_empty(): |
| 64 | + continue |
| 65 | + |
| 66 | + writer.writerow([ |
| 67 | + info.plot_id, |
| 68 | + info.started_at, |
| 69 | + parse_date(info.started_at).strftime("%b %d"), |
| 70 | + info.plot_size, |
| 71 | + info.buffer, |
| 72 | + info.buckets, |
| 73 | + info.threads, |
| 74 | + info.tmp_dir1, |
| 75 | + info.tmp_dir2, |
| 76 | + info.phase1_duration_raw, |
| 77 | + info.phase1_duration, |
| 78 | + info.phase1_duration_minutes, |
| 79 | + info.phase1_duration_hours, |
| 80 | + info.phase2_duration_raw, |
| 81 | + info.phase2_duration, |
| 82 | + info.phase2_duration_minutes, |
| 83 | + info.phase2_duration_hours, |
| 84 | + info.phase3_duration_raw, |
| 85 | + info.phase3_duration, |
| 86 | + info.phase3_duration_minutes, |
| 87 | + info.phase3_duration_hours, |
| 88 | + info.phase4_duration_raw, |
| 89 | + info.phase4_duration, |
| 90 | + info.phase4_duration_minutes, |
| 91 | + info.phase4_duration_hours, |
| 92 | + info.total_time_raw, |
| 93 | + info.total_time, |
| 94 | + info.total_time_minutes, |
| 95 | + info.total_time_hours, |
| 96 | + info.copy_time_raw, |
| 97 | + info.copy_time, |
| 98 | + info.copy_time_minutes, |
| 99 | + info.copy_time_hours, |
| 100 | + info.filename |
| 101 | + ]) |
0 commit comments