Skip to content

Instantly share code, notes, and snippets.

@jfreels
Created November 30, 2021 00:10
Show Gist options
  • Save jfreels/b29a645701d63935f7dbc816dd566ec7 to your computer and use it in GitHub Desktop.
Save jfreels/b29a645701d63935f7dbc816dd566ec7 to your computer and use it in GitHub Desktop.
Determine product usage over the last 7 days
""" Determine product usage over the last 7 days """
import sys
DATALIST = {
"android": [0,1,1,0,1,1,1],
"iphone": [0,1,1,0,1,1,0],
"web": [0,0,0,1,1,1,1]
}
GROUPINGS = {
"overall": ["android", "iphone", "web"],
"mobile": ["android", "iphone"]
}
EXPECTED_RESULTS = {
"overall": 6,
"mobile": 5
}
def last_7_days(datalist:dict) -> dict:
"""
Given a list of devices and the last 7 days of usage (1 = usage, 0 = no usage),
return the number of users over the last 7 day period.
Only count a user once per day per grouping.
"""
overall = 0
mobile = 0
for i in range(7):
if datalist["android"][i] or datalist["iphone"][i] or datalist["web"][i]:
overall += 1
if datalist["android"][i] or datalist["iphone"][i]:
mobile += 1
results = {
"overall": overall,
"mobile": mobile
}
return results
def main():
results_l7 = last_7_days(datalist=DATALIST)
print(results_l7)
assert results_l7 == EXPECTED_RESULTS
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment