feat(data-layer): Resampler (candle resampling) in all 10 languages (#310)
* feat(data-layer): Resampler (candle resampling) in all 10 languages Second data-layer feature (F3): resample candles into a higher timeframe. - Native (Node.js/WASM): new Resampler(timeframe) -> update(o,h,l,c,v,ts): Candle|null + flush(): Candle|null. Python the same -> tuple|None. - C ABI: wickra_resampler_new/update/flush/free (update has the multi-output shape so the generators auto-emit it; flush is bespoke). Go Update -> (Candle, bool) + Flush; C# Candle? Update/Flush; Java Candle update/flush; R update() generic + a flush() S3 method (extends base::flush); C/C++ direct. - Cross-language golden (testdata/golden/data_resampled.csv): the shared input candles resampled into 5-unit buckets, the final partial bucket via flush, pinned bit-for-bit across every binding. Verified locally in all 10 (3 candles for the 5-unit smoke; 16 for the golden). The WickraCandle output record is shared with the tick aggregator (deduped). * test(node): exclude data-layer types from the indicator completeness contract The Resampler exposes update(), so the completeness test flagged it as an indicator and required batch/reset/isReady/warmupPeriod, which a data-layer type does not have. Exclude TickAggregator and Resampler like the bar builders.
This commit is contained in:
@@ -50,3 +50,31 @@ test_that("tick aggregator matches the golden candles", {
|
||||
expect_equal(got, want, tolerance = 1e-9, info = spec$fixture)
|
||||
}
|
||||
})
|
||||
|
||||
test_that("resampler matches the golden candles", {
|
||||
gdir <- find_data_golden_dir()
|
||||
skip_if(is.null(gdir), "golden fixtures not bundled with the package")
|
||||
|
||||
read_mat <- function(name) {
|
||||
lines <- readLines(file.path(gdir, paste0(name, ".csv")))[-1]
|
||||
lines <- lines[nzchar(lines)]
|
||||
do.call(rbind, lapply(lines, function(l) as.numeric(strsplit(l, ",")[[1]])))
|
||||
}
|
||||
|
||||
input <- read_mat("input") # open,high,low,close,volume (timestamp = row index)
|
||||
r <- Resampler(5)
|
||||
got <- matrix(numeric(0), 0, 6)
|
||||
for (i in seq_len(nrow(input))) {
|
||||
c <- update(r, input[i, 1], input[i, 2], input[i, 3], input[i, 4], input[i, 5], i - 1)
|
||||
if (!is.na(c[1])) {
|
||||
got <- rbind(got, unname(c))
|
||||
}
|
||||
}
|
||||
f <- flush(r)
|
||||
if (!is.null(f)) {
|
||||
got <- rbind(got, unname(f))
|
||||
}
|
||||
want <- unname(read_mat("data_resampled"))
|
||||
expect_equal(nrow(got), nrow(want))
|
||||
expect_equal(got, want, tolerance = 1e-9)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user