From 6567959b5723ec4815739e4a6fd0f23ccbf7e614 Mon Sep 17 00:00:00 2001 From: Joshua <138818689+francojoshua@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:30:59 -0400 Subject: [PATCH 1/2] Add __get_date_count and __get_date_chart --- read_log.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/read_log.py b/read_log.py index 4ea23e7..4207291 100644 --- a/read_log.py +++ b/read_log.py @@ -2,6 +2,7 @@ from datetime import datetime import pandas as pd +from matplotlib import pyplot as plt methods = ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "TRACE", "PATCH"] pattern = r'^([\d.]+) - - \[([^]]+)\] "([^"]*)" (\d+) (\d+) "([^"]*)" "([^"]*)" "-"$' @@ -43,3 +44,27 @@ print("No match found.") df = pd.DataFrame(data) + + +def __get_date_count(df): + # Create a frequency of days and requests (e.g. datetime.date(2022, 5, 16): 12337 + return df["date"].apply(lambda dt: dt.date()).value_counts().sort_index() + + +def __get_date_chart(df): + """ + Create a chart that will showcase the amount of requests per day. + """ + frequencies = __get_date_count(df) + + # Create the bar chart + plt.bar(frequencies.index, frequencies.values) + plt.xlabel("Date") + plt.ylabel("Number of Requests") + plt.title("Number of Requests per Day") + plt.xticks(rotation=45) + + # Display the chart + plt.margins(0.05) + plt.tight_layout() + plt.show() From 208807f57382e04430723fd84ec6a02bba0fc753 Mon Sep 17 00:00:00 2001 From: Joshua <138818689+francojoshua@users.noreply.github.com> Date: Wed, 19 Jul 2023 15:54:40 -0400 Subject: [PATCH 2/2] Move functions up --- read_log.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/read_log.py b/read_log.py index 4207291..6226d3a 100644 --- a/read_log.py +++ b/read_log.py @@ -4,6 +4,31 @@ import pandas as pd from matplotlib import pyplot as plt + +def __get_date_count(df): + # Create a frequency of days and requests (e.g. datetime.date(2022, 5, 16): 12337 + return df["date"].apply(lambda dt: dt.date()).value_counts().sort_index() + + +def __get_date_chart(df): + """ + Create a chart that will showcase the amount of requests per day. + """ + frequencies = __get_date_count(df) + + # Create the bar chart + plt.bar(frequencies.index, frequencies.values) + plt.xlabel("Date") + plt.ylabel("Number of Requests") + plt.title("Number of Requests per Day") + plt.xticks(rotation=45) + + # Display the chart + plt.margins(0.05) + plt.tight_layout() + plt.show() + + methods = ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "TRACE", "PATCH"] pattern = r'^([\d.]+) - - \[([^]]+)\] "([^"]*)" (\d+) (\d+) "([^"]*)" "([^"]*)" "-"$' @@ -44,27 +69,3 @@ print("No match found.") df = pd.DataFrame(data) - - -def __get_date_count(df): - # Create a frequency of days and requests (e.g. datetime.date(2022, 5, 16): 12337 - return df["date"].apply(lambda dt: dt.date()).value_counts().sort_index() - - -def __get_date_chart(df): - """ - Create a chart that will showcase the amount of requests per day. - """ - frequencies = __get_date_count(df) - - # Create the bar chart - plt.bar(frequencies.index, frequencies.values) - plt.xlabel("Date") - plt.ylabel("Number of Requests") - plt.title("Number of Requests per Day") - plt.xticks(rotation=45) - - # Display the chart - plt.margins(0.05) - plt.tight_layout() - plt.show()