Published
Edited
Dec 10, 2020
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
data = rawData.map(d => ({
...d,
supervisor_vacancy: d.authorized_supervisors - d.ft_supervisors,
co_vacancy: d.authorized_cos - d.ft_cos,
vacancy:
d.authorized_supervisors + d.authorized_cos - d.ft_supervisors - d.ft_cos
}))
Insert cell
totalVacanciesMarshall = marshallMonthlyVacancies.reduce(function(sum, d) {
return sum + d.vacancy;
}, 0)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
marshallMonthlyVacancies = data.filter(
d =>
d.facility === 'Marshall' &&
d.co_vacancy > 0 &&
d.supervisor_vacancy > -1 && // In one month, there is a clear data entry error that causes supervisor vacancies to be negative
d.date >= moment(marshallStartDate) &&
d.date <= moment(marshallEndDate)
)
Insert cell
Insert cell
marshallMonthlyCostPerVacancy = marshallMonthlyVacancies.map(d => ({
date: d.date,
cost_per_vacancy: d.mandatory_post_remittances / d.vacancy,
vacancy: d.vacancy,
mandatory_post_remittances: d.mandatory_post_remittances,
ref: d
}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
calculateExpected = (facilityName, filtered) => {
const facility = filtered.filter(d => d.facility === facilityName);
const remittances = d3.sum(facility, d => d.mandatory_post_remittances);
const expected = d3.sum(facility, d => d.vacancy * assumedVacancyCost);
return Math.trunc(expected - remittances);
}
Insert cell
wilkinsonExpectedRefund = calculateExpected("Wilkinson", data)
Insert cell
emcfExpectedRefund = calculateExpected("EMCF", data)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rawData = d3.csv(
`${URLROOT}/mdoc-remittances20201103/assets/mdoc-remittances-combined.${fileVersion}.csv`,
d => ({
date: moment(d.month, "MMMM YYYY"),
facility: d.facility,
billed: +d.billed,
paid: +d.paid,
mandatory_post_remittances: +d.mandatory_post_remittances,
ft_cos: +d.ft_cos,
ft_supervisors: +d.ft_supervisors,
authorized_cos: +d.authorized_cos,
authorized_supervisors: +d.authorized_supervisors
})
)
Insert cell
Insert cell
Insert cell
Insert cell
moment = require("moment")
Insert cell
d3 = require("d3@6", "d3-array@2")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more