Created
March 7, 2019 08:37
-
-
Save walkerofmargins/ba5ef70ae129ffd47b3b53d5fd8ed650 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
var params = { | |
number_of_days: 7, | |
sample_percentage: 1, | |
libs: {'web':''}, | |
last_seen: 'Registration Date', | |
csv_format: true, | |
people_spec: ["Community member"] | |
} | |
var defaults = ["$city", "$region", "mp_country_code", "$brand", "$bluetooth_version", "$device", "$os", "$app_release", "$app_version", "$carrier", "$lib_version", "$wifi", "$screen_width", "$screen_height", "$model", "$os_version", "$manufacturer", "$screen_dpi", "$has_telephone", "has_nfc", "$bluetooth_enabled", "$browser", "$initial_referrer", "$initial_referring_domain", "$referrer", "$referring_domain", "$browser_version", "mp_keyword", "$search_engine", "utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term", "$radio", "mp_device_model", "$google_play_services", "mp_lib", "campaign_id", "message_id", "message_subtype", "message_type", "$answer_count", "survey_id", "collection_id", "$survey_shown", "$watch_model", "$ios_ifa", "$current_url", "$duration", "$from_binding", "$experiments", "$import", "distinct_id", "time", "$has_nfc", "$app_version_string", "$app_build_number", "$android_app_version", "$android_app_version_code", "$android_brand", "$android_lib_version", "$android_model", "$android_os", "$android_os_version", "$android_manufacturer", "$distinct_id", "$country_code", "$campaigns", "$deliveries", "$experiments", "$ios_app_release", "$ios_app_version", "$ios_device_model", "$ios_lib_version", "$ios_version", "$timezone", "$android_push_error", "$last_seen", "$ae_first_app_open_date", "$ae_total_app_session_length", "$ae_total_app_sessions", "$journeys"]; | |
function main() { | |
return People() | |
.filter(user => Math.random() < params.sample_percentage && new Date(user.properties[params.last_seen]).getTime() - new Date().getTime() > -60*60*24*1000*params.number_of_days && (user.properties.$ios_app_release == params.libs['iphone'] || user.properties.$android_app_version == params.libs['android'] || !(!user.properties.$ios_app_version || user.properties.$android_app_version))) | |
.reduce(function(accums, items) { | |
var result = {} | |
if(params.libs.toString().indexOf('web') > -1) { | |
result['web'] = {} | |
if(params.libs.toString().indexOf('iphone') > -1) { | |
result['web + iphone'] = {} | |
result['iphone'] = {} | |
if(params.libs.toString().indexOf('android') > -1) { | |
result['web + android'] = {} | |
result['iphone + android'] = {} | |
result['web + iphone + android'] = {} | |
result['android'] = {} | |
} | |
} else if(params.libs.toString().indexOf('android') > -1) { | |
result['web + android'] = {} | |
result['android'] = {} | |
} | |
} else { | |
if(params.libs.toString().indexOf('iphone') > -1) { | |
result['iphone'] = {} | |
if(params.libs.toString().indexOf('android') > -1) { | |
result['iphone + android'] = {} | |
result['android'] = {} | |
} | |
} else if(params.libs.toString().indexOf('android') > -1) { | |
result['android'] = {} | |
} | |
} | |
_.each(accums, function(accum) { | |
var libraries = Object.keys(accum) | |
_.each(libraries, function(lib) { | |
if(!result[lib]) { | |
result[lib] = {} | |
} | |
var props = Object.keys(accum[lib]) | |
_.each(props, function(prop) { | |
if(!result[lib][prop]) { | |
result[lib][prop] = 0 | |
} | |
result[lib][prop] += accum[lib][prop] | |
}) | |
}) | |
}) | |
_.each(items, function(item) { | |
var keys = _.keys(_.omit(item.properties, defaults)) | |
var user_platform = item.properties.$browser && !item.properties.$ios_lib_version && !item.properties.$android_lib_version ? 'web' : (item.properties.$browser && item.properties.$ios_lib_version && !item.properties.$android_lib_version ? 'web + iphone' : (item.properties.$browser && !item.properties.$ios_lib_version && item.properties.$android_lib_version ? 'web + android' : (item.properties.$browser && item.properties.$ios_lib_version && item.properties.$android_lib_version ? 'web + iphone + android' : (!item.properties.$browser && item.properties.$ios_lib_version && !item.properties.$android_lib_version ? 'iphone' : (!item.properties.$browser && !item.properties.$ios_lib_version && item.properties.$android_lib_version ? 'android' : (!item.properties.$browser && item.properties.$ios_lib_version && item.properties.$android_lib_version ? 'iphone + android' : 'unknown') ))))) | |
if(!result[user_platform]) { | |
result[user_platform] = {} | |
} | |
_.each(keys, function(prop) { | |
if(!result[user_platform][prop]) { | |
result[user_platform][prop] = 0 | |
} | |
result[user_platform][prop] += 1 | |
}) | |
if(!result[user_platform].mp_total) { | |
result[user_platform].mp_total = 0 | |
} | |
result[user_platform].mp_total += 1 | |
}) | |
return result | |
}) | |
.map(function(item) { | |
var platforms = Object.keys(item) | |
var res = {} | |
_.each(platforms, function(platform) { | |
if(!res[platform]) { | |
res[platform] = {} | |
res[platform].MissingProperties = [] | |
res[platform].InconsistentProperties = [] | |
} | |
var props = Object.keys(item[platform]) | |
var otherProps = [] | |
if(!params.people_spec) { | |
_.each(platforms, function(comparePlatform) { | |
if(platform!==comparePlatform && item[comparePlatform]) { | |
otherProps = _.union(otherProps, Object.keys(item[comparePlatform])) | |
} | |
}) | |
} else { | |
if(params.people_spec.length > 0) { | |
otherProps = params.people_spec | |
} | |
} | |
_.each(otherProps, function(compareProp) { | |
if(!_.contains(props, compareProp)) { | |
if(platform.indexOf('+') == -1) { | |
res[platform].MissingProperties.push(compareProp) | |
} | |
} | |
}) | |
_.each(props, function(prop) { | |
if(item[platform][prop] / item[platform].mp_total < .8 && item[platform][prop] / item[platform].mp_total > .1) { | |
if(platform.indexOf('+') == -1) { | |
res[platform].InconsistentProperties.push(prop) | |
} | |
} | |
}) | |
}) | |
if(params.csv_format) { | |
var human_res = []; | |
_.each(platforms, function(platform) { | |
_.each(res[platform].MissingProperties, function(prop) { | |
human_res.push({'Platform':platform,'Issue Type':'Missing Properties','Values':prop}) | |
}) | |
_.each(res[platform].InconsistentProperties, function(prop) { | |
human_res.push({'Platform':platform,'Issue Type':'Inconsistent Properties','Values':prop}) | |
}) | |
}) | |
return human_res | |
} else { | |
return res | |
} | |
}) | |
.flatten() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment