-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_rank_from_csv.py
114 lines (98 loc) · 4.32 KB
/
generate_rank_from_csv.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import pandas as pd
def generate_leaderboard_html(private_csv_path,mimic_csv_path, iu_xray_csv_path, chexpert_plus_csv_path, output_path):
# Read the three CSV files
df_mimic = pd.read_csv(mimic_csv_path)
df_iu_xray = pd.read_csv(iu_xray_csv_path)
df_chexpert_plus = pd.read_csv(chexpert_plus_csv_path)
df_private = pd.read_csv(private_csv_path)
# Sort each dataframe by 'RadCliQ-v1' score in ascending order
df_private = df_private.sort_values(by='1/RadCliQ-v1', ascending=False).reset_index(drop=True)
df_mimic = df_mimic.sort_values(by='1/RadCliQ-v1', ascending=False).reset_index(drop=True)
df_iu_xray = df_iu_xray.sort_values(by='1/RadCliQ-v1', ascending=False).reset_index(drop=True)
df_chexpert_plus = df_chexpert_plus.sort_values(by='1/RadCliQ-v1', ascending=False).reset_index(drop=True)
# HTML header
html_string = '''
<div class="col-md-7">
<div class="infoCard">
<div class="infoBody">
<div class="infoHeadline">
<h2>Leaderboard Overview</h2>
</div>
<p>Include top models for different datasets. * denotes model trained on this dataset.</p>
<div class="fixed-height-table">
<table class="table performanceTable">
<thead>
<tr>
<th>Rank</th>
<th>ReXGradient</th>
<th>MIMIC-CXR</th>
<th>IU-Xray</th>
<th>CheXpert Plus</th>
</tr>
</thead>
<tbody>
'''
# Get the maximum rank length
max_rank = max(len(df_private), len(df_mimic), len(df_iu_xray), len(df_chexpert_plus))
# Generate table content
for i in range(max_rank):
html_string += '<tr>'
html_string += f'<td><p>{i+1}</p></td>'
if i < len(df_private):
row_private = df_private.iloc[i]
html_string += f'''
<td style="word-break:break-word;">
<a class="link" href
"{row_private['Model URL']}">{row_private['Model Name']}</a>
<p class="institution">{row_private['Institution']}</p>
</td>
'''
else:
html_string += '<td style="word-break:break-word;"></td>'
if i < len(df_mimic):
row_mimic = df_mimic.iloc[i]
html_string += f'''
<td style="word-break:break-word;">
<a class="link" href="{row_mimic['Model URL']}">{row_mimic['Model Name']}</a>
<p class="institution">{row_mimic['Institution']}</p>
</td>
'''
else:
html_string += '<td style="word-break:break-word;"></td>'
if i < len(df_iu_xray):
row_iu_xray = df_iu_xray.iloc[i]
html_string += f'''
<td style="word-break:break-word;">
<a class="link" href="{row_iu_xray['Model URL']}">{row_iu_xray['Model Name']}</a>
<p class="institution">{row_iu_xray['Institution']}</p>
</td>
'''
else:
html_string += '<td style="word-break:break-word;"></td>'
if i < len(df_chexpert_plus):
row_chexpert_plus = df_chexpert_plus.iloc[i]
html_string += f'''
<td style="word-break:break-word;">
<a class="link" href="{row_chexpert_plus['Model URL']}">{row_chexpert_plus['Model Name']}</a>
<p class="institution">{row_chexpert_plus['Institution']}</p>
</td>
'''
else:
html_string += '<td style="word-break:break-word;"></td>'
html_string += '</tr>'
# HTML footer
html_string += '''
</tbody>
</table>
</div>
</div>
</div>
</div>
'''
# Write the HTML content to the output file
with open(output_path, 'w') as file:
file.write(html_string)
# Call the function to generate the HTML file
generate_leaderboard_html('./results/findings_result_gradienthealth.csv','./results/findings_result_mimiccxr.csv', './results/findings_result_iu_xray.csv', './results/findings_result_chexpertplus.csv', './results/table_rank.html')
# # 调用函数生成HTML文件
# generate_leaderboard_html('./results/result_mimiccxr.csv', './results/result_mimiccxr.csv', './results/table_rank.html')