Modifications
src.brightwebapp.modifications
¶
_create_user_input_columns(df_original, df_user_input)
¶
Given two dataframes with at least the columns 'UID', 'SupplyAmount', 'BurdenIntensity',
returns a dataframe with additional columns 'SupplyAmount_USER', 'BurdenIntensity_USER'where only the user-provided values are kept. All other values in these new columns are replaced byNaN`.
For instance, given an 'original' DataFrame of the kind:
| UID | SupplyAmount | BurdenIntensity |
|---|---|---|
| 0 | 1 | 0.1 |
| 1 | 0.5 | 0.5 |
| 2 | 0.2 | 0.3 |
and a "user input" DataFrame of the kind (modified values highlighted):
| UID | SupplyAmount | BurdenIntensity |
|---|---|---|
| 0 | 1 | 0.1 |
| 1 | 0 | 0.5 |
| 2 | 0.2 | 2.1 |
the function returns a DataFrame of the kind:
| UID | SupplyAmount | SupplyAmount_USER | BurdenIntensity | BurdenIntensity_USER |
|---|---|---|---|---|
| 0 | 1 | NaN | 0.1 | NaN |
| 1 | 0.5 | 0 | 0.5 | NaN |
| 2 | 0.2 | NaN | 0.3 | 2.1 |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_original
|
DataFrame
|
Original DataFrame. |
required |
df_user_input
|
DataFrame
|
User input DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Output DataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the set of UIDs in |
Source code in src/brightwebapp/modifications.py
_determine_edited_rows(df)
¶
Given a dataframe with at least columns 'SupplyAmount_USER', 'BurdenIntensity_USER',
returns a DataFrame with a new column that indicates whether a row has been edited by the user.
For instance, given a DataFrame of the kind:
| UID | SupplyAmount_USER | BurdenIntensity_USER |
|---|---|---|
| 0 | NaN | NaN |
| 1 | 0.25 | NaN |
| 2 | NaN | 2.1 |
| 3 | NaN | NaN |
the function returns a DataFrame of the kind:
| UID | SupplyAmount_USER | BurdenIntensity_USER | Edited? |
|---|---|---|---|
| 0 | NaN | NaN | False |
| 1 | 0.25 | NaN | True |
| 2 | NaN | 2.1 | True |
| 3 | NaN | NaN | False |
Source code in src/brightwebapp/modifications.py
_update_burden_based_on_user_data(df)
¶
Updates the environmental burden of nodes by multiplying the burden intensity and the supply amount.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input dataframe. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Output dataframe. |
Source code in src/brightwebapp/modifications.py
_update_burden_intensity_based_on_user_data(df)
¶
Given a dataframe with columns 'BurdenIntensity', 'BurdenIntensity_USER',
overwrites the values in BurdenIntensity whenever values are provided in BurdenIntensity_USER.
For instance, given a DataFrame of the kind:
| UID | BurdenIntensity | BurdenIntensity_USER |
|---|---|---|
| 0 | 0.1 | NaN |
| 1 | 0.5 | 0.25 |
| 2 | 0.3 | NaN |
the function returns a DataFrame of the kind:
| UID | BurdenIntensity |
|---|---|
| 0 | 0.1 |
| 1 | 0.25 |
| 2 | 0.3 |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Output dataframe. |
Source code in src/brightwebapp/modifications.py
_update_production_based_on_user_data(df)
¶
Updates the production amount of all nodes which are upstream of a node with user-supplied production amount. If an upstream node has half the use-supplied production amount, then the production amount of all downstream node is also halved.
For instance, given a DataFrame of the kind:
| UID | SupplyAmount | SupplyAmount_USER | Branch |
|---|---|---|---|
| 0 | 1 | NaN | NaN |
| 1 | 0.5 | 0.25 | [0,1] |
| 2 | 0.2 | NaN | [0,1,2] |
| 3 | 0.1 | NaN | [0,3] |
| 4 | 0.1 | 0.18 | [0,1,2,4] |
| 5 | 0.05 | NaN | [0,1,2,4,5] |
| 6 | 0.01 | NaN | [0,1,2,4,5,6] |
the function returns a DataFrame of the kind:
| UID | SupplyAmount | Branch | Updated? |
|---|---|---|---|
| 0 | 1 | NaN | False |
| 1 | 0.25 | [0,1] | False |
| 2 | 0.2 * (0.25/0.5) | [0,1,2] | True |
| 3 | 0.1 | [0,3] | False |
| 4 | 0.18 | [0,1,2,4] | False |
| 5 | 0.05 * (0.18/0.1) | [0,1,2,4,5] | True |
| 6 | 0.01 * (0.18/0.1) | [0,1,2,4,5,6] | True |
Notes
As we can see, the function updates production only for those nodes upstream of a node with 'production_user':
- Node 2 is upstream of node 1, which has a 'production_user' value.
- Node 3 is NOT upstream of node 1. It is upstream of node 0, but node 0 does not have a 'production_user' value.
As we can see, the function always takes the "most recent" 'production_user' value upstream of a node:
- Node 5 is upstream of node 4, which has a 'production_user' value.
- Node 4 is upstream of node 1, which also has a 'production_user' value.
In this case, the function takes the 'production_user' value of node 4, not of node 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. Must have the columns 'production', 'production_user' and 'branch'. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Output DataFrame. |
Source code in src/brightwebapp/modifications.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |