1+ import matplotlib .pyplot as plt
2+ import numpy as np
3+ from math import ceil
4+ import os
5+
6+ from test import extract_last_decimal
7+
8+ for d in os .listdir ():
9+ if d .startswith ('f' ):
10+ r = {}
11+
12+ fw_size = np .array ([])
13+ patch_size = np .array ([])
14+ n_frag_patch = np .array ([])
15+ n_frag_fw = np .array ([])
16+ ovh_nbd = np .array ([])
17+ ovh_nbc = np .array ([])
18+ ovh_nba = np .array ([])
19+ ovh_tot = np .array ([])
20+ n_nba = np .array ([])
21+
22+ if os .path .exists (d + '/testout' ):
23+ for report in os .listdir (d + '/testout' ):
24+ if report .startswith ('report' ):
25+ # extract version
26+ version = extract_last_decimal (report )
27+ # add to dictionary
28+ r [version ] = report
29+
30+ # check if there are report in the folder
31+ if r :
32+ fw_versions = sorted (r .keys ())
33+ for v in fw_versions :
34+ with open (d + '/testout/' + r [v ], 'r' ) as f :
35+ f .readline ()
36+ fields = f .readline ().split (',' )
37+
38+ fw_size = np .append (fw_size , int (fields [0 ]))
39+ patch_size = np .append (patch_size , int (fields [1 ]))
40+ n_frag_patch = np .append (n_frag_patch , ceil (int (fields [1 ])/ 112 ))
41+ n_frag_fw = np .append (n_frag_fw , ceil (int (fields [0 ])/ 112 ))
42+ n_nba = np .append (n_nba , int (fields [4 ]))
43+ ovh_nbd = np .append (ovh_nbd , float (fields [5 ]))
44+ ovh_nbc = np .append (ovh_nbc , float (fields [6 ]))
45+ ovh_nba = np .append (ovh_nba , float (fields [7 ]))
46+ ovh_tot = np .append (ovh_tot , float (fields [8 ]))
47+
48+ # fig, axs = plt.subplots(2, 2, figsize=(15, 10))
49+ fig , axs = plt .subplots (2 , 2 )
50+ fig .suptitle (f'Statistics folder: { d } ' )
51+
52+ axs [0 , 0 ].set_title ('Compression' )
53+ axs [0 , 0 ].plot (fw_versions , patch_size / fw_size * 100 )
54+ axs [0 , 0 ].set_xlabel ('FW version' )
55+ axs [0 , 0 ].set_ylabel ('Patch compression [%]' )
56+ axs [0 , 0 ].grid ()
57+
58+ axs [0 , 1 ].set_title ('New Bytes' )
59+ axs [0 , 1 ].plot (fw_versions , np .ceil (n_nba / 1024 ))
60+ axs [0 , 1 ].set_xlabel ('FW version' )
61+ axs [0 , 1 ].set_ylabel ('kB' )
62+ axs [0 , 1 ].grid ()
63+
64+ axs [1 , 0 ].set_title ('Overhead' )
65+ axs [1 , 0 ].plot (fw_versions , ovh_nbd , fw_versions , ovh_nbc , fw_versions , ovh_nba , fw_versions , ovh_tot )
66+ axs [1 , 0 ].set_xlabel ('FW version' )
67+ axs [1 , 0 ].set_ylabel ('Overhead respect new bytes [%]' )
68+ axs [1 , 0 ].legend (['nbd' , 'nbc' , 'nba' , 'total' ])
69+ axs [1 , 0 ].grid ()
70+
71+ width = 0.3 # the width of the bars
72+ species = np .arange (len (fw_versions ))
73+
74+ p1 = axs [1 , 1 ].bar (species - width / 2 , n_frag_fw , width , label = 'FW' )
75+ axs [1 , 1 ].bar_label (p1 , label_type = 'edge' )
76+ p2 = axs [1 , 1 ].bar (species + width / 2 , n_frag_patch , width , label = 'Patch' )
77+ axs [1 , 1 ].bar_label (p2 , label_type = 'edge' )
78+
79+ axs [1 , 1 ].set_title ('Number of fragment comparison' )
80+ axs [1 , 1 ].set_xticks (species )
81+ axs [1 , 1 ].set_xticklabels (fw_versions )
82+ axs [1 , 1 ].legend ()
83+
84+ plt .tight_layout ()
85+ plt .show ()
86+
87+ exit ()
0 commit comments