Skip to content

ledagale27/Final_Project_Coursera

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Project - Coursera Crash Course on Python (Google)

This project pretends to recreate a real world problem which would need to be solve with a script. The purpose is to create a daily report that tracks the use of machines in a company, specifically find out which users are connected to certain machines at a given time.

Problem statement: It's needed to process a list of Event objects using their attributes to generate a report that lists all users currently logged in to the machines.

Existing information: The current system collects the events that happen on the network, among them it collects the records of each time a user logs in or out of a computer.

The input information is: -Date -Machine -User -Type str (login and logout)

The output expeceted: -Machine -Users logged in

Solution explanation

  1. First a helper function called "get_event_date" was created in order to sort the list by the attribute date. This functions takes as an input the "event" argument.

  2. The processing function was created "current_users" which takes as an input "events". Inside this function the list was sorted using the function created in the step 1 as the key. An empty dictionary "machines" was created to store the list of the machines. A for loop was used to iterate through the list of events. Inside this loop the first step was to check if the machine affected by certain event is already on the dictionary, if not it is added with an empty set as the value. Next, for the logins event the user is added to the list (.add() method) and for the logouts the user is removed from the list (.remove() method).

  3. To print a function called "generate_report" was created, it takes as an input the dictionary "machines" from the last step. Inside this function a for loop is created to iterate through all the keys ("machines") and values ("users") with the method .items(). To ensure the function does not print the machines where there is nobody logged in, a conditional function is created to check the lenght of the users is major than 0. If this is true the function need to add it to the "user_list". Finally, the function prints the name of the machine and the user logged in the expected presentation using the method .format().

  4. To check if the code is accurate, an event class is needed to test. A class named "Event" was created which contains a constructor with the necessary attribute "self", "event_date", "event_type", "machine_name", "user".

  5. A list of events was created using the class from the step above, to test the code.

  6. The events were feed into the "current_users" function and following to the function "generate_report" to get the result and the wanted format.

*This exercise was a part of the last Module of the Coursera Crash Couser on Python by Google.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages