Last active
July 25, 2018 20:44
-
-
Save jparishy/64af5a77baf64137f9bac36e55924026 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
const transformDAUResponse = (response) => { | |
return response.dau; | |
}; | |
const transformDateForDAUURL = (date) => { | |
return `/get/daus/?date=${data}`; | |
} | |
const reduceDAUs = (DAUs) => { | |
if (DAUs.length == 0) { | |
return 0; | |
} | |
return DAUs.reduce(0, (agg, dau) => agg + dau) / DAUs.length; | |
}; | |
const retrieveDataForDates = (dates, dateTransformer, responseTransformer, valuesReducer) => { | |
const urls = dates.map(date => dateTransformer(date)); | |
const resultPromises = urls.map(url => await axios.get(url)); | |
const results = await Promise.all(resultPromises); | |
const valuesFromResults = results.map(result => responseTransformer(result.data)); | |
return valuesReducer(valuesFromResults); | |
}; | |
const getDAUStats = (month) => { | |
const averageDAUCurrent = await retrieveDataForDates(getListOfDatesForEachDayInMonth(month), transformDateForDAUURL, transformDAUResponse, reduceDAUs); | |
const averageDAULast = await retrieveDataForDates(getListOfDatesForEachDayInMonth(month - 1), transformDateForDAUURL, transformDAUResponse, reduceDAUs); | |
// Update UI | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment