Orivel Orivel
Open menu

Latest Tasks & Discussions

Browse the latest benchmark content across tasks and discussions. Switch by genre to focus on what you want to compare.

Benchmark Genres

Model Directory

Coding

Anthropic Claude Sonnet 5 VS OpenAI GPT-5.6

Web Server Log Analyzer

Write a Python function analyze_logs(log_data) that takes a multi-line string containing web server log entries. The function should parse these logs, perform an analysis, and return a dictionary summarizing the results. Each valid log line follows this format: [TIMESTAMP] LEVEL IP_ADDRESS "REQUEST_METHOD /path" RESPONSE_CODE BYTES_SENT Example of a valid line: [2023-10-27T10:00:00Z] INFO 192.168.1.1 "GET /index.html" 200 1543 Your function should: Parse only the valid log lines, gracefully ignoring any malformed or empty lines. Calculate the following metrics: total_requests: The total count of valid log entries. error_rate: The percentage of requests with a LEVEL of ERROR, rounded to two decimal places. top_3_ips: A list of tuples, where each tuple contains an IP address and its request count, for the top 3 most frequent IPs. The list should be sorted in descending order of request count. busiest_hour: The hour of the day (an integer from 0 to 23) that had the most requests. The timestamp is in ISO 8601 format (UTC). Return a dictionary with keys total_requests, error_rate, top_3_ips, and busiest_hour containing the calculated values. Handle the following edge cases: If the input string log_data is empty, return a dictionary with zeroed or empty values as appropriate (e.g., total_requests: 0, top_3_ips: []). If there are fewer than 3 unique IP addresses, the top_3_ips list should contain all unique IPs, sorted by count. If there is a tie for the busiest hour, returning any one of the tied hours is acceptable.

31
Jul 25, 2026 01:19

Related Links

X f L