#C14884. Log Analysis Challenge

    ID: 44582 Type: Default 1000ms 256MiB

Log Analysis Challenge

Log Analysis Challenge

You are given a JSON array of log entries from a web server. Each log entry contains an IP address, a processing time, a URL and an HTTP status code. Your task is to analyze the logs and output the following statistics:

  • Total Requests: The total number of log entries.
  • Top 10 IP Addresses: A list of IP addresses with their request counts, sorted by descending frequency (and by order of first occurrence in case of ties).
  • Average Processing Time: The average of the processing times. Formally, \(\text{average_time} = \frac{\sum_{i=1}^{N} \text{processing_time}_i}{N}\) where \(N\) is the total number of requests.
  • Most Accessed URLs: A list of URLs with the number of times they were accessed, again preserving the order of first appearance in case of ties.
  • HTTP Status Summary: A summary count of each HTTP status code.

The input will be provided as a single JSON array read from standard input and the output should be a JSON object containing the computed statistics.

inputFormat

The input is given via standard input as a JSON array. Each element of the array is a JSON object with the following keys:

  • ip: a string representing the IP address.
  • processing_time: an integer representing the processing time.
  • url: a string representing the accessed URL.
  • status: an integer representing the HTTP status code.

outputFormat

The output should be printed to standard output as a JSON object with the following keys:

  • total_requests: an integer representing the total number of requests.
  • top_10_ip: a list of pairs [IP, count] showing the top 10 IP addresses by request count.
  • average_time: a number (floating-point) representing the average processing time.
  • most_accessed_urls: a list of pairs [URL, count] showing how many times each URL was accessed.
  • status_summary: an object with HTTP status codes as keys and their counts as values.
## sample
[
  {"ip": "192.168.1.1", "processing_time": 234, "url": "/index", "status": 200},
  {"ip": "192.168.1.2", "processing_time": 123, "url": "/home", "status": 200}
]
{"total_requests":2,"top_10_ip":[["192.168.1.1",1],["192.168.1.2",1]],"average_time":178.5,"most_accessed_urls":[["/index",1],["/home",1]],"status_summary":{"200":2}}