Skip to content

Instantly share code, notes, and snippets.

@jparishy
Last active July 25, 2018 20:44
Show Gist options
  • Save jparishy/64af5a77baf64137f9bac36e55924026 to your computer and use it in GitHub Desktop.
Save jparishy/64af5a77baf64137f9bac36e55924026 to your computer and use it in GitHub Desktop.
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