@@ -5,47 +5,47 @@ def format_wpt_json_results_for_page(data):
5
5
lighthouse_data = data .get ("lighthouse" )
6
6
lighthouse_metrics = dict ()
7
7
# lighthouse_data["audits"] only exists on Chrome browser
8
- if lighthouse_data .get ("audits" ):
8
+ if lighthouse_data is not None and lighthouse_data .get ("audits" ):
9
+
10
+ lighthouse_audits = lighthouse_data .get ("audits" )
11
+
9
12
lighthouse_metrics = {
10
- "lh_metric_tti_displayed_value" : lighthouse_data [ "audits" ] ["interactive" ][
13
+ "lh_metric_tti_displayed_value" : lighthouse_audits ["interactive" ][
11
14
"displayValue"
12
15
],
13
- "lh_metric_tti_score" : lighthouse_data ["audits" ]["interactive" ]["score" ],
14
- "lh_metric_first_contentful_paint_displayed_value" : lighthouse_data [
15
- "audits"
16
- ]["first-contentful-paint" ]["displayValue" ],
17
- "lh_metric_first_contentful_paint_score" : lighthouse_data ["audits" ][
16
+ "lh_metric_tti_score" : lighthouse_audits ["interactive" ]["score" ],
17
+ "lh_metric_first_contentful_paint_displayed_value" : lighthouse_audits [
18
18
"first-contentful-paint"
19
- ]["score" ],
20
- "lh_metric_speed_index_displayed_value" : lighthouse_data ["audits" ][
21
- "speed-index"
22
19
]["displayValue" ],
23
- "lh_metric_speed_index_score" : lighthouse_data ["audits" ]["speed-index" ][
24
- "score"
20
+ "lh_metric_first_contentful_paint_score" : lighthouse_audits [
21
+ "first-contentful-paint"
22
+ ]["score" ],
23
+ "lh_metric_speed_index_displayed_value" : lighthouse_audits ["speed-index" ][
24
+ "displayValue"
25
25
],
26
- "lh_metric_first_meaningful_paint_displayed_value" : lighthouse_data [
27
- "audits"
28
- ]["first-meaningful-paint" ]["displayValue" ],
29
- "lh_metric_first_meaningful_paint_score" : lighthouse_data ["audits" ][
26
+ "lh_metric_speed_index_score" : lighthouse_audits ["speed-index" ]["score" ],
27
+ "lh_metric_first_meaningful_paint_displayed_value" : lighthouse_audits [
28
+ "first-meaningful-paint"
29
+ ]["displayValue" ],
30
+ "lh_metric_first_meaningful_paint_score" : lighthouse_audits [
30
31
"first-meaningful-paint"
31
32
]["score" ],
32
- "lh_metric_first_cpu_idle_displayed_value" : lighthouse_data [ "audits" ] [
33
+ "lh_metric_first_cpu_idle_displayed_value" : lighthouse_audits [
33
34
"first-cpu-idle"
34
35
]["displayValue" ],
35
- "lh_metric_first_cpu_idle_score" : lighthouse_data ["audits" ][
36
- "first-cpu-idle"
37
- ]["score" ],
38
- "lh_metric_max_potential_first_input_delay_displayed_value" : lighthouse_data [
39
- "audits"
40
- ][
36
+ "lh_metric_first_cpu_idle_score" : lighthouse_audits ["first-cpu-idle" ][
37
+ "score"
38
+ ],
39
+ "lh_metric_max_potential_first_input_delay_displayed_value" : lighthouse_audits [
41
40
"max-potential-fid"
42
41
][
43
42
"displayValue"
44
43
],
45
- "lh_metric_max_potential_first_input_delay_score" : lighthouse_data [
46
- "audits "
47
- ]["max-potential-fid" ][ " score" ],
44
+ "lh_metric_max_potential_first_input_delay_score" : lighthouse_audits [
45
+ "max-potential-fid "
46
+ ]["score" ],
48
47
}
48
+
49
49
wpt_metrics = {
50
50
"wpt_metric_first_view_tti" : data ["median" ]["firstView" ].get (
51
51
"TimeToInteractive"
@@ -57,14 +57,18 @@ def format_wpt_json_results_for_page(data):
57
57
)
58
58
or data ["median" ]["repeatView" ].get ("FirstInteractive" )
59
59
or data ["median" ]["repeatView" ].get ("LastInteractive" ),
60
- "wpt_metric_first_view_speed_index" : data ["median" ]["firstView" ]["SpeedIndex" ],
61
- "wpt_metric_repeat_view_speed_index" : data ["median" ]["repeatView" ][
60
+ "wpt_metric_first_view_speed_index" : data ["median" ]["firstView" ].get (
62
61
"SpeedIndex"
63
- ],
64
- "wpt_metric_first_view_first_paint" : data ["median" ]["firstView" ]["firstPaint" ],
65
- "wpt_metric_repeat_view_first_paint" : data ["median" ]["repeatView" ][
62
+ ),
63
+ "wpt_metric_repeat_view_speed_index" : data ["median" ]["repeatView" ].get (
64
+ "SpeedIndex"
65
+ ),
66
+ "wpt_metric_first_view_first_paint" : data ["median" ]["firstView" ].get (
66
67
"firstPaint"
67
- ],
68
+ ),
69
+ "wpt_metric_repeat_view_first_paint" : data ["median" ]["repeatView" ].get (
70
+ "firstPaint"
71
+ ),
68
72
"wpt_metric_first_view_first_meaningful_paint" : data ["median" ]["firstView" ].get (
69
73
"firstMeaningfulPaint"
70
74
),
@@ -77,24 +81,29 @@ def format_wpt_json_results_for_page(data):
77
81
"wpt_metric_repeat_view_first_contentful_paint" : data ["median" ][
78
82
"repeatView"
79
83
].get ("firstContentfulPaint" ),
80
- "wpt_metric_first_view_load_time" : data ["median" ]["firstView" ]["loadTime" ],
81
- "wpt_metric_repeat_view_load_time" : data ["median" ]["repeatView" ]["loadTime" ],
82
- "wpt_metric_first_view_time_to_first_byte" : data ["median" ]["firstView" ]["TTFB" ],
84
+ "wpt_metric_first_view_load_time" : data ["median" ]["firstView" ].get ("loadTime" ),
85
+ "wpt_metric_repeat_view_load_time" : data ["median" ]["repeatView" ].get (
86
+ "loadTime"
87
+ ),
88
+ "wpt_metric_first_view_time_to_first_byte" : data ["median" ]["firstView" ].get (
89
+ "TTFB"
90
+ ),
83
91
"wpt_metric_repeat_view_time_to_first_byte" : data ["median" ]["repeatView" ][
84
92
"TTFB"
85
93
],
86
- "wpt_metric_first_view_visually_complete" : data ["median" ]["firstView" ][
94
+ "wpt_metric_first_view_visually_complete" : data ["median" ]["firstView" ]. get (
87
95
"visualComplete"
88
- ] ,
89
- "wpt_metric_repeat_view_visually_complete" : data ["median" ]["repeatView" ][
96
+ ) ,
97
+ "wpt_metric_repeat_view_visually_complete" : data ["median" ]["repeatView" ]. get (
90
98
"visualComplete"
91
- ] ,
99
+ ) ,
92
100
"wpt_metric_lighthouse_performance" : data ["median" ]["firstView" ].get (
93
101
"lighthouse.Performance"
94
102
),
95
103
"screenshot_url" : data ["median" ]["firstView" ]["images" ]["screenShot" ],
96
104
}
97
105
wpt_metrics .update (lighthouse_metrics )
106
+
98
107
return [wpt_metrics ]
99
108
100
109
@@ -182,8 +191,8 @@ def format_wpt_json_results_for_script(data):
182
191
"lighthouse.Performance"
183
192
),
184
193
"screenshot_url" : first_view_step_data ["images" ]["screenShot" ],
185
- "step_name " : first_view_step_data ["eventName" ],
186
- "step_number " : first_view_step_data ["step" ],
194
+ "script_step_name " : first_view_step_data ["eventName" ],
195
+ "script_step_number " : first_view_step_data ["step" ],
187
196
}
188
197
)
189
198
0 commit comments