Skip to content

Commit 96c293f

Browse files
authored
fix: ignore missing schedule references (#26)
* fix: ignore missing schedule references * docs: record nullable schedule fix
1 parent f981fb9 commit 96c293f

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# destep 0.0.0.9000
22

3+
- Ignored missing and zero-valued DeST schedule references during conversion,
4+
preventing nullable reserved fields from producing invalid SQL (#26).
35
- Preserved DeST enclosure geometry during EnergyPlus conversion by correcting
46
surface types, outward normals, reciprocal boundary references, true-north
57
rotation, EnergyPlus-tolerance vertex handling, shared-edge topology,

R/conv-schedule.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ destep_conv_schedule <- function(dest, ep) {
4444
}
4545
}
4646
})))
47-
# TODO: what is the value of the default schedule with ID = 0 for WINDOW table?
48-
ids_ref <- ids_ref[ids_ref != 0L]
47+
# NULL means that the optional reference is not assigned, while zero is
48+
# DeST's sentinel for a default or unused schedule. Neither value names a
49+
# SCHEDULE_YEAR row, and retaining NA would emit it as a SQL identifier.
50+
ids_ref <- ids_ref[!is.na(ids_ref) & ids_ref != 0L]
51+
if (length(ids_ref) == 0L) return(NULL)
4952

5053
schedule <- data.table::setDT(DBI::dbGetQuery(
5154
dest,

tests/testthat/test-conv-schedule.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,55 @@ test_that("schedule conversion writes resolvable week day references", {
3636
expect_true(all(unique(week_day_names) %in% day_names))
3737
})
3838

39+
test_that("schedule conversion ignores missing and zero references", {
40+
ep <- ensure_empty_idf()
41+
dest <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
42+
on.exit(DBI::dbDisconnect(dest), add = TRUE)
43+
44+
DBI::dbWriteTable(dest, "SCHEDULE_YEAR", data.frame(
45+
SCHEDULE_ID = 10L,
46+
NAME = "Always On",
47+
TYPE = 1L,
48+
DATA = I(list(destep_test_schedule_blob(rep(1, 8760L))))
49+
))
50+
DBI::dbWriteTable(dest, "DOOR", data.frame(
51+
ID = 1:2,
52+
SCHEDULE = c(NA_integer_, NA_integer_)
53+
))
54+
DBI::dbWriteTable(dest, "SCHEDULE_USAGE", data.frame(
55+
ID = 1:3,
56+
SCHEDULE_ID = c(10L, 0L, NA_integer_)
57+
))
58+
59+
schedule <- destep_conv_schedule(dest, ep)
60+
61+
expect_type(schedule, "list")
62+
expect_equal(attr(schedule, "table")$SCHEDULE_ID, 10L)
63+
})
64+
65+
test_that("schedule conversion returns null without valid references", {
66+
ep <- ensure_empty_idf()
67+
dest <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
68+
on.exit(DBI::dbDisconnect(dest), add = TRUE)
69+
70+
DBI::dbWriteTable(dest, "SCHEDULE_YEAR", data.frame(
71+
SCHEDULE_ID = 10L,
72+
NAME = "Always On",
73+
TYPE = 1L,
74+
DATA = I(list(destep_test_schedule_blob(rep(1, 8760L))))
75+
))
76+
DBI::dbWriteTable(dest, "DOOR", data.frame(
77+
ID = 1:2,
78+
SCHEDULE = c(NA_integer_, NA_integer_)
79+
))
80+
DBI::dbWriteTable(dest, "WINDOW", data.frame(
81+
ID = 1L,
82+
SCHEDULE = 0L
83+
))
84+
85+
expect_null(destep_conv_schedule(dest, ep))
86+
})
87+
3988
test_that("real model schedule week and year references are resolvable", {
4089
skip_on_cran()
4190

0 commit comments

Comments
 (0)