CenterForTheBuiltEnvironment / comfort-dash

Revision of the CBE Comfort Tool using Dash.
0 stars 12 forks source link

listen to changes in the variables inputs #26

Closed Jinjia-Bai closed 1 week ago

Jinjia-Bai commented 1 week ago

back-end development

Description

In this version, we have the very clear examples that we can add more comfort models from pythermalcomfort. In order to integrate all models so that the model can obtain results by inputting different values ​​and output them on the page, I focused on listening changes in input values. In this process, I also solve other todos.

Types of change

Implementation

Here I add PHS in the page image And It also can output the result successfully

Then I want to dynamically listen the changes in variable inputs, so I changed the id assigned when entering parameters from static to dynamic, so that ALL can be used to achieve this goal. image Because dynamic input is used, there is no need to listen whether the form is clicked and capture the input values from the form. At the same time, the id="test-form" can also be removed from the form in input_environmental_personal.py image Because the value captured from dynamic input is a list instead of a dict, it needs to be processed into a dict before calling the display_results function. image In show_results.py I moved the find_dict_with_key_value function out of the display_results function. The input parameters of the model calculation function want to use the key instead of the position of the list to retrieve the value of each parameter, so I changed the original list to a dict. The code for retrieving the value of each parameter in the model calculation function is as shown in the figure below. But when I use find_dict_with_key_value to find the key in form_content, I can't find the corresponding value. However, I can find the corresponding values by directly using form_content.get(). Therefore, I want to know is whether the find_dict_with_key_value function still needs to be retained and must use it to get the value. image I also modified the value range and default values ​​of the parameters of these models according to the description of the model in pythermalcomfort, so that errors will not occur due to input.

The following two pictures show that I changed the input value of the Metabolic Rate parameter after selecting the PHS model, and its output results also changed accordingly. So now we can successfully listen input changes and output the results. image image

Checklists

Jinjia-Bai commented 1 week ago

After I created this pull request, upstream/main updated the code to add features such as ploting charts. So I tried to merge the code and continue to complete work of listen to input changes, but it seemed that the code conflict was not resolved, resulting in some errors. It might take me some time to figure it out. I have now rolled back the code of this branch to the version when this pull request was created. If there is progress in work on another branch, I will cherry-pick the commit to this branch.

Jinjia-Bai commented 1 week ago

Now I think I have resolved the code conflict and made the feature of updating chart listen for input changes as well. But because I only wrote the result output of PHS and did not write the code to support ploting chart, there will be an error on the PHS page. Maybe you can delete the PHS part I wrote when merging the code.