Skip to content

Commit

Permalink
fixed value/indexes for infrastructure buildout overrides; the value …
Browse files Browse the repository at this point in the history
…becomes one of the indexes and the underlying value is 1
  • Loading branch information
MichaelPesce committed Jul 13, 2023
1 parent 9dfa6aa commit c609d26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
10 changes: 8 additions & 2 deletions electron/ui/src/components/OverrideTable/OverrideTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default function OverrideTable(props) {
if (!value[i].includes("-")) indexes.push(value[i])
}
override_object.indexes=indexes
override_object.value=""
if(category ==="vb_y_overview_dict") override_object.value=1
else override_object.value=""
// console.log(override_object)
let tempOverrideValues = {...scenario.override_values}
if(Object.keys(tempOverrideValues[category]).includes(""+index)) {
Expand All @@ -86,7 +87,12 @@ export default function OverrideTable(props) {
***
*/
if(inputType === "select") {
tempOverrideValues[category][idx].value = val
if(category ==="vb_y_overview_dict") {
if (tempOverrideValues[category][idx].indexes.length >=3) tempOverrideValues[category][idx].indexes[2] = (val)
else tempOverrideValues[category][idx].indexes.push(val)
} else {
tempOverrideValues[category][idx].value = val
}
const tempScenario = {...scenario}
tempScenario.override_values = tempOverrideValues
updateScenario(tempScenario)
Expand Down
28 changes: 18 additions & 10 deletions electron/ui/src/components/OverrideTable/OverrideTableRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const OVERRIDE_PRESET_VALUES = {
},
}


export default function OverrideTableRows(props) {
const {
category,
Expand Down Expand Up @@ -153,7 +152,7 @@ function BinaryVariableRow(props) {
}
const [ displayValue, setDisplayValue ] = useState()
const [ showData, setShowData ] = useState(false)
const [ overrideChecked, setOverrideChecked ] = useState(null)
const [ overrideChecked, setOverrideChecked ] = useState(false)
const [ rowName, setRowName ] = useState("")
const [ presetValues, setPresetValues ] = useState({})
const [ technology, setTechnology ] = useState(null)
Expand All @@ -169,7 +168,14 @@ function BinaryVariableRow(props) {
let preset_value_table = scenario.data_input.df_parameters[OVERRIDE_PRESET_VALUES[tempDisplayValue[0]].input_table]
let preset_values = {}
if(tempDisplayValue[0] === "Treatment Facility") {
let tempTechnology = tempDisplayValue[5]
// check for technology in override values. if found, use that. else, use the value from scenario
let tempTechnology
if (scenario.override_values[category][index] !== undefined) {
tempTechnology = scenario.override_values[category][index].indexes[1]
} else {
tempTechnology = tempDisplayValue[5]
}

let technologyNamesKey = "TreatmentCapacities"
let technologies = scenario.data_input.df_parameters[OVERRIDE_PRESET_VALUES[tempDisplayValue[0]].input_table][technologyNamesKey]
let len = technologies.length
Expand All @@ -196,12 +202,6 @@ function BinaryVariableRow(props) {
}
}


// let tempDisplayValue = [...value]
// setDisplayValue(tempDisplayValue)
// console.log('value is ')
// console.log(value)

setRowName(value[0])
setPresetValues(preset_values)
setShowData(true)
Expand All @@ -212,6 +212,12 @@ function BinaryVariableRow(props) {
else if (!Object.keys(scenario.override_values[category]).includes(""+index) && overrideChecked) setOverrideChecked(false)
}, [scenario])

const getValueSelectValue = () => {
if (scenario.override_values[category][index] !== undefined) {
if(scenario.override_values[category][index].indexes.length>=3) return scenario.override_values[category][index].indexes[2]
else return ""
} else return ""
}

const generateInfrastructureBuildoutValueOptions = (value, index) => {
if (Object.keys(OVERRIDE_PRESET_VALUES).includes(value[0])) {
Expand All @@ -229,7 +235,9 @@ function BinaryVariableRow(props) {
labelId=""
id=""
name={`${index}::select`}
value={scenario.override_values[category][index] !== undefined ? scenario.override_values[category][index].value : ""}
// value={scenario.override_values[category][index] !== undefined ? scenario.override_values[category][index].value : ""}
// value={scenario.override_values[category][index].indexes.length>=3 ? scenario.override_values[category][index][2] : ""}
value={getValueSelectValue()}
label="Value"
onChange={handleInputOverrideValue}
>
Expand Down

0 comments on commit c609d26

Please sign in to comment.