Skip to content

Commit

Permalink
feat: simplify modelizer (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
fargito authored Apr 16, 2021
1 parent 5878845 commit e6582d1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 129 deletions.
93 changes: 5 additions & 88 deletions backend/audits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,102 +122,19 @@ def poll_audit_results(audit_uuid, json_url, previous_api_response="", repeat_in
formatted_results_array = format_wpt_json_results_for_script(
response["data"]
)

for formatted_results in formatted_results_array:
screenshot_url = formatted_results.pop("screenshot_url")

audit_results = AuditResults(
audit=audit,
wpt_results_json_url=json_url,
wpt_results_user_url=wpt_results_user_url,
wpt_metric_first_view_tti=formatted_results[
"wpt_metric_first_view_tti"
],
wpt_metric_repeat_view_tti=formatted_results[
"wpt_metric_repeat_view_tti"
],
wpt_metric_first_view_speed_index=formatted_results[
"wpt_metric_first_view_speed_index"
],
wpt_metric_repeat_view_speed_index=formatted_results[
"wpt_metric_repeat_view_speed_index"
],
wpt_metric_first_view_first_paint=formatted_results[
"wpt_metric_first_view_first_paint"
],
wpt_metric_repeat_view_first_paint=formatted_results[
"wpt_metric_repeat_view_first_paint"
],
wpt_metric_first_view_first_meaningful_paint=formatted_results[
"wpt_metric_first_view_first_meaningful_paint"
],
wpt_metric_repeat_view_first_meaningful_paint=formatted_results[
"wpt_metric_repeat_view_first_meaningful_paint"
],
wpt_metric_first_view_load_time=formatted_results[
"wpt_metric_first_view_load_time"
],
wpt_metric_repeat_view_load_time=formatted_results[
"wpt_metric_repeat_view_load_time"
],
wpt_metric_first_view_first_contentful_paint=formatted_results[
"wpt_metric_first_view_first_contentful_paint"
],
wpt_metric_repeat_view_first_contentful_paint=formatted_results[
"wpt_metric_repeat_view_first_contentful_paint"
],
wpt_metric_first_view_time_to_first_byte=formatted_results[
"wpt_metric_first_view_time_to_first_byte"
],
wpt_metric_repeat_view_time_to_first_byte=formatted_results[
"wpt_metric_repeat_view_time_to_first_byte"
],
wpt_metric_first_view_visually_complete=formatted_results[
"wpt_metric_first_view_visually_complete"
],
wpt_metric_repeat_view_visually_complete=formatted_results[
"wpt_metric_repeat_view_visually_complete"
],
wpt_metric_lighthouse_performance=formatted_results[
"wpt_metric_lighthouse_performance"
],
script_step_name=formatted_results.get("step_name"),
script_step_number=formatted_results.get("step_number"),
lh_metric_tti_displayed_value=formatted_results.get(
"lh_metric_tti_displayed_value"
),
lh_metric_tti_score=formatted_results.get("lh_metric_tti_score"),
lh_metric_first_contentful_paint_displayed_value=formatted_results.get(
"lh_metric_first_contentful_paint_displayed_value"
),
lh_metric_first_contentful_paint_score=formatted_results.get(
"lh_metric_first_contentful_paint_score"
),
lh_metric_speed_index_displayed_value=formatted_results.get(
"lh_metric_speed_index_displayed_value"
),
lh_metric_speed_index_score=formatted_results.get(
"lh_metric_speed_index_score"
),
lh_metric_first_meaningful_paint_displayed_value=formatted_results.get(
"lh_metric_first_meaningful_paint_displayed_value"
),
lh_metric_first_meaningful_paint_score=formatted_results.get(
"lh_metric_first_meaningful_paint_score"
),
lh_metric_first_cpu_idle_displayed_value=formatted_results.get(
"lh_metric_first_cpu_idle_displayed_value"
),
lh_metric_first_cpu_idle_score=formatted_results.get(
"lh_metric_first_cpu_idle_score"
),
lh_metric_max_potential_first_input_delay_displayed_value=formatted_results.get(
"lh_metric_max_potential_first_input_delay_displayed_value"
),
lh_metric_max_potential_first_input_delay_score=formatted_results.get(
"lh_metric_max_potential_first_input_delay_score"
),
**formatted_results,
)
audit_results.save()

project.screenshot_url = formatted_results["screenshot_url"]
project.screenshot_url = screenshot_url
project.save()

AuditStatusHistory.objects.create(
Expand Down
91 changes: 50 additions & 41 deletions backend/audits/wpt_utils/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@ def format_wpt_json_results_for_page(data):
lighthouse_data = data.get("lighthouse")
lighthouse_metrics = dict()
# lighthouse_data["audits"] only exists on Chrome browser
if lighthouse_data.get("audits"):
if lighthouse_data is not None and lighthouse_data.get("audits"):

lighthouse_audits = lighthouse_data.get("audits")

lighthouse_metrics = {
"lh_metric_tti_displayed_value": lighthouse_data["audits"]["interactive"][
"lh_metric_tti_displayed_value": lighthouse_audits["interactive"][
"displayValue"
],
"lh_metric_tti_score": lighthouse_data["audits"]["interactive"]["score"],
"lh_metric_first_contentful_paint_displayed_value": lighthouse_data[
"audits"
]["first-contentful-paint"]["displayValue"],
"lh_metric_first_contentful_paint_score": lighthouse_data["audits"][
"lh_metric_tti_score": lighthouse_audits["interactive"]["score"],
"lh_metric_first_contentful_paint_displayed_value": lighthouse_audits[
"first-contentful-paint"
]["score"],
"lh_metric_speed_index_displayed_value": lighthouse_data["audits"][
"speed-index"
]["displayValue"],
"lh_metric_speed_index_score": lighthouse_data["audits"]["speed-index"][
"score"
"lh_metric_first_contentful_paint_score": lighthouse_audits[
"first-contentful-paint"
]["score"],
"lh_metric_speed_index_displayed_value": lighthouse_audits["speed-index"][
"displayValue"
],
"lh_metric_first_meaningful_paint_displayed_value": lighthouse_data[
"audits"
]["first-meaningful-paint"]["displayValue"],
"lh_metric_first_meaningful_paint_score": lighthouse_data["audits"][
"lh_metric_speed_index_score": lighthouse_audits["speed-index"]["score"],
"lh_metric_first_meaningful_paint_displayed_value": lighthouse_audits[
"first-meaningful-paint"
]["displayValue"],
"lh_metric_first_meaningful_paint_score": lighthouse_audits[
"first-meaningful-paint"
]["score"],
"lh_metric_first_cpu_idle_displayed_value": lighthouse_data["audits"][
"lh_metric_first_cpu_idle_displayed_value": lighthouse_audits[
"first-cpu-idle"
]["displayValue"],
"lh_metric_first_cpu_idle_score": lighthouse_data["audits"][
"first-cpu-idle"
]["score"],
"lh_metric_max_potential_first_input_delay_displayed_value": lighthouse_data[
"audits"
][
"lh_metric_first_cpu_idle_score": lighthouse_audits["first-cpu-idle"][
"score"
],
"lh_metric_max_potential_first_input_delay_displayed_value": lighthouse_audits[
"max-potential-fid"
][
"displayValue"
],
"lh_metric_max_potential_first_input_delay_score": lighthouse_data[
"audits"
]["max-potential-fid"]["score"],
"lh_metric_max_potential_first_input_delay_score": lighthouse_audits[
"max-potential-fid"
]["score"],
}

wpt_metrics = {
"wpt_metric_first_view_tti": data["median"]["firstView"].get(
"TimeToInteractive"
Expand All @@ -57,14 +57,18 @@ def format_wpt_json_results_for_page(data):
)
or data["median"]["repeatView"].get("FirstInteractive")
or data["median"]["repeatView"].get("LastInteractive"),
"wpt_metric_first_view_speed_index": data["median"]["firstView"]["SpeedIndex"],
"wpt_metric_repeat_view_speed_index": data["median"]["repeatView"][
"wpt_metric_first_view_speed_index": data["median"]["firstView"].get(
"SpeedIndex"
],
"wpt_metric_first_view_first_paint": data["median"]["firstView"]["firstPaint"],
"wpt_metric_repeat_view_first_paint": data["median"]["repeatView"][
),
"wpt_metric_repeat_view_speed_index": data["median"]["repeatView"].get(
"SpeedIndex"
),
"wpt_metric_first_view_first_paint": data["median"]["firstView"].get(
"firstPaint"
],
),
"wpt_metric_repeat_view_first_paint": data["median"]["repeatView"].get(
"firstPaint"
),
"wpt_metric_first_view_first_meaningful_paint": data["median"]["firstView"].get(
"firstMeaningfulPaint"
),
Expand All @@ -77,24 +81,29 @@ def format_wpt_json_results_for_page(data):
"wpt_metric_repeat_view_first_contentful_paint": data["median"][
"repeatView"
].get("firstContentfulPaint"),
"wpt_metric_first_view_load_time": data["median"]["firstView"]["loadTime"],
"wpt_metric_repeat_view_load_time": data["median"]["repeatView"]["loadTime"],
"wpt_metric_first_view_time_to_first_byte": data["median"]["firstView"]["TTFB"],
"wpt_metric_first_view_load_time": data["median"]["firstView"].get("loadTime"),
"wpt_metric_repeat_view_load_time": data["median"]["repeatView"].get(
"loadTime"
),
"wpt_metric_first_view_time_to_first_byte": data["median"]["firstView"].get(
"TTFB"
),
"wpt_metric_repeat_view_time_to_first_byte": data["median"]["repeatView"][
"TTFB"
],
"wpt_metric_first_view_visually_complete": data["median"]["firstView"][
"wpt_metric_first_view_visually_complete": data["median"]["firstView"].get(
"visualComplete"
],
"wpt_metric_repeat_view_visually_complete": data["median"]["repeatView"][
),
"wpt_metric_repeat_view_visually_complete": data["median"]["repeatView"].get(
"visualComplete"
],
),
"wpt_metric_lighthouse_performance": data["median"]["firstView"].get(
"lighthouse.Performance"
),
"screenshot_url": data["median"]["firstView"]["images"]["screenShot"],
}
wpt_metrics.update(lighthouse_metrics)

return [wpt_metrics]


Expand Down Expand Up @@ -182,8 +191,8 @@ def format_wpt_json_results_for_script(data):
"lighthouse.Performance"
),
"screenshot_url": first_view_step_data["images"]["screenShot"],
"step_name": first_view_step_data["eventName"],
"step_number": first_view_step_data["step"],
"script_step_name": first_view_step_data["eventName"],
"script_step_number": first_view_step_data["step"],
}
)

Expand Down

0 comments on commit e6582d1

Please sign in to comment.