From e534fefb5801d8358430961967e32d0435c14166 Mon Sep 17 00:00:00 2001 From: Joshua <138818689+francojoshua@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:02:25 -0400 Subject: [PATCH 1/2] Add __get_failure_rate --- read_log.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/read_log.py b/read_log.py index 4ea23e7..849f1f8 100644 --- a/read_log.py +++ b/read_log.py @@ -43,3 +43,21 @@ print("No match found.") df = pd.DataFrame(data) + + +def __get_failure_rate(df): + """ + Retrieve the failure rate of an access file. + Failure rate is defined as (number of 200 status code & is a bot) / (number of bot requests) + """ + + # Is the request from a bot? + is_bot = df["is_bot"] + + # Is the request a success and from a bot? + is_success_and_bot = (df["status_code"] == "200") & is_bot + + return len(df[is_success_and_bot]) / len(df[is_bot]) + + +print(__get_failure_rate(df)) From f75a512719af22a660bc9d67077832c8d11d841a Mon Sep 17 00:00:00 2001 From: Joshua <138818689+francojoshua@users.noreply.github.com> Date: Wed, 19 Jul 2023 15:55:12 -0400 Subject: [PATCH 2/2] Move function up and remove print statement --- read_log.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/read_log.py b/read_log.py index 849f1f8..5e2f2ad 100644 --- a/read_log.py +++ b/read_log.py @@ -3,6 +3,22 @@ import pandas as pd + +def __get_failure_rate(df): + """ + Retrieve the failure rate of an access file. + Failure rate is defined as (number of 200 status code & is a bot) / (number of bot requests) + """ + + # Is the request from a bot? + is_bot = df["is_bot"] + + # Is the request a success and from a bot? + is_success_and_bot = (df["status_code"] == "200") & is_bot + + return len(df[is_success_and_bot]) / len(df[is_bot]) + + methods = ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "TRACE", "PATCH"] pattern = r'^([\d.]+) - - \[([^]]+)\] "([^"]*)" (\d+) (\d+) "([^"]*)" "([^"]*)" "-"$' @@ -43,21 +59,3 @@ print("No match found.") df = pd.DataFrame(data) - - -def __get_failure_rate(df): - """ - Retrieve the failure rate of an access file. - Failure rate is defined as (number of 200 status code & is a bot) / (number of bot requests) - """ - - # Is the request from a bot? - is_bot = df["is_bot"] - - # Is the request a success and from a bot? - is_success_and_bot = (df["status_code"] == "200") & is_bot - - return len(df[is_success_and_bot]) / len(df[is_bot]) - - -print(__get_failure_rate(df))