|
| 1 | + |
| 2 | +# Generate the LaTeX table with validation git statistics. |
| 3 | + |
| 4 | +import subprocess |
| 5 | +from pathlib import Path |
| 6 | +import glob |
| 7 | + |
| 8 | +outdir = '../../../out/' |
| 9 | +valdir = '../../Validation/' |
| 10 | +resdir = '../../Manuals/FDS_Validation_Guide/SCRIPT_FIGURES/ScatterPlots/' |
| 11 | + |
| 12 | +def MAKEGITENTRY(case_name): |
| 13 | + |
| 14 | + # Output a single LaTeX table entry with git information for a validation set. |
| 15 | + |
| 16 | + # Collect all git.txt files and sort uniquely |
| 17 | + git_file_pattern = outdir + case_name + '/*git.txt' |
| 18 | + matching_files = set(Path().glob(git_file_pattern)) |
| 19 | + |
| 20 | + # Read first line |
| 21 | + gitrev = '' |
| 22 | + for file_path in sorted(matching_files): |
| 23 | + with open(file_path.as_posix(), 'r') as fff: |
| 24 | + gitrev = fff.readline().strip() |
| 25 | + |
| 26 | + output = '' |
| 27 | + if gitrev != '': |
| 28 | + # Extract git revision short hash |
| 29 | + parts = gitrev.split('-') |
| 30 | + if len(parts) >= 2: |
| 31 | + gitrevshort = parts[-2] |
| 32 | + gitrevshort = gitrevshort[1:] if gitrevshort.startswith('g') else gitrevshort |
| 33 | + else: |
| 34 | + gitrevshort = gitrev |
| 35 | + |
| 36 | + # Get git date |
| 37 | + gitdate = '' |
| 38 | + try: |
| 39 | + result = subprocess.run( ['git show -s --format=%aD', gitrevshort], capture_output=True, text=True) |
| 40 | + if result.returncode == 0 and result.stdout.strip(): |
| 41 | + date_parts = result.stdout.strip().split() |
| 42 | + if len(date_parts) >= 5: |
| 43 | + gitdate = f"{date_parts[2]} {date_parts[1]}, {date_parts[3]}" |
| 44 | + except Exception: |
| 45 | + gitdate = '' |
| 46 | + |
| 47 | + # Escape underscores for LaTeX |
| 48 | + dir_escaped = case_name.replace('_', '\\_') |
| 49 | + output = f"{dir_escaped} & {gitdate} & {gitrev} \\\\ \\hline\n" |
| 50 | + |
| 51 | + return output |
| 52 | + |
| 53 | + |
| 54 | +# Create a LaTeX table |
| 55 | + |
| 56 | +OUTPUT_TEX_FILE = resdir + 'validation_git_stats.tex' |
| 57 | + |
| 58 | +with open(OUTPUT_TEX_FILE, 'w') as outf: |
| 59 | + outf.write("\\begin{longtable}[c]{|l|c|c|}\n") |
| 60 | + outf.write("\\caption[Validation Git Statistics]{Validation Git statistics for all data sets}\n") |
| 61 | + outf.write("\\label{validation_git_stats}\n") |
| 62 | + outf.write("\\\\ \\hline\n") |
| 63 | + outf.write("Dataset & FDS Revision Date & FDS Revision String\\\\ \\hline \\hline\n") |
| 64 | + outf.write("\\endfirsthead\n") |
| 65 | + outf.write("\\hline\n") |
| 66 | + outf.write("Dataset & FDS Revision Date & FDS Revision String\\\\ \\hline \\hline\n") |
| 67 | + outf.write("\\endhead\n") |
| 68 | + |
| 69 | + |
| 70 | +# Extract case list from Validation/Process_All_Output.sh |
| 71 | + |
| 72 | +with open(valdir + 'Process_All_Output.sh', 'r') as inf: |
| 73 | + lines = inf.readlines() |
| 74 | + |
| 75 | +cases = [] |
| 76 | +line_num = 0 |
| 77 | +for line in lines: |
| 78 | + if 'PROCESS' in line: |
| 79 | + parts = line.strip().split() |
| 80 | + if len(parts) >= 2: |
| 81 | + line_num += 1 |
| 82 | + if line_num > 1: # Skip first match |
| 83 | + cases.append(parts[1]) |
| 84 | + |
| 85 | +# Process each case and generate table entries |
| 86 | + |
| 87 | +for case in cases: |
| 88 | + entry = MAKEGITENTRY(case) |
| 89 | + with open(OUTPUT_TEX_FILE, 'a') as outf: |
| 90 | + outf.write(entry) |
| 91 | + |
| 92 | +# Table footer |
| 93 | + |
| 94 | +with open(OUTPUT_TEX_FILE, 'a') as f: |
| 95 | + f.write("\\end{longtable}\n") |
| 96 | + |
0 commit comments