Repository: equinor/acidwatch
Pull request #336: Fix input concentration max ppm to 1000000
Author: login: UsamaEquinorAFK
Created: 2025-05-27T10:57:31Z | Merged: 2025-05-27T12:54:15Z

Closes #329 329

Linked issue #329: ppm cannot be larger than 1 million (by definition)

Diff:
diff --git a/backend/src/acidwatch_api/models/model_config.py b/backend/src/acidwatch_api/models/model_config.py
index 634356fe..ce54b9a1 100644
--- a/backend/src/acidwatch_api/models/model_config.py
+++ b/backend/src/acidwatch_api/models/model_config.py
@@ -1,45 +1,72 @@
 def get_model_config():
+    # Common input concentration properties
+    common_input_properties = {
+        "meta": "ppm",
+        "max": 1000000,
+        "type": "float",
+        "input_type": "textbox",
+    }
+
+    # Default values for co2spec
+    co2spec_defaults = {
+        "O2": 30,
+        "H2O": 30,
+        "H2S": 0,
+        "SO2": 10,
+        "NO2": 20,
+    }
+
+    # Default values for arcs
+    arcs_defaults = {
+        "CH2O2": 0,
+        "CH3CH2OH": 0,
+        "CO": 0,
+        "H2": 0,
+        "O2": 50,
+        "CH3COOH": 0,
+        "CH3OH": 0,
+        "CH4": 0,
+        "CH3CHO": 0,
+        "H2CO": 0,
+        "H2O": 20,
+        "H2SO4": 0,
+        "H2S": 30,
+        "S8": 0,
+        "SO2": 10,
+        "H2SO3": 0,
+        "HNO3": 0,
+        "NO2": 50,
+        "NH3": 0,
+        "HNO2": 0,
+        "NO": 0,
+        "N2": 0,
+        "NOHSO4": 0,
+    }
+
+    # Create input concentrations using dictionary comprehension
+    co2spec_input_concentrations = {
+        compound: {
+            **common_input_properties,
+            "defaultvalue": default_value,
+            "enabled": True,
+        }
+        for compound, default_value in co2spec_defaults.items()
+    }
+
+    arcs_input_concentrations = {
+        compound: {
+            **common_input_properties,
+            "defaultvalue": default_value,
+            "enabled": compound in ["O2", "H2O", "H2S", "SO2", "NO2"],
+        }
+        for compound, default_value in arcs_defaults.items()
+    }
+
     return {
         "co2spec": {
             "formconfig": {
                 "settings": {},
-                "inputConcentrations": {
-                    "H2O": {
-                        "defaultvalue": 30,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "O2": {
-                        "defaultvalue": 30,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "SO2": {
-                        "defaultvalue": 10,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "NO2": {
-                        "defaultvalue": 20,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "H2S": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                },
+                "inputConcentrations": co2spec_input_concentrations,
             }
         },
         "arcs": {
@@ -72,169 +99,7 @@ def get_model_config():
                         "min": 1,
                     },
                 },
-                "inputConcentrations": {
-                    "CH2O2": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "CH3CH2OH": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "CO": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "H2": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "O2": {
-                        "defaultvalue": 50,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "CH3COOH": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "CH3OH": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "CH4": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "CH3CHO": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "H2CO": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "H2O": {
-                        "defaultvalue": 20,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "H2SO4": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "H2S": {
-                        "defaultvalue": 30,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "S8": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "SO2": {
-                        "defaultvalue": 10,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "H2SO3": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "HNO3": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "NO2": {
-                        "defaultvalue": 50,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": True,
-                    },
-                    "NH3": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "HNO2": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "NO": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "N2": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                    "NOHSO4": {
-                        "defaultvalue": 0,
-                        "meta": "ppm",
-                        "type": "float",
-                        "input_type": "textbox",
-                        "enabled": False,
-                    },
-                },
+                "inputConcentrations": arcs_input_concentrations,
             }
         },
     }
diff --git a/frontend/src/pages/InputForm.tsx b/frontend/src/pages/InputForm.tsx
index 352621a8..ba9aa188 100644
--- a/frontend/src/pages/InputForm.tsx
+++ b/frontend/src/pages/InputForm.tsx
@@ -121,6 +121,7 @@ const InputForm: React.FC = () => {
                                         style={{ paddingTop: "5px" }}
                                         step="any"
                                         name={key}
+                                        max={inputconc.max}
                                         meta={inputconc.meta}
                                         placeholder={"0"}
                                         value={inputconc.defaultvalue === 0 ? "" : inputconc.defaultvalue}


Reviews:
user: login: lars-petter-hauge
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-27T11:09:39Z
user: login: UsamaEquinorAFK
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-27T11:11:00Z
user: login: lars-petter-hauge
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-27T11:11:38Z
user: login: UsamaEquinorAFK
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-27T11:11:56Z
user: login: lars-petter-hauge
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-27T11:15:33Z
user: login: lars-petter-hauge
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-27T11:18:45Z
user: login: pinkwah
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-05-27T12:43:03Z

Review comments:
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: lars-petter-hauge
body: close to 200 lines of copy paste here..

Could be something along:

```python
{
    comp: {
        "defaultvalue": 0,
        "meta": "ppm",
        "max": 1000000,
        "type": "float",
        "input_type": "textbox",
        "enabled": False,
    }
    for comp in ["CH202", ...]
}
```

What do you think?
created_at: 2025-05-27T11:09:39Z
author_association: COLLABORATOR
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: UsamaEquinorAFK
body: 20*
But yes I agree 
created_at: 2025-05-27T11:11:00Z
author_association: CONTRIBUTOR
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: lars-petter-hauge
body: I see some variations in default value, those could be separated:

```python
DEFAULT_VALUES = {"H2O": 0, ...}

{
    comp: {
        "defaultvalue": DEFAULT_VALUES.get(comp, 0),
        "meta": "ppm",
        "max": 1000000,
        "type": "float",
        "input_type": "textbox",
        "enabled": False,
    }
    for comp in ["CH202", ...]
}
```
created_at: 2025-05-27T11:11:37Z
author_association: COLLABORATOR
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: UsamaEquinorAFK
body: Ah now I understand yes it can be 200 :D 
created_at: 2025-05-27T11:11:56Z
author_association: CONTRIBUTOR
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: lars-petter-hauge
body: Could even do:

```python
COMP_SPECIFIC_ATTRS = {"H2O": {"defaultvalue": 20, "enabled": True}, ...}

{
    comp: {
        "defaultvalue": 0,
        "meta": "ppm",
        "max": 1000000,
        "type": "float",
        "input_type": "textbox",
        "enabled": False,
    }.update(COMP_SPECIFIC_ATTRS.get(comp,{}))
    for comp in ["CH202", ...]
}
```
I think the latter works, haven't actually tested it..
created_at: 2025-05-27T11:15:32Z
author_association: COLLABORATOR
diff_hunk: @@ -76,160 +81,183 @@ def get_model_config():
                     "CH2O2": {
                         "defaultvalue": 0,
                         "meta": "ppm",
+                        "max": 1000000,
                         "type": "float",
                         "input_type": "textbox",
                         "enabled": False,
                     },
path: backend/src/acidwatch_api/models/model_config.py
user: login: lars-petter-hauge
body: > Ah now I understand yes it can be 200 :D

Yeah, it was more of current state than what you added :) I always like to improve on what exists as well, so it'll be better till next time :) 
created_at: 2025-05-27T11:18:45Z
author_association: COLLABORATOR

PR comments:
user: login: UsamaEquinorAFK
created_at: 2025-05-27T11:01:07Z
body: ![Image 27-05-2025 at 12 55](https://github.com/user-attachments/assets/cc350a59-3d99-4852-b647-a8eec6eaaa57)

author_association: CONTRIBUTOR
user: login: lars-petter-hauge
created_at: 2025-05-27T11:16:33Z
body: Nice work getting these things fixed :) 
author_association: COLLABORATOR
user: login: UsamaEquinorAFK
created_at: 2025-05-27T11:52:42Z
body: Refactored according to above comments
author_association: CONTRIBUTOR
user: login: UsamaEquinorAFK
created_at: 2025-05-27T12:54:08Z
body: Closes #334 as well :) 
author_association: CONTRIBUTOR