#C14817. Log File Summary Report
Log File Summary Report
Log File Summary Report
You are given a log file in JSON format in which each record is an event having three attributes: timestamp
, event_type
, and user_id
. Your task is to generate a summary report of the log file. The report should be a JSON object containing the following keys:
- total_events: the total number of events.
- unique_users: the number of unique users (i.e. the size of the set \(\{user_id\}\)).
- event_counts: a JSON object where each key is an event type and its value is the count of its occurrence.
Note: The input will be provided via standard input and the output should be printed to standard output in JSON format.
inputFormat
The input is given via standard input and consists of a single line containing a JSON array of event objects. Each event object has the following attributes:
timestamp
: a string representing the date and time in ISO 8601 format.event_type
: a string representing the type of the event (e.g., LOGIN, LOGOUT, ERROR, etc.).user_id
: a string representing the user identifier.
Example input:
[{"timestamp": "2023-10-17T16:20:00Z", "event_type": "LOGIN", "user_id": "user1"}, {"timestamp": "2023-10-17T16:25:00Z", "event_type": "LOGOUT", "user_id": "user1"}]
outputFormat
Output a JSON object to standard output summarizing the log file. The JSON object must have the following structure:
total_events
: an integer representing the total number of events.unique_users
: an integer representing the number of unique users.event_counts
: a JSON object where each key is an event type and its value is the count of that event.
For example:
{ "total_events": 5, "unique_users": 3, "event_counts": {"LOGIN": 3, "LOGOUT": 1, "ERROR": 1} }## sample
[{"timestamp": "2023-10-17T16:20:00Z", "event_type": "LOGIN", "user_id": "user1"}, {"timestamp": "2023-10-17T16:25:00Z", "event_type": "LOGOUT", "user_id": "user1"}, {"timestamp": "2023-10-17T16:30:00Z", "event_type": "LOGIN", "user_id": "user2"}, {"timestamp": "2023-10-17T16:35:00Z", "event_type": "ERROR", "user_id": "user2"}, {"timestamp": "2023-10-17T16:40:00Z", "event_type": "LOGIN", "user_id": "user3"}]
{"total_events": 5, "unique_users": 3, "event_counts": {"LOGIN": 3, "LOGOUT": 1, "ERROR": 1}}