-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creates Transition Risk Score
at product level and company level
#152
Conversation
@AnneSchoenauer @Tilmon You can see the complete sample outputs of transition risk score at product and company level through these files: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kalashsinghal
Here are my comments. I focused on superficial things for now. The concepts that this function implements are best captured in tests and discussed with Anne/Tilman.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM,
Thanks @kalashsinghal.
Maybe discuss with @AnneSchoenauer the more conceptual aspects of this PR, e.g. reviewing the documentation of the new exported function is complete and clear, and that the tests capture the behaviour sufficiently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kalashsinghal, Could you please create also some tests that test the averaging functions? Please see my comment above that the average score, the average reduction targets and the average profile ranking should be calcualted regardless of the benchmark_score grouping. I asked Chat GPT what could be nice ways of testing if the averages are correct. Here is what it said. I really like this. Also do we need tests for the correct input data that we need? Or tests for merging? Thanks a lot for your work on this!
Chat GPT:
For the Transition Risk Score Calculation
verification, we can design a series of test cases that specifically target the calculation logic of the score_transition_risk
function. Below, I provide concrete examples for each scenario mentioned.
Test Setup
Before we dive into the specific tests, let's establish a base setup that these tests might follow. The setup involves creating mock data that mimics the structure expected by the score_transition_risk
function, including emissions profile and sector profile at the product level.
1. All Input Data Available and Correctly Formatted
Objective: Ensure the function correctly calculates transition risk scores when all required data is present and correctly formatted.
Test Steps:
- Create mock emissions and sector profiles with known values where the calculation of the transition risk score is straightforward (e.g.,
profile_ranking
andreduction_targets
values that result in simple averages). - Call
score_transition_risk
with these profiles. - Assert that the calculated
transition_risk_score
matches expected values calculated manually.
Example Mock Data:
- Emissions Profile:
profile_ranking
of 70 for all products. - Sector Profile:
reduction_targets
of 30 for all products.
Expected Outcome:
- The
transition_risk_score
should be(70 + 30) / 2 = 50
for all products.
2. Missing or Incomplete Data for Some Products or Companies
Objective: Test how the function handles scenarios where some data points (e.g., reduction_targets
or profile_ranking
) are missing.
Test Steps:
- Create mock data where some products have
NULL
orNA
for eitherprofile_ranking
orreduction_targets
. - Call
score_transition_risk
with this data. - Verify that the function handles these cases gracefully, either by excluding these products from the score calculation or by appropriately calculating scores with available data.
Expected Outcome:
- Products with complete data are scored correctly.
- Products with missing data are handled as per the function's design (e.g., scores set to
NA
or calculated using available data).
3. Edge Cases Where the Input Data Might Lead to Division by Zero or Other Mathematical Errors
Objective: Ensure the function is robust against edge cases that could result in mathematical errors, such as division by zero.
Test Steps:
- Create mock data where
profile_ranking
andreduction_targets
could lead to situations that typically result in mathematical errors (e.g., both are zero, leading to a potential division by zero in some calculation approaches). - Execute
score_transition_risk
with this dataset. - Confirm that the function either avoids these errors through checks and balances or handles them elegantly (e.g., setting scores to a default value or NA).
Expected Outcome:
- The function completes execution without errors.
- Products with problematic data are handled in a predefined manner, ensuring the integrity of the scoring process.
Implementing the Tests
These tests can be implemented using a testing framework appropriate for your development environment (e.g., testthat
for R). For each test, you would craft the specific mock data sets, run the score_transition_risk
function, and then assert that the outcomes match your expectations. This approach ensures that the function behaves correctly across a wide range of scenarios, enhancing the reliability and accuracy of your transition risk scoring methodology.
@AnneSchoenauer I have removed averaging of Regarding tests suggestions from Chat GPT:
Tests Added
Tests added
This objective is not applicable for |
Okay thanks for your comments - make sense! Is this also the case when there are only NAs so let’s assume that we couldn’t match any ep_product to the Ecoinvent product would the code behave properly? |
And one last comment! I noticed that the philo… company has two products but they are matched with the same Ecoinvent activity for this it is a bit hard to check if the average on company level is taken correctly. Could you just provide another example with a company with different products and so with different sector reduction targets and profile ranking? Does the code also behave well if from 5 products 2 have distinct sector reductions and profile ranking, 1 product was not being able to match with reduction_targets and 1 product doesn’t have a profile_ranking and 1 product was not able to be matched with Ecoinvent and doesn’t have a reduction target? Just to check again if also some „edge cases“ or more complicated cases will work. |
@AnneSchoenauer In the sample data we have, there is not even a single company which has more than 2 products, hence to test the edge cases you suggested I formulated a test. Please have a look at it and let me know if it covers every case! Please note that I am joining the sector and profile dataframes using columns
|
Yes the code will behave properly, I have added a test for this
I have tried to catch this case using the added test. Please review! |
Great @kalashsinghal approved :) Good work :) |
closes #149
closes #151
Dear @maurolepore @AnneSchoenauer
This PR creates the Transition Risk Score at product and company levels. Here is the reprex of the outputs:
Created on 2024-02-13 with reprex v2.0.2
cc' @Tilmon
TODO
EXCEPTIONS