Published
Edited
Apr 22, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function ghg(f, m, s) {
//f = the period of evaluation (frame), m = max capacity of the battery, s = starting charge of battery
const demand = f.map(d => Math.max(d.project_demand - d.pv_generation, 0));
const max_rate = m / 6;
//const low = year === "grid_CO2e_2020" ? 0.25: 0.40;
//const high = year === "grid_CO2e_2030" ? 0.75: 0.60;
const high = percentile(f, max_rate, s);
const low = 1 - high;

const charge_min = d3.quantile(f.map(d => d[year]), low);
const charge_max = d3.quantile(f.map(d => d[year]), high);

return f.map((d, i) => {
let discharge = 0;
if (d[year] >= charge_max) {
discharge = 1;
}
else if (d[year] <= charge_min) {
discharge = -1;
}
return {discharge: discharge, discharge_limit: max_rate};

});
}

Insert cell
function percentile(d, r, start_charge) {
if(year == "grid_CO2e_2030") {
d.sort((a, b) => b.grid_CO2e_2030 - a.grid_CO2e_2030);
}
else {
d.sort((a, b) => b.grid_CO2e_2020 - a.grid_CO2e_2020);
}
let charge = start_charge;
let i = 0;
while ((i<=23) && (charge <= r*(22-i))) {
let demand = d[i].project_demand <= d[i].pv_generation ? 0 : d[i].project_demand - d[i].pv_generation;
charge += Math.min(demand, r);
i++;
}

return (1-i/24);
}
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