1
+ use std:: collections:: HashMap ;
2
+
1
3
use crate :: assets;
2
4
use crate :: experiments:: Experiment ;
3
5
use crate :: prelude:: * ;
@@ -6,7 +8,9 @@ use crate::report::{
6
8
ResultColor , ResultName , TestResults ,
7
9
} ;
8
10
use crate :: results:: EncodingType ;
9
- use indexmap:: IndexMap ;
11
+ use indexmap:: { IndexMap , IndexSet } ;
12
+
13
+ use super :: CrateVersionStatus ;
10
14
11
15
#[ derive( Serialize ) ]
12
16
struct NavbarItem {
@@ -23,15 +27,15 @@ enum CurrentPage {
23
27
}
24
28
25
29
#[ derive( Serialize ) ]
26
- enum ReportCratesHTML {
27
- Plain ( Vec < CrateResultHTML > ) ,
30
+ enum ReportCratesHTML < ' a > {
31
+ Plain ( Vec < CrateResultHTML < ' a > > ) ,
28
32
Tree {
29
33
count : u32 ,
30
- tree : IndexMap < String , Vec < CrateResultHTML > > ,
34
+ tree : IndexMap < String , Vec < CrateResultHTML < ' a > > > ,
31
35
} ,
32
36
RootResults {
33
37
count : u32 ,
34
- results : IndexMap < String , Vec < CrateResultHTML > > ,
38
+ results : IndexMap < String , Vec < CrateResultHTML < ' a > > > ,
35
39
} ,
36
40
}
37
41
@@ -61,13 +65,13 @@ impl CurrentPage {
61
65
struct ResultsContext < ' a > {
62
66
ex : & ' a Experiment ,
63
67
nav : Vec < NavbarItem > ,
64
- categories : Vec < ( Comparison , ReportCratesHTML ) > ,
68
+ // (comparison, category color, ...)
69
+ categories : Vec < ( Comparison , usize , ReportCratesHTML < ' a > ) > ,
65
70
info : IndexMap < Comparison , u32 > ,
66
71
full : bool ,
67
72
crates_count : usize ,
68
- comparison_colors : IndexMap < Comparison , Color > ,
69
- result_colors : Vec < Color > ,
70
- result_names : Vec < String > ,
73
+ colors : IndexSet < Color > ,
74
+ result_names : IndexSet < String > ,
71
75
}
72
76
73
77
#[ derive( Serialize ) ]
@@ -80,20 +84,52 @@ struct DownloadsContext<'a> {
80
84
}
81
85
82
86
#[ derive( Serialize ) ]
83
- struct CrateResultHTML {
84
- name : String ,
85
- url : String ,
87
+ struct CrateResultHTML < ' a > {
88
+ name : & ' a str ,
89
+ url : & ' a str ,
86
90
res : Comparison ,
87
91
#[ serde( skip_serializing_if = "Option::is_none" ) ]
88
- status : Option < String > ,
89
- runs : [ Option < BuildTestResultHTML > ; 2 ] ,
92
+ status : Option < CrateVersionStatus > ,
93
+ color_idx : usize ,
94
+ runs : [ Option < BuildTestResultHTML < ' a > > ; 2 ] ,
90
95
}
91
96
92
97
// Map TestResult to usize to avoid the presence of special characters in html
93
98
#[ derive( Serialize ) ]
94
- struct BuildTestResultHTML {
95
- res : usize ,
96
- log : String ,
99
+ struct BuildTestResultHTML < ' a > {
100
+ color_idx : usize ,
101
+ name_idx : usize ,
102
+ log : & ' a str ,
103
+ }
104
+
105
+ fn to_html_crate_result < ' a > (
106
+ colors : & mut IndexSet < Color > ,
107
+ result_names : & mut IndexSet < String > ,
108
+ category_color : usize ,
109
+ result : & ' a CrateResult ,
110
+ ) -> CrateResultHTML < ' a > {
111
+ let mut runs = [ None , None ] ;
112
+
113
+ for ( pos, run) in result. runs . iter ( ) . enumerate ( ) {
114
+ if let Some ( run) = run {
115
+ let ( color_idx, _) = colors. insert_full ( run. res . color ( ) ) ;
116
+ let ( name_idx, _) = result_names. insert_full ( run. res . short_name ( ) ) ;
117
+ runs[ pos] = Some ( BuildTestResultHTML {
118
+ color_idx,
119
+ name_idx,
120
+ log : run. log . as_str ( ) ,
121
+ } ) ;
122
+ }
123
+ }
124
+
125
+ CrateResultHTML {
126
+ name : result. name . as_str ( ) ,
127
+ url : result. url . as_str ( ) ,
128
+ status : result. status ,
129
+ res : result. res ,
130
+ color_idx : category_color,
131
+ runs,
132
+ }
97
133
}
98
134
99
135
fn write_report < W : ReportWriter > (
@@ -105,54 +141,37 @@ fn write_report<W: ReportWriter>(
105
141
dest : & W ,
106
142
output_templates : bool ,
107
143
) -> Fallible < ( ) > {
108
- let mut comparison_colors = IndexMap :: new ( ) ;
109
- let mut test_results_to_int = IndexMap :: new ( ) ;
110
- let mut result_colors = Vec :: new ( ) ;
111
- let mut result_names = Vec :: new ( ) ;
144
+ let mut colors = IndexSet :: new ( ) ;
145
+ let mut result_names = IndexSet :: new ( ) ;
112
146
113
- let mut to_html_crate_result = |result : CrateResult | {
114
- let mut runs = [ None , None ] ;
115
-
116
- for ( pos, run) in result. runs . iter ( ) . enumerate ( ) {
117
- if let Some ( ref run) = run {
118
- let idx = test_results_to_int
119
- . entry ( run. res . clone ( ) )
120
- . or_insert_with ( || {
121
- result_colors. push ( run. res . color ( ) ) ;
122
- result_names. push ( run. res . short_name ( ) ) ;
123
- result_names. len ( ) - 1
124
- } ) ;
125
- runs[ pos] = Some ( BuildTestResultHTML {
126
- res : * idx,
127
- log : run. log . clone ( ) ,
128
- } ) ;
129
- }
130
- }
131
-
132
- CrateResultHTML {
133
- name : result. name . clone ( ) ,
134
- url : result. url . clone ( ) ,
135
- status : result. status . map ( |status| status. to_string ( ) ) ,
136
- res : result. res ,
137
- runs,
138
- }
139
- } ;
147
+ let color_for_category = res
148
+ . categories
149
+ . keys ( )
150
+ . map ( |category| ( category. color ( ) , colors. insert_full ( category. color ( ) ) . 0 ) )
151
+ . collect :: < HashMap < _ , _ > > ( ) ;
140
152
141
153
let categories = res
142
154
. categories
143
155
. iter ( )
144
156
. filter ( |( category, _) | full || category. show_in_summary ( ) )
145
- . map ( |( & category, crates) | ( category, crates. to_owned ( ) ) )
157
+ . map ( |( & category, crates) | ( category, crates) )
146
158
. flat_map ( |( category, crates) | {
147
- comparison_colors. insert ( category, category. color ( ) ) ;
148
-
159
+ let category_color_idx = * color_for_category. get ( & category. color ( ) ) . unwrap ( ) ;
149
160
match crates {
150
161
ReportCrates :: Plain ( crates) => vec ! [ (
151
162
category,
163
+ category_color_idx,
152
164
ReportCratesHTML :: Plain (
153
165
crates
154
- . into_iter( )
155
- . map( |result| to_html_crate_result( result) )
166
+ . iter( )
167
+ . map( |result| {
168
+ to_html_crate_result(
169
+ & mut colors,
170
+ & mut result_names,
171
+ category_color_idx,
172
+ result,
173
+ )
174
+ } )
156
175
. collect:: <Vec <_>>( ) ,
157
176
) ,
158
177
) ]
@@ -163,8 +182,15 @@ fn write_report<W: ReportWriter>(
163
182
. map ( |( root, deps) | {
164
183
(
165
184
root. to_string ( ) ,
166
- deps. into_iter ( )
167
- . map ( |result| to_html_crate_result ( result) )
185
+ deps. iter ( )
186
+ . map ( |result| {
187
+ to_html_crate_result (
188
+ & mut colors,
189
+ & mut result_names,
190
+ category_color_idx,
191
+ result,
192
+ )
193
+ } )
168
194
. collect :: < Vec < _ > > ( ) ,
169
195
)
170
196
} )
@@ -175,8 +201,15 @@ fn write_report<W: ReportWriter>(
175
201
(
176
202
res. long_name ( ) ,
177
203
krates
178
- . into_iter ( )
179
- . map ( |result| to_html_crate_result ( result) )
204
+ . iter ( )
205
+ . map ( |result| {
206
+ to_html_crate_result (
207
+ & mut colors,
208
+ & mut result_names,
209
+ category_color_idx,
210
+ result,
211
+ )
212
+ } )
180
213
. collect :: < Vec < _ > > ( ) ,
181
214
)
182
215
} )
@@ -185,13 +218,15 @@ fn write_report<W: ReportWriter>(
185
218
vec ! [
186
219
(
187
220
category,
221
+ category_color_idx,
188
222
ReportCratesHTML :: Tree {
189
223
count: tree. keys( ) . len( ) as u32 ,
190
224
tree,
191
225
} ,
192
226
) ,
193
227
(
194
228
category,
229
+ category_color_idx,
195
230
ReportCratesHTML :: RootResults {
196
231
count: results. keys( ) . len( ) as u32 ,
197
232
results,
@@ -216,13 +251,14 @@ fn write_report<W: ReportWriter>(
216
251
info : res. info . clone ( ) ,
217
252
full,
218
253
crates_count,
219
- comparison_colors,
220
- result_colors,
254
+ colors,
221
255
result_names,
222
256
} ;
223
257
224
258
info ! ( "generating {}" , to) ;
225
- let html = minifier:: html:: minify ( & assets:: render_template ( "report/results.html" , & context) ?) ;
259
+ let rendered = assets:: render_template ( "report/results.html" , & context)
260
+ . context ( "rendering template report/results.html" ) ?;
261
+ let html = minifier:: html:: minify ( & rendered) ;
226
262
dest. write_string ( to, html. into ( ) , & mime:: TEXT_HTML ) ?;
227
263
228
264
if output_templates {
0 commit comments