Last active
August 29, 2015 14:16
-
-
Save acmisiti/a16715097f1898a55134 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_reporting(data): | |
if not data: | |
return (0, 0) | |
unique_ids = list(set(data)) | |
num_unique_vistors = len(unique_ids) | |
# create frequency of visits by user id dict | |
frequency = dict((key, len([k for k in data if k == key])) for key in unique_ids) | |
# get average page views per user | |
avg = sum(frequency.values())/float(num_unique_vistors) | |
return (num_unique_vistors, avg) | |
dataset1 = [8, 8, 2, 2] | |
assert get_reporting(dataset1) == (2, 2.0) | |
dataset2 = [9, 8, 9] | |
assert get_reporting(dataset2) == (2, 1.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment