Public
Edited
May 8, 2023
Insert cell
Insert cell
Insert cell
simpleHistogram = Histogram(tpt, {
value: (d) => d["TPT"],
y: (d) => d["Case count"],
label: "Throughput time (days) →",
yLabel: "↑ Case count",
width,
height: 500,
color: "steelblue",
xFormat: ".1~s",
marginLeft: 60,
marginRight: 40,
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// otp2 = Histogram(otp, {
// value: (d) => +d.days / 7,
// y: (d) => +d.cases,
// label: "Time of payment (days) →",
// width,
// height: 500,
// thresholds: [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1 ,2, 3, 4, 5, 6, 7, 8, 9, 10],
// xDomain: [lowestQuantile / 7, -10, 10, highestQuantile / 7], // domain
// xTickValues: [lowestQuantile / 7, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, highestQuantile / 7],
// xRange: [60, 60 + 50, width - 60 - 50, width - 60],
// marginLeft: 60,
// marginRight: 60,
// color: (d) => (d.x0 < -2 || d.x0 >= 2 ? "grey" : "steelblue"),
// })
Insert cell
Insert cell
otp = FileAttachment("payments.csv").csv()
Insert cell
Insert cell
tptOutlierBounds1 = getOutliers(tpt, (d) => d["TPT"])
Insert cell
Insert cell
getOutliers = (data, value) => {
const min = d3.min(data, value);
const max = d3.max(data, value);
const q1 = 1
const q2 = 6
const q3 = 31
const iqr = q3 - q1; // interquartile range
const r0 = Math.max(min, q1 - iqr * 1.5);
const r1 = Math.min(max, q3 + iqr * 1.5);
console.log(q1, q2, q3);
return [r0, r1]
}
Insert cell
array = otp.map(d => {
const casesArray = Array(+d.cases)
console.log(casesArray);
})
Insert cell
// otpOutlierBounds = getOutliers(otp, (d) => +d.days)
Insert cell
otpThresholds = getThresholds(otpOutlierBounds[0], otpOutlierBounds[1], (d) => +d.days);
Insert cell
getThresholds = (min, max, value) => {
const thresholdsNum = d3.thresholdFreedmanDiaconis(
otp.map(value),
min,
max
)
let thresholds = []
const diff = Math.abs(max - min)
const step = diff/thresholdsNum;

for(let i = min; i <= max; i+= step) {
thresholds.push(i);
}
return thresholds
}
Insert cell
otpMin = d3.min(otp, (d) => +d.days);
Insert cell
otpMax= d3.max(otp, (d) => +d.days);
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more