import Section from "./Section"; import Card from "./Card"; import Form from "./Form"; import TextInputRow from "./TextInputRow"; import FileInputRow from "./FileInputRow"; import DictInputRow from "./DictInputRow"; import { csvFormat, csvParse, generateFile } from "./csv"; const PlantBlock = (props) => { const onChange = (val, field1, field2, field3) => { const newPlant = { ...props.value }; if (field3 !== undefined) { newPlant[field1][field2][field3] = val; } else if (field2 !== undefined) { newPlant[field1][field2] = val; } else { newPlant[field1] = val; } props.onChange(newPlant); }; const onCandidateLocationsTemplate = () => { generateFile( "Candidate locations - Template.csv", csvFormat([ { name: "Washakie County", "latitude (deg)": "43.8356", "longitude (deg)": "-107.6602", "area cost factor": "0.88", }, { name: "Platte County", "latitude (deg)": "42.1314", "longitude (deg)": "-104.9676", "area cost factor": "1.29", }, { name: "Park County", "latitude (deg)": "44.4063", "longitude (deg)": "-109.4153", "area cost factor": "0.99", }, { name: "Goshen County", "latitude (deg)": "42.0853", "longitude (deg)": "-104.3534", "area cost factor": "1", }, ]) ); }; const onCandidateLocationsFile = (contents) => { const data = csvParse({ contents: contents, requiredCols: [ "name", "latitude (deg)", "longitude (deg)", "area cost factor", ], }); const result = {}; data.forEach((el) => { result[el["name"]] = { "latitude (deg)": el["latitude (deg)"], "longitude (deg)": el["longitude (deg)"], "area cost factor": el["area cost factor"], }; }); onChange(result, "locations"); }; const onCandidateLocationsDownload = () => { const result = []; for (const [locationName, locationDict] of Object.entries( props.value["locations"] )) { result.push({ name: locationName, "latitude (deg)": locationDict["latitude (deg)"], "longitude (deg)": locationDict["longitude (deg)"], "area cost factor": locationDict["area cost factor"], }); } generateFile(`Candidate locations - ${props.name}.csv`, csvFormat(result)); }; const onCandidateLocationsClear = () => { onChange({}, "locations"); }; let description = "No locations set"; const nCenters = Object.keys(props.value["locations"]).length; if (nCenters > 0) description = `${nCenters} locations`; const shouldDisableMaxCap = props.value["minimum capacity (tonne)"] === props.value["maximum capacity (tonne)"]; return ( <>

General information

Inputs & Outputs

onChange(v, "outputs (tonne/tonne)")} disableKeys={true} validate="float" />

Capacity & Costs

onChange(v, "minimum capacity (tonne)")} validate="float" /> onChange(v, "opening cost (min capacity) ($)")} validate="float" /> onChange(v, "fixed operating cost (min capacity) ($)") } validate="float" /> onChange(v, "maximum capacity (tonne)")} validate="float" /> onChange(v, "opening cost (max capacity) ($)")} validate="float" disabled={shouldDisableMaxCap} /> onChange(v, "fixed operating cost (max capacity) ($)") } validate="float" disabled={shouldDisableMaxCap} /> onChange(v, "variable operating cost ($/tonne)")} validate="float" /> onChange(v, "energy (GJ/tonne)")} validate="float" />

Storage

onChange(v, "storage", "cost ($/tonne)")} validate="float" /> onChange(v, "storage", "limit (tonne)")} validate="float" />

Disposal

onChange(v, "disposal cost ($/tonne)")} disableKeys={true} validate="float" /> onChange(v, "disposal limit (tonne)")} disableKeys={true} valuePlaceholder="Unlimited" validate="float" />

Emissions

onChange(v, "emissions (tonne/tonne)")} keyPlaceholder="Emission name" valuePlaceholder="0" validate="float" />
); }; export default PlantBlock;