-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_psnrs.py
More file actions
38 lines (36 loc) · 1.36 KB
/
parse_psnrs.py
File metadata and controls
38 lines (36 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import argparse
import re
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-i')
args = parser.parse_args()
file = args.i
regexpsnr = re.compile(r"[\d]+--> .* (\d[\d]?.\d\d)dB ")
regexpsnry = re.compile(r"[\d]+--> .* (\d[\d]?.\d\d)dBy ")
sums_psnr = {}
sums_psnry = {}
counts = {}
with open(file, 'r') as handle:
for line in handle:
if '-->' in line:
if '_easy_' in line:
key = 'easy'
elif '_medium_' in line:
key = 'medium'
elif '_hard_' in line:
key = 'hard'
else:
print('Could not parse line')
print(line)
print('Continuing')
psnr = regexpsnr.search(line)
if psnr is None:
print(line)
sums_psnr[key] = sums_psnr.get(key, 0) + float(psnr.group(1))
psnry = regexpsnry.search(line).group(1)
sums_psnry[key] = sums_psnry.get(key, 0) + float(psnry)
counts[key] = counts.get(key, 0) + 1
for key in ['easy', 'medium', 'hard']:
print(key, 'psnr:', str(round(sums_psnr[key] / counts[key],2)) + 'dB', 'psnr y:', str(round(sums_psnry[key] / counts[key],2)) + 'dBy')
if __name__ == '__main__':
main()