Public
Edited
Jun 15, 2023
Insert cell
Insert cell
viewof constructionType = Inputs.select(["Steel Frame","Wood Frame","Mass","Metal Building"], {label: "Construction Type"})
Insert cell
viewof constructionType2 = Inputs.select(["Steel Frame","Wood Frame","Mass","Metal Building"], {label: "Construction Type"})
Insert cell
viewof infiltrationRate = Inputs.range([1, 1], {step: 1, label: "Infiltration Rate"})
Insert cell
viewof infiltrationRate3 = Inputs.range([1, 1], {step: 1, label: "Infiltration Rate"})
Insert cell
viewof locations = Inputs.select(["office","circulations","atrium"], {label: "Locations"})
Insert cell
viewof grossFloorArea = Inputs.range([0, 255], {step: 1, label: "Gross Floor Area"})
Insert cell
viewof hvac = Inputs.select(["Ideal Air","VAV All Air","Radiant w/ DOAS"], {label: "HVAC System Type"})
Insert cell
viewof hvac2 = Inputs.select(["Ideal Air","VAV All Air","Radiant w/ DOAS"], {label: "HVAC System Type"})
Insert cell
viewof heatRecoveryEfficiency = Inputs.range([0, 100], {step: 5, label: "Heat Recovery Efficiency"})
Insert cell
viewof heatRecoveryEfficiency2 = Inputs.range([0, 100], {step: 5, label: "Heat Recovery Efficiency"})
Insert cell
viewof economizer = Inputs.radio(["Yes", "No"], {label: "Economizer", value:"Yes"})
Insert cell
viewof economizer2 = Inputs.radio(["Yes", "No"], {label: "Economizer", value:"Yes"})
Insert cell
viewof ventilation = Inputs.select(["Min Outdoor Air","5X Min","10X Min","VOC Biofilter","Full Biofilter"], {label: "Ventilation Type"})
Insert cell
viewof ventilation2 = Inputs.select(["Min Outdoor Air","5X Min","10X Min","VOC Biofilter","Full Biofilter"], {label: "Ventilation Type"})
Insert cell
viewof bioType = Inputs.select(["1 Hot Humid","2 Hot Dry","3 Marine","4 Mixed Humid","5 Mixed Dry","6 Cold","7 Very Cold","8 Subarctic"], {label: "Climate Zone"})
Insert cell
viewof bioType2 = Inputs.select(["1 Hot Humid","2 Hot Dry","3 Marine","4 Mixed Humid","5 Mixed Dry","6 Cold","7 Very Cold","8 Subarctic"], {label: "Climate Zone"})
Insert cell
viewof climateZone = Inputs.select(["1 Hot Humid","2 Hot Dry","3 Marine","4 Mixed Humid","5 Mixed Dry","6 Cold","7 Very Cold","8 Subarctic"], {label: "Climate Zone"})
Insert cell
viewof climateZone2 = Inputs.select(["1 Hot Humid","2 Hot Dry","3 Marine","4 Mixed Humid","5 Mixed Dry","6 Cold","7 Very Cold","8 Subarctic"], {label: "Climate Zone"})
Insert cell
viewof tempSet = Inputs.range([0, 100], {step: 1, label: "Temperature Setpoint"})
Insert cell
viewof bioPower = Inputs.range([0, 100], {step: 1, label: "Biofilter Power"})
Insert cell
viewof metabolicRate = Inputs.range([1, 4], {step: 1, label: "Metabolic Rate"})
Insert cell
viewof metabolicRate2 = Inputs.range([1, 4], {step: 1, label: "Metabolic Rate"})
Insert cell
viewof occSched = Inputs.radio(["Typical", "Sparse","Dense"], {label: "Occupancy Schedule"})
Insert cell
viewof program = Inputs.select(["Office","Hotel","Apartment","Hospital"], {label: "Program"})
Insert cell
viewof program2 = Inputs.select(["Office","Hotel","Apartment","Hospital"], {label: "Program"})
Insert cell
viewof actLvl = Inputs.range([0, 100], {step: 1, label: "Activity Level (Mets)"})
Insert cell
viewof wwRatio = Inputs.range([0, 1], {step: .05, label: "Window to Wall Ratio"})
Insert cell
viewof wwRatio2 = Inputs.range([0, 1], {step: .05, label: "Window to Wall Ratio"})
Insert cell
btn = DOM.download(serialize(textOb), "userSettings", "Save Inputs")
Insert cell
viewof clicks = Inputs.button("Click me")
Insert cell
textOb
Insert cell
viewof infiltrationRate.value
Insert cell
viewof clicks2 = Inputs.button("Set Inputs")
Insert cell
viewof mirror = Inputs.button("Mirror Data")
Insert cell
clicks2
Insert cell
viewof name = Inputs.text({placeholder: "File Name"})
Insert cell
name
Insert cell
name1 = []
Insert cell
name1[name1.length-1]
Insert cell
{
if(clicks2>0){
textOb.run
//name.run
name1.push(constructionType)
//name1.length=0
//clicks2.value=0
console.log("click")
}

return textOb[1].value
}
Insert cell
btn2=DOM.download(serialize(textOb))
Insert cell
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", {bubbles: true}));
}
Insert cell
mirror
Insert cell
mirrorData={

if(mirror>0){
set(viewof ventilation2,ventilation)
set(viewof climateZone2,climateZone)
set(viewof program2,program)
set(viewof constructionType2,constructionType)
set(viewof hvac2,hvac)
set(viewof metabolicRate2,metabolicRate)
set(viewof heatRecoveryEfficiency2,heatRecoveryEfficiency)
set(viewof infiltrationRate2,infiltrationRate)
set(viewof wwRatio2,wwRatio)
set(viewof economizer2,economizer)

//console.log("hellllo")

set(viewof mirror,0)
}

//mirror
//return mirror
//return [{name:"set",value:mirror}]
}

Insert cell
dashboard = html`<div class='dashboardOuter' style='height:800px;width:1200px'>

<div class="topText" style="position:absolute;left:20px;top:00px;width:500px">
<h3 > BIPS<br>
Project Name: AERA New York</br>
</div>

<div class="inputsLabel" style="position:absolute;left:20px;top:100px">
<h3 > Model Inputs</h3>
</div>



<div class="inputViews" style="position:absolute;left:50px;top:165px;width:330px;">
<h3>Scenario 01</h3>
${viewof ventilation}
${viewof climateZone}
${viewof program}
${viewof constructionType}
${viewof hvac}
${viewof metabolicRate}
${viewof heatRecoveryEfficiency}


${viewof wwRatio}
${viewof economizer}


</div>


<div class="inputViews" style="position:absolute;left:470px;top:165px;width:200px;">
<h3>Scenario Comparison</h3>
</div>

<div class="inputViews" style="position:absolute;left:470px;top:200px;width:300px;">
<p>Predicted CO2 (ppm) </p>
<div class="inputViews" style="position:absolute;left:40px;top:30px;width:40%;">
${pie1}
</div>
<div class="inputViews" style="position:absolute;left:0%;top:50px;">
<h3>${predictedC02}</h3>
</div>
<div class="inputViews" style="position:absolute;left:50%;top:50px;">
<h3>${predictedC022}</h3>
</div>


</div>


<div class="inputViews" style="position:absolute;left:470px;top:400px;width:300px;">
<p>Predicted Avg VOC (ppb)<br></br> </p>
<div class="inputViews" style="position:absolute;left:40px;top:30px;width:40%;">
${pie2}
</div>
<div class="inputViews" style="position:absolute;left:0%;top:50%;">
<h3>${predictedVOC}</h3>
</div>
<div class="inputViews" style="position:absolute;left:50%;top:50%;">
<h3>${predictedVOC2}</h3>
</div>
</div>

<div class="inputViews" style="position:absolute;left:770px;top:200px;width:300px;">
<p>Predicted EUI (kwh/m2/yr)<br></br> </p>
<div class="inputViews" style="position:absolute;left:40px;top:30px;width:40%;">
${pie3}
</div>
<div class="inputViews" style="position:absolute;left:0%;top:50%;">
<h3>${predictedbuilding}</h3>
</div>
<div class="inputViews" style="position:absolute;left:50%;top:50%;">
<h3>${predictedbuilding2}</h3>
</div>
</div>

<div class="inputViews" style="position:absolute;left:770px;top:400px;width:300px;">
<p>Predicted Required Greenwall (m2)<br></br> </p>
<div class="inputViews" style="position:absolute;left:40px;top:30px;width:40%;">
${pie4}
</div>
<div class="inputViews" style="position:absolute;left:0%;top:50%;">
<h3>${predictedbalanc}</h3>
</div>
<div class="inputViews" style="position:absolute;left:50%;top:50%;">
<h3>${predictedbalanc2}</h3>
</div>
</div>


<div class="inputViews" style="position:absolute;left:1050px;top:165px;width:330px;">
<h3>Scenario 02</h3>
${viewof ventilation2}
${viewof climateZone2}
${viewof program2}
${viewof constructionType2}
${viewof hvac2}
${viewof metabolicRate2}
${viewof heatRecoveryEfficiency2}


${viewof wwRatio2}
${viewof economizer2}



</div>



<div class="download" style="position:absolute;left:175px;top:100px;height:50px;width:100px">
${viewof clicks2}
</div>
<div class="download" style="position:absolute;left:255px;top:100px;height:50px;width:100px">
${viewof mirror}
</div>

<div class="download" style="position:absolute;left:340px;top:100px;height:50px;width:100px">

${btn}
</div>





<div class="download" style="display:none">

${mirrorData}
</div>



</div>

`
Insert cell
/*function serialize (data) {
let s = JSON.stringify(data);
return new Blob([s], {type: "application/json"})
}*/
Insert cell
viewof infiltrationRate2 = Inputs.range([0, 255], {step: 1, label: "Infiltration Rate2"})
Insert cell
function serialize1 (data){
console.log("hello")
textOb

//serialize(data)
//return jkd
}
Insert cell
import {serialize} from "@palewire/saving-json"
Insert cell
button = (data, filename = 'data.csv') => {
if (!data) throw new Error('Array of data required as first argument');

let downloadData;
if (filename.includes('.csv')) {
downloadData = new Blob([d3.csvFormat(data)], { type: "text/csv" });
} else {
downloadData = new Blob([JSON.stringify(data, null, 2)], {
type: "application/json"
});
}

const size = (downloadData.size / 1024).toFixed(0);
const button = DOM.download(
downloadData,
filename,
`Download ${filename} (~${size} KB)`
);
return button;
}
Insert cell
rf = import('https://cdn.skypack.dev/ml-random-forest@2.1.0?min')
Insert cell
Insert cell
fullDataSet2 = FileAttachment("500 - Sheet2@1.csv").csv()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fullDataSet = d3.csv(fullDataSetLink, d3.autoType)
Insert cell
Insert cell
trainingSetFormatted = formattedData.map((d) => d.slice(0, 10));
Insert cell
avgVOCtraining = formattedData.map((d) => d[12])
Insert cell
predictionsFormatted = formattedData.map((d) => d[13])
Insert cell
regression = new rf.RandomForestRegression(options)
Insert cell
regressionVOC = new rf.RandomForestRegression(options)
Insert cell
a = await regression.train(trainingSetFormatted, predictionsFormatted);
Insert cell
VOCtrained2 = await regressionVOC.train(trainingSetFormatted, avgVOCtraining);
Insert cell
result = a, regression.predict(trainingSetFormatted);
Insert cell
regressionFormald = new rf.RandomForestRegression(options)
Insert cell
buildingtraining = formattedData.map((d) => d[14])
Insert cell
buildingTrain = await regressionFormald.train(trainingSetFormatted, buildingtraining);
Insert cell
building = buildingTrain, regressionFormald.predict(userInputs);
Insert cell
building2 = buildingTrain, regressionFormald.predict(userInputs2);
Insert cell
predictedbuilding = round(building,0)
Insert cell
predictedbuilding2 = round(building2,0)
Insert cell
regressionBenzene = new rf.RandomForestRegression(options)
Insert cell
balanctraining = formattedData.map((d) => d[15])
Insert cell
balancTrain = await regressionBenzene.train(trainingSetFormatted, balanctraining);
Insert cell
balanc = balancTrain, regressionBenzene.predict(userInputs);
Insert cell
balanc2 = balancTrain, regressionBenzene.predict(userInputs2);
Insert cell
predictedbalanc = round(balanc,0)
Insert cell
predictedbalanc2 = round(balanc2,0)
Insert cell
//resultVOC = VOCtrained, regression.predict(trainingSetFormatted);
Insert cell
co2 = a, regression.predict(userInputs);
Insert cell
co22 = a, regression.predict(userInputs2);
Insert cell
predictedC02 = round(co2,0)
Insert cell
predictedC022 = round(co22,0)
Insert cell
resultVOC = VOCtrained2, regressionVOC.predict(userInputs);
Insert cell
resultVOC2 = VOCtrained2, regressionVOC.predict(userInputs2);
Insert cell
predictedVOC = round(resultVOC,0)
Insert cell
predictedVOC2 = round(resultVOC2,0)
Insert cell
round = (n, places) => {
if (!places) return Math.round(n);
const d = 10 ** places;
return Math.round(n * d) / d;
}
Insert cell
Plot.plot({
aspectRatio: 1,
x: {label: "Age (years)"},
y: {
grid: true,
label: "← Women · Men →",
labelAnchor: "center",
tickFormat: Math.abs
},
marks: [
Plot.dot(
co2result,
Plot.stackY({
x: (d) => d.output,
y: (d) => d.value === "prediction" ? 1 : -1,
fill: "gender",
title: "full_name"
})
),
Plot.ruleY([0])
]
})
Insert cell
co2result = [
{output:"Predicted CO2", prediction:'1', fill:"red",value:predictedC022},
{output:"Predicted CO2", prediction:'2', fill:"blue",value:predictedC02}
]
Insert cell
build = [
{output:"Predicted AVG CO2", prediction:'1', fill:"red",value:predictedbuilding2},
{output:"Predicted AVG CO2", prediction:'2', fill:"blue",value:predictedbuilding}
]
Insert cell
avgvocresult = [
{output:"Predicted AVG CO2", prediction:'1', fill:"red",value:predictedVOC2},
{output:"Predicted AVG CO2", prediction:'2', fill:"blue",value:predictedVOC}
]
Insert cell
balance = [
{output:"Predicted AVG CO2", prediction:'1', fill:"red",value:predictedbalanc2},
{output:"Predicted AVG CO2", prediction:'2', fill:"blue",value:predictedbalanc}
]
Insert cell
plot1 = Plot.barX(co2result, {x: "value", y: "prediction", fill:"fill"}).plot()
Insert cell
plot2 = Plot.barX(avgvocresult, {x: "value", y: "prediction", fill:"fill"}).plot()
Insert cell
pie1 = PieChart(co2result, {
name: d => d.prediction,
value: d => d.value,
//colors:d => d.fill,
width: 400,
height: 500
})
Insert cell
pie2 = PieChart(avgvocresult, {
name: d => d.prediction,
value: d => d.value,
//colors:d => d.fill,
width: 400,
height: 500
})
Insert cell
pie3 = PieChart(build, {
name: d => d.prediction,
value: d => d.value,
//colors:d => d.fill,
width: 400,
height: 500
})
Insert cell
pie4 = PieChart(balance, {
name: d => d.prediction,
value: d => d.value,
//colors:d => d.fill,
width: 400,
height: 500
})
Insert cell
// Copyright 2021 Observable, Inc.
// Released under the ISC license.
// https://observablehq.com/@d3/pie-chart
function PieChart(data, {
name = ([x]) => x, // given d in data, returns the (ordinal) label
value = ([, y]) => y, // given d in data, returns the (quantitative) value
title, // given d in data, returns the title text
width = 640, // outer width, in pixels
height = 400, // outer height, in pixels
innerRadius = 0, // inner radius of pie, in pixels (non-zero for donut)
outerRadius = Math.min(width, height) / 2, // outer radius of pie, in pixels
labelRadius = (innerRadius * 0.2 + outerRadius * 0.8), // center radius of labels
format = ",", // a format specifier for values (in the label)
names, // array of names (the domain of the color scale)
colors, // array of colors for names
stroke = innerRadius > 0 ? "none" : "black", // stroke separating widths
strokeWidth = 1, // width of stroke separating wedges
strokeLinejoin = "round", // line join of stroke separating wedges
padAngle = stroke === "none" ? 1 / outerRadius : 0, // angular separation between wedges
} = {}) {
// Compute values.
const N = d3.map(data, name);
const V = d3.map(data, value);
const I = d3.range(N.length).filter(i => !isNaN(V[i]));

// Unique the names.
if (names === undefined) names = N;
names = new d3.InternSet(names);

// Chose a default color scheme based on cardinality.
if (colors === undefined) colors = d3.schemeSpectral[names.size];
if (colors === undefined) colors = d3.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), names.size);

// Construct scales.
const color = d3.scaleOrdinal(names, colors);

// Compute titles.
if (title === undefined) {
const formatValue = d3.format(format);
title = i => `${N[i]}\n${formatValue(V[i])}`;
} else {
const O = d3.map(data, d => d);
const T = title;
title = i => T(O[i], i, data);
}

// Construct arcs.
const arcs = d3.pie().padAngle(padAngle).sort(null).value(i => V[i])(I);
const arc = d3.arc().innerRadius(innerRadius).outerRadius(outerRadius);
const arcLabel = d3.arc().innerRadius(labelRadius).outerRadius(labelRadius);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [(-width / 2)-5, -height / 2, width+50, height])
.attr("style", "max-width: 100%; height: auto; height: intrinsic;");

svg.append("g")
.attr("stroke", stroke)
//.attr("stroke-width", strokeWidth)
.attr("stroke-width", '2')
.attr("stroke-linejoin", strokeLinejoin)
.selectAll("path")
.data(arcs)
.join("path")
//.attr("fill", d => color(N[d.data]))
.attr("fill", 'rgba(230,230,230)')
.attr("d", arc)
.append("title")
//.text(d => title(d.data));

svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("text-anchor", "middle")
.selectAll("text")
.data(arcs)
.join("text")
.attr("transform", d => `translate(${arcLabel.centroid(d)})`)
.selectAll("tspan")
.data(d => {
const lines = `${title(d.data)}`.split(/\n/);
return (d.endAngle - d.startAngle) > 0.25 ? lines : lines.slice(0, 1);
})
.join("tspan")
.attr("x", 0)
.attr("y", (_, i) => `${i * 1.1}em`)
.attr("font-weight", (_, i) => i ? null : "bold")
//.text(d => d);

return Object.assign(svg.node(), {scales: {color}});
}
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