From a1573421c3756a17a013396d69123cf600170779 Mon Sep 17 00:00:00 2001 From: Churamani Paudel Date: Sat, 23 Aug 2025 17:18:39 -0600 Subject: [PATCH] Update employee.py --- python-package/employee_events/employee.py | 67 +++++++++++----------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/python-package/employee_events/employee.py b/python-package/employee_events/employee.py index 71b45a15..b3f13ec0 100644 --- a/python-package/employee_events/employee.py +++ b/python-package/employee_events/employee.py @@ -1,65 +1,62 @@ # Import the QueryBase class -#### YOUR CODE HERE +from query_base import QueryBase # Import dependencies needed for sql execution # from the `sql_execution` module -#### YOUR CODE HERE +from sql_execution import execute, execute_df -# Define a subclass of QueryBase -# called Employee -#### YOUR CODE HERE - - # Set the class attribute `name` - # to the string "employee" - #### YOUR CODE HERE +# Define a subclass of QueryBase called Employee +class Employee(QueryBase): + # Set the class attribute `name` to the string "employee" + name = "employee" # Define a method called `names` # that receives no arguments # This method should return a list of tuples # from an sql execution - #### YOUR CODE HERE - + def names(self): # Query 3 - # Write an SQL query - # that selects two columns + # Write an SQL query that selects two columns # 1. The employee's full name # 2. The employee's id - # This query should return the data - # for all employees in the database - #### YOUR CODE HERE - + # This query should return the data for all employees in the database + sql = f""" + SELECT + first_name || ' ' || last_name AS full_name, + {self.name}_id + FROM {self.name} + """ + return execute(sql) # Define a method called `username` # that receives an `id` argument - # This method should return a list of tuples - # from an sql execution - #### YOUR CODE HERE - + # This method should return a list of tuples from an sql execution + def username(self, id): # Query 4 - # Write an SQL query - # that selects an employees full name + # Write an SQL query that selects an employee's full name # Use f-string formatting and a WHERE filter # to only return the full name of the employee # with an id equal to the id argument - #### YOUR CODE HERE - + sql = f""" + SELECT + first_name || ' ' || last_name AS full_name + FROM {self.name} + WHERE {self.name}.{self.name}_id = {id} + """ + return execute(sql) # Below is method with an SQL query - # This SQL query generates the data needed for - # the machine learning model. - # Without editing the query, alter this method - # so when it is called, a pandas dataframe - # is returns containing the execution of - # the sql query - #### YOUR CODE HERE + # This SQL query generates the data needed for the machine learning model. + # Without editing the query, alter this method so when it is called, + # a pandas dataframe is returned containing the execution of the sql query def model_data(self, id): - - return f""" + sql = f""" SELECT SUM(positive_events) positive_events , SUM(negative_events) negative_events FROM {self.name} JOIN employee_events USING({self.name}_id) WHERE {self.name}.{self.name}_id = {id} - """ \ No newline at end of file + """ + return execute_df(sql)