Daily usage of the machines
Daily usage of the machines
I want to write a script that generates a report of which users are logged in to which machines at that time. I have to input a list of event objects and evaluate these objects attributes to output a report of all the users currently logged into a machine.
When I process an event, I'll see that someone interacted with a machine. If it's a login, I want to add it to the group of users logged into that machine. If it's a logout, I want to remove it from the group of users logged into the machine.
Once we're done processing the events, I'll want to print a report of the information I generated. This is a completely separate task. So it should be a separate function. This function will receive the dictionary regenerated and print the report. It's important to have separate functions; to process the data and to print the data to the screen.
To check that my code is doing everything it's supposed to do, I need an event class. For this scenario, I'll use the very simple event class. I have an event class that has a Constructor and sets the necessary attributes. Using this Constructor, I'll create some events and add them to a list.
I've got a bunch of events. They're currently unsorted, they affect a few machines and include some users. I'll feed these events into our function and see what happens.
I'll feed these events into our function and see what happens:
Output (it works):
Let's now try generating the report:
Output:
It works!