I have a script that takes a list of metrics as an input, and then fetches those metrics from the database to perform various operations with them.
My problem is that different clients get different subsets of the metrics, but I don't want to write a new IF block every time we add a new client. So right now, I have a large IF block that calls different functions based on whether the corresponding metric is in the list. What is the most elegant or Pythonic way of handling this?
Setup and function definitions:
clientOne = ['churn','penetration','bounce']
clientTwo = ['engagement','bounce']def calcChurn(clientId):churn = cursor.execute(sql to get churn)[...]return churndef calcEngagement(clientId):engagement = cursor.execute(sql to get engagement)[...]return engagement
Imagine three other functions in a similar format, so there is one function that corresponds to each unique metric. Now here is the block of code in the script that takes the list of metrics:
def scriptName(client, clientId):if churn in client:churn = calcChurn(clientId)if engagement in client:engagement = calcEngagement(clientId)if penetration in client:[...]