From ded0eeabeb758db282c31a29eb014ddcbd00240e Mon Sep 17 00:00:00 2001 From: zackcglee Date: Tue, 31 Dec 2024 11:00:46 +0900 Subject: [PATCH] [bin] add stat script --- bin/print_bench_stat.py | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 bin/print_bench_stat.py diff --git a/bin/print_bench_stat.py b/bin/print_bench_stat.py new file mode 100755 index 0000000..13bcb6a --- /dev/null +++ b/bin/print_bench_stat.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import os, json, csv + +FILE_PATH=os.path.dirname(os.path.abspath(__file__)) +ROOT=os.path.abspath(os.path.join(FILE_PATH, "..")) +BENCHMARK_DIR=os.path.join(ROOT, "benchmark") + +def get_benchmark_data(): + out = os.path.join(ROOT, "stat.tsv") + projects = os.listdir(BENCHMARK_DIR) + stat = dict() + for project in projects: + stat[project] = dict() + versions = os.listdir(os.path.join(BENCHMARK_DIR, project)) + for version in versions: + stat[project][version] = dict() + label_file = os.path.join(BENCHMARK_DIR, project, version, "label.json") + if not os.path.exists(label_file): + stat[project][version]['bug_trace'] = '0' + stat[project][version]['bugs'] = '0' + continue + with open(label_file, 'r') as f: + data = json.load(f) + stat[project][version]['bugs'] = len(data) + stat[project][version]['bug_trace'] = 0 + for bug in data: + if 'bug-trace' in bug.keys() and bug['bug-trace'] != []: + stat[project][version]['bug_trace'] += 1 + return stat + +def print_stat(stat): + stat = get_benchmark_data() + with open(os.path.join(ROOT, "stat.tsv"), 'w') as f: + writer = csv.writer(f, delimiter='\t') + writer.writerow(['Project', 'Version', '# Bugs', '# Bug Trace']) + f.flush() + for project in stat: + for version in stat[project]: + writer.writerow([project, version, stat[project][version]['bugs'], stat[project][version]['bug_trace']]) + f.flush() + f.close() +def main(): + stat = get_benchmark_data() + print_stat(stat) + +if __name__ == "__main__": + main() \ No newline at end of file