Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 32 additions & 35 deletions python-package/employee_events/employee.py
Original file line number Diff line number Diff line change
@@ -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}
"""
"""
return execute_df(sql)