-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_analysis.py
38 lines (27 loc) · 1.31 KB
/
data_analysis.py
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
# File written by Mansour Sims
from output import append_to_txt_file, write_to_txt_file
def data_analysis(read_item_list):
hit_ratio = 0
replacement_count = 0
address_map = {}
temp_list = []
write_to_txt_file("./output/hit_replace.txt", ["Data Analysis", "------------------------","","Hit Ratio:"])
for i in read_item_list:
address = i.getAddr()
temp_list.append(address)
if address in address_map:
address_map[address] += 1
else:
address_map[address] = 1
if i.getIsHit() == True:
hit_ratio += 1
if i.getReplaceLoc() != None:
replacement_count += 1
hit_ratio = hit_ratio/len(read_item_list)
append_to_txt_file("./output/hit_replace.txt", [str(hit_ratio)])
append_to_txt_file("./output/hit_replace.txt", ["", "Replacement Count:", str(replacement_count)])
write_to_txt_file("./output/spatial_locality.txt", ["Spactial Locality:", "------------------------", ""])
result_list = [f"{key}: {value}" for key, value in address_map.items()]
append_to_txt_file("./output/spatial_locality.txt", result_list)
write_to_txt_file("./output/temporal_locality.txt", ["Temporal Locality:", "------------------------", ""])
append_to_txt_file("./output/temporal_locality.txt", temp_list)