Public
Edited
Oct 26, 2023
Insert cell
Insert cell
Insert cell
pma = FileAttachment("pma@2.xlsx").xlsx()
Insert cell
Insert cell
sheet_name = "Meter Entries"
Insert cell
sheet.filter(d => d.E == "Fuel Oil (No. 2)")
Insert cell
sheet = pma.sheet(sheet_name)
Insert cell
Inputs.table(sheet)
Insert cell
Insert cell
data = {
// Sample the columns of interest
let data = pma.sheet(sheet_name).map(d => ({building: d.A, type: d.E, quantity: d.J, units: d.K, start: d.G, end: d.H, delivery: d.I}));

// Set "date" to either start or delivery date (latter is used for "Fuel Oil (No. 2)"
data.forEach(d => d.date = d.delivery == "Not Available" ? d.start : d.delivery)

// Remove extraneous rows at the beginning of the sheet
data = data.filter((d, i) => i > 5);

// Verify that start and end were correctly converted to date objects
if (Object.prototype.toString.call(data[0].start) !== "[object Date]") throw "start not converted to date";
if (Object.prototype.toString.call(data[0].end) !== "[object Date]") throw "end not converted to date";

return data;
}
Insert cell
{
// Sample the columns of interest
let data = pma.sheet(sheet_name).map(d => ({building: d.A, type: d.E, quantity: d.J, units: d.K, start: d.G, end: d.H, delivery: d.I}));

// Set "date" to either start or delivery date (latter is used for "Fuel Oil (No. 2)"
data.forEach(d => d.date = d.delivery == "Not Available" ? d.start : d.delivery)

return data
}
Insert cell
Insert cell
Inputs.table(data)
Insert cell
buildings = [...new Set(data.map(d => d.building))] // Unique entries -- with spread syntax
Insert cell
units = Array.from(new Set(data.map(d => d.units))) // Unique entries -- with Array.from()
Insert cell
types = Array.from(new Set(data.map(d => d.type))) // Unique entries
Insert cell
Insert cell
overall = Plot.plot({
width: width,
margin: 50,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{
fx: "building",
x: "date",
y: "quantity",
fill: "building",
tip: true
}
)
),
Plot.ruleY([0])
]
})
Insert cell
Plot.plot({
width: width,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{
fy: "building",
x: "date",
y: "quantity",
fill: "building",
tip: true
}
)
),
Plot.ruleY([0])
]
})

Insert cell
Plot.plot({
width: width,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{ fx: "type", x: "date", y: "quantity", fill: "type", tip: true }
)
),
Plot.ruleY([0])
]
})
Insert cell
Plot.plot({
width: width,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{ fy: "type", x: "date", y: "quantity", fill: "type", tip: true }
)
),
Plot.ruleY([0])
]
})
Insert cell
test = Plot.plot({
width: width,
y: {
type: "log"
},
color: {legend: true},
marks: [
Plot.dot(data, {x: "date", y:"quantity", tip: true, stroke: "type"}),
Plot.linearRegressionY(data, {x: "date", y: "quantity", stroke: "type"}),
Plot.linearRegressionY(data, {x: "date", y: "quantity"})
]
})
Insert cell
Plot.plot({
width: width,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{ fx: "building", x: "date", y: "cost", fill: "building", tip: true }
)
),
Plot.ruleY([0])
]
})
Insert cell
Plot.plot({
width: width,
color: { legend: true },
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
data,
Plot.binX(
{ y: "mean" },
{ fy: "building", x: "date", y: "cost", fill: "building", tip: true }
)
),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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