Last active
September 3, 2016 18:04
-
-
Save ttrefren/5d134da6a7ef7f9f6340139e279b2979 to your computer and use it in GitHub Desktop.
This file contains 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
// get distribution of active days per company over a week. | |
// e.g. "100 companies were active 1 day, 200 were active 2 days, ..., 65 were active 7 days" | |
function main() { | |
return Events({ | |
from_date: "2016-08-21", | |
to_date: "2016-08-26" | |
}) | |
// dedupe into (day, company_id) tuples, because all we care about is | |
// that the company was present that day | |
.groupBy([event_to_date, "properties.company_id"], mixpanel.reducer.noop()) | |
// group again by company_id and count the number of unique days | |
.groupBy(["key.1"], mixpanel.reducer.count()) | |
// group AGAIN by the count to figure out your usage distribution across companies | |
.groupBy(["value"], mixpanel.reducer.count()) | |
} | |
function event_to_date(e) { | |
return new Date(e.time).toISOString().split('T')[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment