Skip to content

Commit fa02912

Browse files
feat: separate last comment/other comment
1 parent fa4fa87 commit fa02912

11 files changed

+63
-45
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ importFrom(cli,cli_alert_danger)
2525
importFrom(cli,cli_alert_info)
2626
importFrom(cli,cli_rule)
2727
importFrom(digest,digest)
28+
importFrom(dplyr,arrange)
29+
importFrom(dplyr,desc)
2830
importFrom(dplyr,distinct)
2931
importFrom(dplyr,filter)
3032
importFrom(dplyr,full_join)

R/app_server.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ app_server <- function(input, output, session) {
9393
date_p = as.Date(info$chene$planting_date),
9494
der_truf = info$truffes$derniere_truffe,
9595
tot_weight = info$truffes$weight_tot,
96-
comments = info$truffes$comments
96+
last_comment = info$truffes$last_comment,
97+
other_comments = info$truffes$other_comments
9798
)
9899
)
99100
}

R/check_param.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ check_names_dataframe <- function(names, df) {
2323

2424
#' formater_comment
2525
#' @noRd
26-
formater_comment <- function(comment) {
27-
c <- paste0(comment, " : ")
26+
formater_comment <- function(date_found, comment) {
27+
c <- paste(date_found, comment, sep = " : ")
2828
return(c)
2929
}

R/get_info_chene_truffe.R

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @return A list containing information about truffles associated with the oak tree,
1212
#' including the total weight, date of the last truffle found, and any comments.
1313
#'
14-
#' @importFrom dplyr filter summarise pull
14+
#' @importFrom dplyr filter summarise pull arrange desc
1515
#' @export
1616
#'
1717
#' @examples
@@ -24,42 +24,48 @@
2424
#' get_info_chene_truffe(dbtruffe = truffe, theidoak = "119")
2525
#' DBI::dbDisconnect(conn)
2626
get_info_chene_truffe <- function(dbtruffe, theidoak) {
27-
check_param(dbtruffe, "data.frame")
28-
check_param(theidoak, "character")
29-
check_names_dataframe(c("idoak", "weight", "date_found", "comment"), dbtruffe)
27+
check_param(dbtruffe, "data.frame")
28+
check_param(theidoak, "character")
29+
check_names_dataframe(c(
30+
"idoak", "weight", "date_found",
31+
"comment"
32+
), dbtruffe)
33+
truffe_chene <- filter(dbtruffe, idoak == theidoak)
34+
if (nrow(truffe_chene) == 0) {
35+
return(list(weight_tot = 0, derniere_truffe = "-", last_comment = "-", other_comments = "-"))
36+
}
3037

31-
truffe_chene <- dbtruffe |>
32-
filter(idoak == theidoak)
3338

34-
if (nrow(truffe_chene) == 0) {
35-
return(list(
36-
weight_tot = 0,
37-
derniere_truffe = "-",
38-
comments = "-"
39-
))
40-
}
39+
weight_tot <- pull(summarise(truffe_chene, weight_tot = sum(weight,
40+
na.rm = TRUE
41+
)), weight_tot)
42+
derniere_truffe <- pull(summarise(truffe_chene, date_found = as.Date(max(date_found,
43+
na.rm = TRUE
44+
))), date_found)
4145

42-
weight_tot <- truffe_chene |>
43-
summarise(weight_tot = sum(weight, na.rm = TRUE)) |>
44-
pull(weight_tot)
46+
sort_comment <- truffe_chene |>
47+
arrange(desc(date_found))
4548

46-
derniere_truffe <- truffe_chene |>
47-
summarise(date_found = as.Date(max(date_found, na.rm = TRUE))) |>
48-
pull(date_found)
49-
50-
comments <-
51-
paste(
52-
paste(
53-
as.Date(truffe_chene$date_found),
54-
truffe_chene$comment,
49+
last_comment <- paste(as.Date(sort_comment$date_found[1]),
50+
sort_comment$comment[1],
5551
sep = " : "
56-
),
57-
collapse = "<br>"
5852
)
5953

60-
return(list(
61-
weight_tot = weight_tot,
62-
derniere_truffe = derniere_truffe,
63-
comments = comments
64-
))
65-
}
54+
if (nrow(sort_comment) > 1) {
55+
other_comments <- paste(paste(as.Date(sort_comment$date_found[-1]),
56+
sort_comment$comment[-1],
57+
sep = " : "
58+
), collapse = "<br>")
59+
} else {
60+
other_comments <- "-"
61+
}
62+
63+
64+
65+
return(list(
66+
weight_tot = weight_tot,
67+
derniere_truffe = derniere_truffe,
68+
last_comment = last_comment,
69+
other_comments = other_comments
70+
))
71+
}

R/update_db_truffe.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#' comment = "It's good!"
4444
#' )
4545
update_db_truffe <- function(conn, idtruffle, idoak, date_found, weight, comment, estimation) {
46-
comment <- formater_comment(comment)
46+
comment <- formater_comment(date_found, comment)
4747

4848
# Build and execute the SQL query to update the line
4949

R/write_db_new_truffe.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ write_db_new_truffe <-
2828
date_found = as.character(date_found),
2929
weight = weight,
3030
estimation = estimation,
31-
comment = formater_comment(comment)
31+
comment = formater_comment(date_found, comment)
3232
)
3333

3434
dbAppendTable(conn, "truffe", add_truffe)

inst/app/www/template_identity_card.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
<hr> <b>Dernier Réensemencement : </b> {{date_reens}}
55
<hr> <b>Dernière truffe : </b> {{der_truf}}
66
<hr> <b>Poids total trouvé : </b> {{tot_weight}} g
7-
<hr> <b>Commentaires : </b> {{comments}}
7+
<hr> <b>Dernier Commentaire : </b> {{last_comment}}
8+
<hr>
9+
<details>
10+
<summary><b>Autres Commentaires :</b></summary>
11+
{{other_comments}}
12+
</details>

tests/testthat/test-get_info.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ test_that("get_info works", {
3939
truffes = list(
4040
weight_tot = 0,
4141
derniere_truffe = "-",
42-
comments = "-"
42+
last_comment = "-",
43+
other_comments = "-"
4344
),
4445
reensemence = "2021-06-20"
4546
)
@@ -56,7 +57,8 @@ test_that("get_info works", {
5657
truffes = list(
5758
weight_tot = 125,
5859
derniere_truffe = structure(19844, class = "Date"),
59-
comments = "2024-04-01 : Small truffle<br>2024-05-01 : Medium truffle"
60+
last_comment = "2024-05-01 : Medium truffle",
61+
other_comments = "2024-04-01 : Small truffle"
6062
),
6163
reensemence = "-"
6264
)

tests/testthat/test-get_info_chene_truffe.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ test_that("get_info_chene_truffe works", {
2525
list(
2626
weight_tot = 0,
2727
derniere_truffe = "-",
28-
comments = "-"
28+
last_comment = "-",
29+
other_comments = "-"
2930
)
3031
)
3132

@@ -34,7 +35,8 @@ test_that("get_info_chene_truffe works", {
3435
list(
3536
weight_tot = 125,
3637
derniere_truffe = as.Date("2024-05-01"),
37-
comments = "2024-04-01 : Truffe petite<br>2024-05-01 : Truffe moyenne"
38+
last_comment = "2024-05-01 : Truffe moyenne",
39+
other_comments = "2024-04-01 : Truffe petite"
3840
)
3941

4042
expect_equal(get_info_chene_truffe(dbtruffe, "3"), expected_output)

tests/testthat/test-update_db_truffe.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_that("update_db_truffe works", {
3636
date_found = 18294,
3737
weight = 22,
3838
estimation = 0,
39-
comment = formater_comment("New comment")
39+
comment = formater_comment("18294", "New comment")
4040
)
4141
expect_equal(
4242
DBI::dbReadTable(conn, "truffe") |>

0 commit comments

Comments
 (0)