1313
1414
1515def plot_security_report (table : Table ) -> io .BytesIO :
16+ """
17+ Generates a polar plot representing the security report based on the given data.
18+
19+ Args:
20+ table (Table): The input data table containing security metrics.
21+
22+ Returns:
23+ io.BytesIO: A buffer containing the generated plot image in PNG format.
24+ Returns an empty buffer in case of an error.
25+ """
1626 try :
1727 return _plot_security_report (table = table )
1828 except (TypeError , ValueError , OverflowError , IndexError , Exception ) as e :
@@ -21,6 +31,15 @@ def plot_security_report(table: Table) -> io.BytesIO:
2131
2232
2333def generate_identifiers (data : pd .DataFrame ) -> list [str ]:
34+ """
35+ Generates unique identifiers for the given dataset.
36+
37+ Args:
38+ data (pd.DataFrame): A pandas DataFrame containing security-related data.
39+
40+ Returns:
41+ list[str]: A list of generated identifiers. Returns a list with an empty string in case of an error.
42+ """
2443 try :
2544 _generate_identifiers (data = data )
2645 except (TypeError , ValueError , Exception ) as e :
@@ -29,6 +48,21 @@ def generate_identifiers(data: pd.DataFrame) -> list[str]:
2948
3049
3150def _plot_security_report (table : Table ) -> io .BytesIO :
51+ """
52+ Generates a polar plot-based security report visualizing the failure rates for different modules.
53+
54+ This function processes the input data, sorts it by failure rate, and generates a polar plot
55+ where each bar represents the failure rate for a specific module. The plot includes identifiers,
56+ color-coding based on token count, failure rate values on the bars, and a table listing the modules
57+ and their corresponding failure rates.
58+
59+ Args:
60+ table (Table): A table-like structure (e.g., pandas DataFrame) containing security report data
61+ with columns for failure rate, tokens, and modules.
62+
63+ Returns:
64+ io.BytesIO: A buffer containing the generated plot image in PNG format.
65+ """
3266 # Data preprocessing
3367 logger .info ("Data preprocessing started." )
3468
@@ -162,6 +196,21 @@ def _plot_security_report(table: Table) -> io.BytesIO:
162196
163197
164198def _generate_identifiers (data : pd .DataFrame ) -> list [str ]:
199+ """
200+ Generates a list of unique identifiers for each row in the given DataFrame.
201+
202+ The identifiers are based on the English alphabet, with each identifier consisting
203+ of a letter followed by a number. The letter represents the "group" of identifiers
204+ (using a letter from A to Z) and the number is a counter within that group. For example:
205+ - A1, A2, ..., A26, B1, B2, ..., Z1, Z2, ...
206+
207+ Args:
208+ data (pd.DataFrame): The input DataFrame containing data for which identifiers
209+ are to be generated.
210+
211+ Returns:
212+ list[str]: A list of unique identifiers as strings, one for each row in the DataFrame.
213+ """
165214 data_length = len (data )
166215
167216 alphabet = string .ascii_uppercase
0 commit comments