esqLABS / esqlabsR

Utility functions for modelling and simulation workflows within esqLABS organization
https://esqlabs.github.io/esqlabsR/
GNU General Public License v2.0
16 stars 2 forks source link

Validation object & individual modification validation #710

Open AKostiv8 opened 2 weeks ago

AKostiv8 commented 2 weeks ago

 devtools::load_all()
#ℹ Loading esqlabsR

# Create a project
p <- testProject()

# Check available individuals in configuration
p$configurations$individuals
# $Indiv1
# • Individual ID: Indiv1
# • Characteristics:
#   • Specy: Human
# • Population: European_ICRP_2002
# • Gender: MALE
# • Weight: 73
# • Height: 176
# • Age: 30
# • Protein: NA
# • Ontogeny: NA
# • Parameters:
#   • GFR

# Modify to non declared individual
 p$configurations$scenarios$TestScenario$individual <- "Non-declared individual"

# Run validation
p$validate()
# ℹ Warnings:
#   ! Scenario: TestScenario - The individual 'Non-declared individual' does not exist in the individuals configuration for scenario 'TestScenario'

# Modify `TestScenario2` and add one more unknown individual
 p$configurations$scenarios$TestScenario2$individual <- "Non-declared individual 2"
# Run validation
p$validate()
# ℹ Warnings:
#   ! Scenario: TestScenario - The individual 'Non-declared individual' does not exist in the individuals configuration for scenario 'TestScenario'
#   ! Scenario: TestScenario2 - The individual 'Non-declared individual 2' does not exist in the individuals configuration for scenario 'TestScenario2'

# Switch back to the defined individual in the `TestScenario2`
p$configurations$scenarios$TestScenario2$individual <- "Indiv1"
# Run validation
p$validate()
# ℹ Warnings:
#   ! Scenario: TestScenario - The individual 'Non-declared individual' does not exist in the individuals configuration for scenario 'TestScenario'

# Get validation object with the warnings 
p$get_warning_manager()$get_warnings()
# $TestScenario
# $TestScenario$INDIVIDUAL_NOT_FOUND
# [1] "The individual 'Non-declared individual' does not exist in the individuals configuration for scenario 'TestScenario'"
Felixmil commented 1 week ago

This is going in the right direction ! I think it would be better to provide feedback directly when a value is modified, for example:

p$configurations$scenarios$TestScenario$individual <- "Non-declared individual"

#   ! Scenario: TestScenario - The individual 'Non-declared individual' does not exist in the individuals configuration for scenario 'TestScenario'

Nice to be able to list all ongoing problems on the projects with p$validate() but I think status would be a better name for users. So I would define a status active field that returns what validate() print.

Also, I feel like Scenario validation should happen within each ScenarioConfiguration object and thus defined in ScenariosConfiguration.R. As Scenarios object have the whole project passed during their initialization, you can still compare with other configurations.

To summarise, here are new requirements:

AKostiv8 commented 7 minutes ago

devtools::load_all()
#ℹ Loading esqlabsR

# Create a project
p <- testProject()

# Modify to existing one individual
p$configurations$scenarios$TestScenario$individual <- "Indiv1"
# ✔ No warnings found.

# Modify to non-existing one individual
 p$configurations$scenarios$TestScenario$individual <- "Indiv3"
# ℹ Warnings:
# ! Scenario: TestScenario - The individual 'Indiv3' does not exist in the individuals configuration.

# Add non-existing one model 
p$configurations$scenarios$TestScenario$model <- "Blabla.pkml"
# ℹ Warnings:
# ! Scenario: TestScenario - The individual 'Indiv3' does not exist in the individuals configuration.
# ! Scenario: TestScenario - The model 'Blabla.pkml' does not exist in the models configuration.

p$configurations$scenarios$TestScenario2$model <- "Blabla.pkml"
# ℹ Warnings:
# ! Scenario: TestScenario - The individual 'Indiv3' does not exist in the individuals configuration.
# ! Scenario: TestScenario - The model 'Blabla.pkml' does not exist in the models configuration.
# ! Scenario: TestScenario2 - The model 'Blabla.pkml' does not exist in the models configuration.

# Replace Indiv3 with Indiv1
p$configurations$scenarios$TestScenario$individual <- "Indiv1"
# ℹ Warnings:
# ! Scenario: TestScenario - The model 'Blabla.pkml' does not exist in the models configuration.
# ! Scenario: TestScenario2 - The model 'Blabla.pkml' does not exist in the models configuration.

# Check configuration status
p$status()
# ℹ Warnings:
# ! Scenario: TestScenario - The model 'Blabla.pkml' does not exist in the models configuration.
# ! Scenario: TestScenario2 - The model 'Blabla.pkml' does not exist in the models configuration.

# Get validation object with the warnings 
p$get_warning_manager()$warnings
# $TestScenario
# $TestScenario$MODEL_NOT_FOUND
# [1] "The model 'Blabla.pkml' does not exist in the models configuration."

# $TestScenario2
# $TestScenario2$MODEL_NOT_FOUND
# [1] "The model 'Blabla.pkml' does not exist in the models configuration."