-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_response_processor.py
62 lines (57 loc) · 2.07 KB
/
api_response_processor.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
class ResponseProcessor:
def __init__(self) -> None:
self.CATEGORIES: list = [
"performance",
"accessibility",
"best-practices",
"seo",
]
self.ESSENTIAL_METRICS = [
"firstContentfulPaint",
"firstMeaningfulPaint",
"largestContentfulPaint",
"speedIndex",
"interactive",
"observedDomContentLoaded",
"observedLoad",
"totalBlockingTime",
"cumulativeLayoutShift",
]
def get_page_url(self, data: dict) -> dict:
return {"page_url": data.get("id")}
def get_diagnosis_device(self, lighthouseresult: dict) -> dict:
return {
"device": lighthouseresult.get("configSettings").get("emulatedFormFactor")
}
async def get_cetegorical_performance(self, lighthouseresult: dict) -> dict:
"""There we will get URL SCORE, PERFORMANCE, BEST_PRACTICE & SEO information"""
return {
category: lighthouseresult.get("categories", {})
.get(category, {})
.get("score", None)
for category in self.CATEGORIES
}
async def get_essential_metrics(self, lighthouseresult: dict) -> dict:
essential_metric_result = {}
for metric in self.ESSENTIAL_METRICS:
if (
len(
lighthouseresult.get("audits", {})
.get("metrics", {})
.get("details", {})
.get("items", [])
)
> 0
):
essential_metric_result[metric] = (
lighthouseresult.get("audits", {})
.get("metrics", {})
.get("details", {})
.get("items")[0]
.get(metric, None)
)
else:
essential_metric_result[metric] = None
return essential_metric_result
async def get_light_house_result(self, data: dict) -> dict:
return data.get("lighthouseResult", {})