Skip to content

Commit

Permalink
Merge pull request #38 from tmills-usgs/master
Browse files Browse the repository at this point in the history
ISsue fix and test
  • Loading branch information
T. Joe Mills committed Feb 4, 2016
2 parents cc3548b + a888d2f commit bf45ca2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.Rproj.user
.Rproj
.Rhistory
.RData
README.md
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
language: r
warnings_are_errors: true
sudo: required

notifications:
slack: cowsc-datascience:iIMgl9BANsTVPnrsDQVuz31r
12 changes: 9 additions & 3 deletions R/fl3.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
fl3 <- function(qfiletempf, pref = "mean") {
lfcrit <- 0.05*mean(qfiletempf$discharge)
lowflow <- subset(qfiletempf,qfiletempf$discharge<lfcrit)

if (nrow(lowflow)>0) {
lowbyyr <- aggregate(lowflow$discharge,list(lowflow$wy_val),FUN=length)
lowCounts <- aggregate(lowflow$discharge,list(lowflow$wy_val),FUN=length)
names(lowCounts) <- c("wy_val","count")
lowbyyr <- data.frame(wy_val = unique(qfiletempf$wy_val))
lowbyyr <- merge(lowbyyr,lowCounts, by = "wy_val",all=TRUE)
lowbyyr$count[is.na(lowbyyr$count)] <- 0

if (pref == "median") {
fl3 <- round(median(lowbyyr$x),digits=2)
fl3 <- round(median(lowbyyr$count),digits=2)
}
else {
fl3 <- round(mean(lowbyyr$x),digits=2)
fl3 <- round(mean(lowbyyr$count),digits=2)
}}
else {
fl3 <- 0
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/requencyFunctionTests.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
context("frequency indicators")

###load the data upfront
load("data/sampleData.RData")
qfiletempf <- sampleData

test_that("fh1.2 test", {
expect_equal(fh1.2(qfiletempf),list(fh1=16,
fh2=44.19))
})

test_that("fh10 test", {
expect_equal(fh10(qfiletempf),2)
})

test_that("fh11 test", {
sites<-"02178400"
peakValues<-getPeakData(sites)
thresh<-1158.495

expect_equal(fh11(qfiletempf,thresh),1.5)
})

test_that("fh3 test", {
expect_equal(fh3(qfiletempf),14)
})

0 comments on commit bf45ca2

Please sign in to comment.