Skip to content

Commit

Permalink
Merge pull request #9 from NorwegianVeterinaryInstitute/feat-sushi-calc
Browse files Browse the repository at this point in the history
Feat sushi calc
  • Loading branch information
novica authored Oct 17, 2024
2 parents eb2d013 + 2a52398 commit bed73ff
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 75 deletions.
24 changes: 17 additions & 7 deletions R/fct_calculate_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ calc_mini_table_3_4 <- function(prod_temp = 4,
)


ref_growth_2 <- ref_growth * (10 + 1.5) ^ 2 / (10 + 1.5) ^ 2
ref_growth_2 <- 0.007343 * (10 + 1.5) ^ 2 / (10 + 1.5) ^ 2
ref_temp_2 <- 10
ref_hours_2 <- 3

Expand All @@ -138,10 +138,11 @@ calc_mini_table_3_4 <- function(prod_temp = 4,
row_5 <- c(
reference = ref_growth_2 * ref_hours_2,
likely = likely_growth_2 * salmon_hours,
min = 0.9 * likely_growth * salmon_hours,
max = 1.1 * likely_growth * salmon_hours
min = 0.9 * likely_growth_2 * salmon_hours,
max = 1.1 * likely_growth_2 * salmon_hours
)


return(list(home = row_4, salmon = row_5))

}
Expand Down Expand Up @@ -174,7 +175,8 @@ calc_mini_table_3_4 <- function(prod_temp = 4,
calc_mini_table_5_6 <- function(sushi_temp = 4,
sushi_hours = 12,
period_temp = 22,
period_hours = 6) {
period_hours = 6,
sushi_pctg = 20) {

ref_growth <- 0.00286
ref_temp <- 4
Expand All @@ -198,7 +200,13 @@ calc_mini_table_5_6 <- function(sushi_temp = 4,
max = 1.1 * likely_growth_2 * period_hours
)

return(list(sushi = row_6, period = row_7))
# here we use salmon % to decrease the value of row_6

sushi_log <- log10(sushi_pctg/100)

row_6_sushi <- row_6 + sushi_log

return(list(sushi = row_6_sushi, period = row_7))

}

Expand Down Expand Up @@ -227,7 +235,8 @@ calc_wrapper <- function(prod_temp = 4,
sushi_hours = 12,
period_temp = 22,
period_hours = 6,
initial_conc = 1) {
initial_conc = 1,
sushi_pctg = 20) {
dat_1 <- calc_mini_table_1(
prod_temp = prod_temp,
prod_days = prod_days,
Expand All @@ -248,7 +257,8 @@ calc_wrapper <- function(prod_temp = 4,
sushi_temp = sushi_temp,
sushi_hours = sushi_hours,
period_temp = period_temp,
period_hours = period_hours
period_hours = period_hours,
sushi_pctg = sushi_pctg
)
dat <- data.frame(rbind(
t(data.frame(dat_1)),
Expand Down
31 changes: 16 additions & 15 deletions R/fct_listeria_calculator.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,28 @@ calc_plot_wrapper <- function(prod_temp,
period_temp,
period_hours,
initial_conc,
sushi_pctg,
lang) {

dat <- calc_wrapper(
prod_temp,
prod_days,
store_temp,
store_days,
home_temp,
home_hours,
salmon_temp,
salmon_hours,
sushi_temp,
sushi_hours,
period_temp,
period_hours,
initial_conc
prod_temp = prod_temp,
prod_days = prod_days,
store_temp = store_temp,
store_days = store_days,
home_temp = home_temp,
home_hours = home_hours,
salmon_temp = salmon_temp,
salmon_hours = salmon_hours,
sushi_temp = sushi_temp,
sushi_hours = sushi_hours,
period_temp = period_temp,
period_hours = period_hours,
initial_conc = initial_conc,
sushi_pctg = sushi_pctg
)

dat_long <- translate_and_pivot(dat, lang)
p <- make_plot(dat = dat_long)

return(p)
}

}
17 changes: 12 additions & 5 deletions R/mod_listeria_calculator.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,15 @@ mod_listeria_calculator_server <- function(id, selected_language){
selected = 1,
inline = TRUE,
width = "100%"
))



)),
shiny::div(class="text-center",
shiny::sliderInput(
ns("sushi_pctg"),
label = "Percentage of salmon in sushi",
min = 0,
max = 100,
value = 20,
ticks = TRUE))
)

})
Expand Down Expand Up @@ -218,7 +223,8 @@ mod_listeria_calculator_server <- function(id, selected_language){
"sushi_hours",
"period_temp",
"period_hours",
"initial_conc"), function(x) {req(input[[x]])})
"initial_conc",
"sushi_pctg"), function(x) {req(input[[x]])})
calc_plot_wrapper(
prod_temp = input$prod_temp,
prod_days = input$prod_days,
Expand All @@ -233,6 +239,7 @@ mod_listeria_calculator_server <- function(id, selected_language){
period_temp = input$period_temp,
period_hours = input$period_hours,
initial_conc = input$initial_conc,
sushi_pctg = input$sushi_pctg,
lang = i18n()$get_translation_language()
)
}
Expand Down
50 changes: 25 additions & 25 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# Listeria Calculator

<!-- badges: start -->
<!-- badges: end -->

This calculator illustrates the storage conditions of salmon that result in higher concentrations than 100 Listeria monocytogenes per gram of sushi.

Enter time and temperature data for the steps from slaughter to finished sushi that you have an overview of, and see how big an effect small and large deviations correspond to. On the steps you do not have an overview of, start with the data we have set up in the reference case.

The calculator is not a substitute for other requirements in the regulations, only a supplement.
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# Listeria Calculator

<!-- badges: start -->
<!-- badges: end -->

This calculator illustrates the storage conditions of salmon that result in higher concentrations than 100 Listeria monocytogenes per gram of sushi.

Enter time and temperature data for the steps from slaughter to finished sushi that you have an overview of, and see how big an effect small and large deviations correspond to. On the steps you do not have an overview of, start with the data we have set up in the reference case.

The calculator is not a substitute for other requirements in the regulations, only a supplement.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# Listeria Calculator

<!-- badges: start -->
<!-- badges: end -->

This calculator illustrates the storage conditions of salmon that result
in higher concentrations than 100 Listeria monocytogenes per gram of
sushi.

Enter time and temperature data for the steps from slaughter to finished
sushi that you have an overview of, and see how big an effect small and
large deviations correspond to. On the steps you do not have an overview
of, start with the data we have set up in the reference case.

The calculator is not a substitute for other requirements in the
regulations, only a supplement.

<!-- README.md is generated from README.Rmd. Please edit that file -->

# Listeria Calculator

<!-- badges: start -->
<!-- badges: end -->

This calculator illustrates the storage conditions of salmon that result
in higher concentrations than 100 Listeria monocytogenes per gram of
sushi.

Enter time and temperature data for the steps from slaughter to finished
sushi that you have an overview of, and see how big an effect small and
large deviations correspond to. On the steps you do not have an overview
of, start with the data we have set up in the reference case.

The calculator is not a substitute for other requirements in the
regulations, only a supplement.
30 changes: 28 additions & 2 deletions inst/app/www/home.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
### This is what the calculator does

This calculator illustrates the storage conditions of salmon that result in higher concentrations than 100 Listeria monocytogenes per gram of sushi.

Enter time and temperature data for the steps from slaughter to finished sushi that you have an overview of, and see how big an effect small and large deviations correspond to. On the steps you do not have an overview of, start with the data we have set up in the reference case.
On the tab __Calculator__ you can enter time and temperature data for the steps from slaughter to finished sushi that you have an overview of, and see how big an effect small and large deviations correspond to.

The calculator is not a substitute for other requirements in the regulations, only a supplement.

Do you want to understand how the calculator is built? See background data for the calculations.
### The Reference Case

The starting data in the calculator are a reference scenario that is also presented in the figure. This scenario reflects an example of reasonably foreseeable conditions of storage in the different steps from the fish filleting facility to the fish is brought home, stored in the refrigerator, and prepared for sushi. Sushi does in our case mean combinations of raw fish fillet and acid marinated rice.

When the initial concentration of Listeria in the fish fillet is 1 cfu/g fish, the concentration will be below 100 cfu/g when the sushi is consumed. The conditions in the reference scenario numbers for the reference criteria are given in the table below.

By comparing other scenarios with the reference scenarios, it is possible to assess which steps that cause large deviations, and where a change of time or temperature will have a positive or negative effect on the final concentration of Listeria monocytogenes.


| Location | Temperature | Period |
|----------------------------------------|--------------|----------|
| Storage in a salmon production company | 4 | 4 days |
| Time in store | 4 | 3 days |
| Transport home | 10 | 3 hours |
| Storing salmon in a refrigerator | 10 | 3 hours |
| Storing sushi in a refrigerator | 4 | 12 hours |
| Tempering period | 22 | 6 hours |

Initial concentration is set to 1, and Percentage of salmon in sushi is set to 20%.

![Reference scenario](./reference_line.png)

Please note that the reference case will remain the same in the plot also when other input numbers are inserted in the table.
### Learn more

Do you want to understand how the calculator is built? See background data on the __About__ tab for the calculations.
Binary file added inst/app/www/reference_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions inst/app/www/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
"nb": "Tempereringsperiode"},
{
"en": "Initial concetration",
"nb": "Startkonsentrasjon"}

"nb": "Startkonsentrasjon"},
{
"en": "Percentage of salmon in sushi",
"nb": "Andel laks i sushi"}
]
}

0 comments on commit bed73ff

Please sign in to comment.