Foundation Programming
Foundation Programming
Team ID:
Student IDs and Names:
Contribution Summary
We had certain difficulties and hurdles throughout the job that needed a quick
response. Technical difficulties, time restrictions, and comprehension of the
assignment's complicated elements were some of these difficulties. To get past
them:
Reflection
This task has taught us important lessons and given us insightful new
information:
Better Problem-Solving Skills: We became more confident in our ability to
solve challenging programming issues and successfully implement solutions.
Increased Teamwork: As we delegated jobs and communicated effectively, our
ability to work together increased.
Time management: To reach project milestones, we discovered how important
proactive time management is.
For upcoming programming projects, we advise:
Upkeep of precise Project Plans: Establishing and following precise project
plans with distinct dates.
Regular Communication: Keeping lines of communication open and
transparent to quickly resolve problems.
Continuous Learning: Encouragement of ongoing learning and skill
improvement to successfully complete challenging assignments.
2. Pseudocode
• Write one Python program that reads input from the log file and
shows which host visited the website on both days.
Pseudocode
Source code
Output
Parse each line into fields, using appropriate variables or data
structures to store them. Find the top 10 visiting URL in the log.
Pseudocode
function parse_log_file(log_file_path):
url_stats = an empty dictionary
ip_pattern = a regex pattern for IP addresses
url_pattern = a regex pattern for URLs
For each line in the log file:
Use 'ip_pattern' to search and extract IP address
Use 'url_pattern' to search and extract URL
If ip_match and url_match are successful:
ip = ip_match.group()
url = url_match.group(2)
Increment the 'visits' count for 'url' in 'url_stats'
Add 'ip' to the set of IPs associated with 'url' in 'url_stats'
Return 'url_stats'
if __name__ equals "__main__":
log_file_path
url_statistics = call 'parse_log_file' function with 'log_file_path'
Sort 'url_statistics' by visit counts in descending order
Print "Top 10 Visiting URLs:"
For each 'url' and 'stats' in the sorted URL statistics (first 10 items):
total_visits = 'stats'['visits']
unique_ips = Count the number of elements in 'stats'['ips'] set
Print "URL:", 'url', "| Total Visits:", total_visits, "| Unique IPs:",
unique_ips
Source code
Output
Counting the suspected abnormal client visiting by detecting
unsuccess visiting codes
Pseudocode
function count_abnormal_visits(log_file_path):
client_error_counts = an empty dictionary
failure_counts = an empty dictionary
ip_pattern = a regex pattern for IP addresses
code_pattern = a regex pattern for visiting codes
Open the log file at 'log_file_path' for reading
For each line in the log file:
Use 'ip_pattern' to search and extract IP address
Use 'code_pattern' to search and extract visiting code
Source code
Output
The task involves generating a summary of abnormal visits in the
log, including information such as the fail access times (404 code
indicating a failed visit), successful visiting times (200 code
indicating a successful visit), and the maximum visiting frequency
per hour, determined by checking the frequency of 404 errors.
Pseudocode
function generate_abnormal_summary(log_file_path):
ip_visits = an empty dictionary
ip_pattern = a regex pattern for IP addresses
code_pattern = a regex pattern for visiting codes
timestamp_pattern = a regex pattern for timestamps
Open the log file at 'log_file_path' for reading
For each line in the log file:
Use 'ip_pattern' to search and extract IP address
Use 'code_pattern' to search and extract visiting code
Use 'timestamp_pattern' to search and extract timestamp
If ip_match and code_match and timestamp_match are successful:
ip = ip_match.group()
code = int(code_match.group())
timestamp = timestamp_match.group()
If code equals 200:
Increment the 'Success Count' for 'ip' in 'ip_visits'
Elif code equals 404:
Increment the 'Failure Count' for 'ip' in 'ip_visits'
Append 'timestamp' to the list of 'timestamps' for 'ip' in 'ip_visits'
Increment the 'hourly_frequency' count for 'timestamp' in 'ip_visits[ip]
['hourly_frequency']'
Initialize an empty dictionary 'summary'
For each 'ip' and 'info' in 'ip_visits':
success_count = 'info['Success Count']'
failure_count = 'info['Failure Count']'
timestamps = 'info['timestamps']'
hourly_frequency = Find the maximum count in
'info['hourly_frequency']'
'summary[ip]' = {
'Success Count': success_count,
'Failure Count': failure_count,
'Fail Access Times': failure_count,
'Success Visiting Times': success_count,
'Maximum Visiting Frequency per Hour': hourly_frequency
}
Return 'summary'
if __name__ equals "__main__":
log_file_path = 'log.txt'
abnormal_summary = call 'generate_abnormal_summary' function with
'log_file_path'
For each 'ip' and 'data' in 'abnormal_summary':
Print "IP Address:", 'ip'
Print "Success Count:", 'data['Success Count']'
Print "Failure Count:", 'data['Failure Count']'
Print "Fail Access Times:", 'data['Fail Access Times']'
Print "Success Visiting Times:", 'data['Success Visiting Times']'
Print "Maximum Visiting Frequency per Hour:", 'data['Maximum Visiting
Frequency per Hour']'
Source code
Output