def calculate_ltv (query_results, aggregation_method, profiles):
responses_by_id = {}
for i in profiles:
if aggregation_method == "count" or aggregation_method == "sum":
# default all entries for counted or summed aggregations to 0 to start... will be replaced later if there is a response
responses_by_id[i["id"]] = [0]
for row in query_results:
responses_by_id[row["id"]] = row["data"]
return responses_by_id
mock_query_results = [{"id":1, "data":[112.50]}, {"id":2, "data":[16.48]}, {"id":3, "data":[42.97]}, {"id":4, "data":[96.41]}]
mock_aggregation_method = "sum"
mock_profiles = [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}]
print(calculate_ltv(mock_query_results, mock_aggregation_method, mock_profiles))
ZGVmIGNhbGN1bGF0ZV9sdHYgKHF1ZXJ5X3Jlc3VsdHMsIGFnZ3JlZ2F0aW9uX21ldGhvZCwgcHJvZmlsZXMpOgogIHJlc3BvbnNlc19ieV9pZCA9IHt9CiAgCiAgZm9yICBpIGluIHByb2ZpbGVzOgogICAgaWYgYWdncmVnYXRpb25fbWV0aG9kID09ICJjb3VudCIgb3IgYWdncmVnYXRpb25fbWV0aG9kID09ICJzdW0iOgogICAgICAgICMgZGVmYXVsdCBhbGwgZW50cmllcyBmb3IgY291bnRlZCBvciBzdW1tZWQgYWdncmVnYXRpb25zIHRvIDAgdG8gc3RhcnQuLi4gd2lsbCBiZSByZXBsYWNlZCBsYXRlciBpZiB0aGVyZSBpcyBhIHJlc3BvbnNlCiAgICAgICAgcmVzcG9uc2VzX2J5X2lkW2lbImlkIl1dID0gWzBdCiAgCiAgZm9yIHJvdyBpbiBxdWVyeV9yZXN1bHRzOgogICAgcmVzcG9uc2VzX2J5X2lkW3Jvd1siaWQiXV0gPSByb3dbImRhdGEiXQogIAogIHJldHVybiByZXNwb25zZXNfYnlfaWQKCgptb2NrX3F1ZXJ5X3Jlc3VsdHMgPSBbeyJpZCI6MSwgImRhdGEiOlsxMTIuNTBdfSwgeyJpZCI6MiwgImRhdGEiOlsxNi40OF19LCB7ImlkIjozLCAiZGF0YSI6WzQyLjk3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