Skip to content

Commit 35cac32

Browse files
committed
pylint docstring
1 parent 8958b0c commit 35cac32

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

tests/performance_sitespeed_io.py

+102
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,22 @@ def cleanup_result_dict(result_dict):
369369

370370

371371
def get_result_dict(data, mode):
372+
"""
373+
Extract performance metrics from the data and calculate the results for each metric.
374+
375+
This function uses a regular expression to extract performance metrics and
376+
their values from the data.
377+
It then calculates the results for each metric using the `get_data_for_entry` function and
378+
stores them in a dictionary.
379+
380+
Parameters:
381+
data (str): The data containing the performance metrics and their values.
382+
mode (str): The mode of the device ('desktop' or 'mobile').
383+
384+
Returns:
385+
dict: A dictionary where the keys are the performance metrics and
386+
the values are dictionaries containing the results for each metric.
387+
"""
372388
result_dict = {}
373389
tmp_dict = {}
374390
regex = r"(?P<name>TTFB|DOMContentLoaded|firstPaint|FCP|LCP|Load|TBT|CLS|FirstVisualChange|SpeedIndex|VisualComplete85|LastVisualChange)\:[ ]{0,1}(?P<value>[0-9\.ms]+)" # pylint: disable=line-too-long
@@ -391,6 +407,22 @@ def get_result_dict(data, mode):
391407
return result_dict
392408

393409
def get_data_for_entry(mode, key, values):
410+
"""
411+
Calculate the performance data for a given entry.
412+
413+
This function calculates the median, range, points, and message for a given performance metric.
414+
It processes the values, which are in milliseconds or seconds,
415+
and calculates the total, biggest, median, and range.
416+
It also gets the full name of the metric and calculates the points.
417+
418+
Parameters:
419+
mode (str): The mode of the device ('desktop' or 'mobile').
420+
key (str): The performance metric key.
421+
values (list): The list of values for the performance metric.
422+
423+
Returns:
424+
dict: A dictionary containing the median, range, mode, points, message, and values.
425+
"""
394426
biggest = 0
395427
total = 0
396428
value_range = 0
@@ -448,6 +480,26 @@ def get_fullname(key):
448480
return fullname
449481

450482
def get_points(mode, key, result, median):
483+
"""
484+
Calculate the performance points based on the mode, key, result, and median.
485+
486+
This function assigns points based on different performance metrics such as:
487+
TTFB, TBT, FCP, LCP, CLS, SpeedIndex, FirstVisualChange, VisualComplete85, and Load.
488+
The points are calculated differently for each metric and
489+
can also vary based on the mode ('desktop' or 'mobile').
490+
491+
Parameters:
492+
mode (str): The mode of the device ('desktop' or 'mobile').
493+
key (str): The performance metric key.
494+
result (float): The result value for the SpeedIndex related metrics.
495+
median (float): The median value for the TTFB, TBT, FCP, LCP, and CLS metrics.
496+
497+
Returns:
498+
float: The calculated performance points.
499+
500+
Note:
501+
For more information on SpeedIndex, refer to: https://docs.webpagetest.org/metrics/speedindex/
502+
"""
451503
points = -1
452504
if 'TTFB' in key:
453505
points = get_ttfb_points(mode, median)
@@ -479,6 +531,16 @@ def get_points(mode, key, result, median):
479531
return points
480532

481533
def get_cls_points(median):
534+
"""
535+
Calculate the Cumulative Layout Shift (CLS) points based on the mode and median.
536+
537+
Parameters:
538+
mode (str): The mode of the device ('desktop' or 'mobile').
539+
median (float): The median CLS in milliseconds.
540+
541+
Returns:
542+
float: The calculated CLS points.
543+
"""
482544
points = 5.0
483545
if median <= 0.1:
484546
points = 5.0
@@ -489,6 +551,16 @@ def get_cls_points(median):
489551
return points
490552

491553
def get_fcp_points(median):
554+
"""
555+
Calculate the First Contentful Paint (FCP) points based on the mode and median.
556+
557+
Parameters:
558+
mode (str): The mode of the device ('desktop' or 'mobile').
559+
median (float): The median FCP in milliseconds.
560+
561+
Returns:
562+
float: The calculated FCP points.
563+
"""
492564
points = 5.0
493565
if median <= 1800:
494566
points = 5.0
@@ -499,6 +571,16 @@ def get_fcp_points(median):
499571
return points
500572

501573
def get_tbt_points(median):
574+
"""
575+
Calculate the Total Blocking Time (TBT) points based on the mode and median.
576+
577+
Parameters:
578+
mode (str): The mode of the device ('desktop' or 'mobile').
579+
median (float): The median TBT in milliseconds.
580+
581+
Returns:
582+
float: The calculated TBT points.
583+
"""
502584
points = 5.0
503585
if median <= 200:
504586
points = 5.0
@@ -509,6 +591,16 @@ def get_tbt_points(median):
509591
return points
510592

511593
def get_lcp_points(mode, median):
594+
"""
595+
Calculate the Largest Contentful Paint (LCP) points based on the mode and median.
596+
597+
Parameters:
598+
mode (str): The mode of the device ('desktop' or 'mobile').
599+
median (float): The median LCP in milliseconds.
600+
601+
Returns:
602+
float: The calculated LCP points.
603+
"""
512604
points = 5.0
513605
if 'desktop' in mode:
514606
if median <= 500:
@@ -527,6 +619,16 @@ def get_lcp_points(mode, median):
527619
return points
528620

529621
def get_ttfb_points(mode, median):
622+
"""
623+
Calculate the Time to First Byte (TTFB) points based on the mode and median.
624+
625+
Parameters:
626+
mode (str): The mode of the device ('desktop' or 'mobile').
627+
median (float): The median TTFB in milliseconds.
628+
629+
Returns:
630+
float: The calculated TTFB points.
631+
"""
530632
points = 5.0
531633
if 'desktop' in mode:
532634
if median <= 250:

0 commit comments

Comments
 (0)