Skip to content

Commit 3e6a765

Browse files
committed
Fixed some bugs
1 parent fbb636d commit 3e6a765

File tree

2 files changed

+64
-32
lines changed

2 files changed

+64
-32
lines changed

R/late.R

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ need_reviewers <- function(editor) {
129129
dplyr::count(id) |>
130130
dplyr::filter(n < 2)
131131
}
132+
132133
# Add papers ready for review
133134
papers <- report(editor = editor) |>
134135
dplyr::filter(status == "waiting (editor)") |>
@@ -140,6 +141,9 @@ need_reviewers <- function(editor) {
140141
output <- as.data.frame(dplyr::arrange(output, n))
141142
colnames(output) <- c("id", "number_reviewers")
142143

144+
# Remove papers that need decision
145+
output <- output[!(output$id %in% need_decision(editor)$id), ]
146+
143147
if (NROW(output) == 0L) {
144148
return(invisible(NULL))
145149
} else {
@@ -179,6 +183,14 @@ completed_reviews <- function(x) {
179183
#' @export
180184

181185
need_decision <- function(editor) {
186+
# Find papers with AE recommendation as last status
187+
all_articles <- get_assignments(editor, "Submissions")
188+
latest <- get_latest(all_articles)
189+
ae_recommendation <- latest[grep("^AE", latest$status), ] |>
190+
unnest(reviewers) |>
191+
dplyr::group_by(id, ae, status, date) |>
192+
dplyr::summarise(n = dplyr::n())
193+
182194
# Find existing reviewers
183195
reviewers <- get_reviewers(editor = editor)
184196
ids <- unique(reviewers$id)
@@ -190,22 +202,24 @@ need_decision <- function(editor) {
190202
reviewers <- subset(reviewers, reviewers$id %in% ids[nreviews >= 2])
191203
status <- last_reviewer_status(reviewers$comment)
192204
reviewers <- reviewers[status %in% c("Major", "Minor", "Accept", "Reject"), ]
193-
if (NROW(reviewers) == 0L) {
194-
return(invisible(NULL))
195-
} else {
205+
206+
if (NROW(reviewers) > 0L) {
196207
reviewers$date <- stringr::str_extract(
197208
reviewers$comment,
198209
"[0-9]*\\-[0-9]*\\-[0-9]*$"
199210
) |>
200211
as.Date()
201-
output <- reviewers |>
212+
reviewers <- reviewers |>
202213
dplyr::group_by(id) |>
203-
dplyr::summarise(date = max(date)) |>
214+
dplyr::summarise(date = max(date), n = dplyr::n()) |>
204215
dplyr::arrange(date)
205-
days_taken <- difftime(Sys.Date(), output$date, units = "days")
206-
output$stars <- unlist(lapply(days_taken, function(u) {
207-
str_dup("*", sum(u > deadlines("needs editor")))
208-
}))
209-
as.data.frame(output)
216+
reviewers$status <- "needs decision"
210217
}
218+
output <- as.data.frame(bind_rows(ae_recommendation, reviewers))
219+
days_taken <- difftime(Sys.Date(), output$date, units = "days")
220+
output$stars <- unlist(lapply(days_taken, function(u) {
221+
str_dup("*", sum(u > deadlines("needs editor")))
222+
}))
223+
output$ae[is.na(output$ae)] <- ""
224+
return(output)
211225
}

R/status.R

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,19 @@ status <- function(status, date = Sys.Date(), comments = "") {
6767
if (tolower(status) == tolower(guess)) {
6868
status <- guess
6969
} else {
70-
stop(status, " is not a known status. ",
71-
"Did you mean ", amatch_status(status), "?",
70+
stop(
71+
status,
72+
" is not a known status. ",
73+
"Did you mean ",
74+
amatch_status(status),
75+
"?",
7276
call. = FALSE
7377
)
7478
}
7579
}
7680

77-
structure(list(date = date, status = status, comments = comments),
81+
structure(
82+
list(date = date, status = status, comments = comments),
7883
class = "status"
7984
)
8085
}
@@ -100,7 +105,10 @@ c.status <- c.status_list <- function(..., recursive = FALSE) {
100105

101106
#' @export
102107
format.status <- function(x, ...) {
103-
paste(format(x$date), " ", x$status,
108+
paste(
109+
format(x$date),
110+
" ",
111+
x$status,
104112
if (!empty(x$comments)) paste(" [", x$comments, "]", sep = ""),
105113
sep = ""
106114
)
@@ -110,8 +118,11 @@ print.status <- function(x, ...) cat(format(x), "\n")
110118

111119
#' @importFrom utils adist
112120
amatch_status <- function(status) {
113-
ldist <- adist(status, valid_status,
114-
ignore.case = TRUE, partial = FALSE,
121+
ldist <- adist(
122+
status,
123+
valid_status,
124+
ignore.case = TRUE,
125+
partial = FALSE,
115126
costs = c(ins = 0.5, sub = 1, del = 2)
116127
)[1, ]
117128
valid_status[which.min(ldist)]
@@ -132,29 +143,37 @@ todo <- function(x) {
132143

133144
status <- last_status(x)$status
134145
status_date <- last_status(x)$date
135-
if(status == "resubmission") {
136-
# Sent back to author to fix before allocating an editor
146+
if (
147+
status %in%
148+
c(
149+
"resubmission",
150+
"reject and resubmit",
151+
"major revision",
152+
"minor revision",
153+
"accepted",
154+
"copy edited"
155+
)
156+
) {
137157
"waiting (author)"
138-
} else if (empty(x$editor) |
139-
status == "submitted" |
140-
(status == "revision received" & status_date > "2025-01-01")
141-
) {
158+
} else if (
159+
empty(x$editor) |
160+
status == "submitted" |
161+
(status == "revision received" & status_date > "2025-01-01")
162+
) {
142163
# Needs an editor, or needs an acknowledgement.
143164
# Ignore unacknowledged revisions before 2025
144165
"waiting (editor-in-chief)"
145-
} else if(status == "with AE") {
166+
} else if (status == "with AE") {
146167
"waiting (AE)"
147168
} else if (empty(x$reviewers)) {
148169
"waiting (editor)"
149-
} else if(status == "out for review" & completed_reviews(x) >= 2) {
150-
"waiting (editor)"
170+
} else if (status == "out for review" & completed_reviews(x) >= 2) {
171+
"waiting (editor)"
151172
} else {
152-
switch(status,
153-
"major revision" = "waiting (author)",
154-
"minor revision" = "waiting (author)",
173+
switch(
174+
status,
155175
"out for review" = "waiting (reviewers)",
156176
"updated" = "waiting (editor)",
157-
"reject and resubmit" = "waiting (author)",
158177
"published" = "needs removal (editor)",
159178
"withdrawn" = "needs removal (editor)",
160179
"rejected" = "needs removal (editor)",
@@ -163,10 +182,8 @@ todo <- function(x) {
163182
"AE: minor revision" = "waiting (editor)",
164183
"AE: accept" = "waiting (editor)",
165184
"AE: reject" = "waiting (editor)",
166-
"accepted" = "waiting (author)",
167185
"style checked" = "needs online (editor-in-chief)",
168186
"online" = "needs copy-editing (editor)",
169-
"copy edited" = "waiting (author)",
170187
"proofed" = "ready for publication (editor-in-chief)",
171188
"acknowledged" = "needs reviewers (editor)",
172189
stop("Unknown status: ", status)
@@ -239,7 +256,8 @@ parse_status <- function(x) {
239256
if (!stringr::str_detect(x, re)) {
240257
# NM added line
241258
cat("bad status:", x, "\n")
242-
stop("Status must have form 'yyyy-mm-dd status [optional comments]'",
259+
stop(
260+
"Status must have form 'yyyy-mm-dd status [optional comments]'",
243261
call. = FALSE
244262
)
245263
}

0 commit comments

Comments
 (0)