From b7f3ffe21eaf7e244fc9705381421cbfcc1f1bb7 Mon Sep 17 00:00:00 2001 From: Alan Arnholt Date: Thu, 23 Jun 2016 19:38:56 -0400 Subject: [PATCH 1/3] add answer tag --- inst/lab.css | 267 ++++++++++++++++++++++++++------------------------- 1 file changed, 137 insertions(+), 130 deletions(-) diff --git a/inst/lab.css b/inst/lab.css index cbbe37d..e47ceb5 100644 --- a/inst/lab.css +++ b/inst/lab.css @@ -1,130 +1,137 @@ -.fax-slot-machine:before { - content: "\1f3b0" -} - -body { - counter-reset: li; /* initialize counter named li */ -} - -h1 { - font-family:Arial, Helvetica, sans-serif; - font-weight:bold; -} - -h2 { - font-family:Arial, Helvetica, sans-serif; - font-weight:bold; - margin-top: 24px; -} - -hr { - border: 1px solid #357FAA; -} - -ol { - margin-left:0; /* Remove the default left margin */ - padding-left:0; /* Remove the default left padding */ -} - -ol > li { - position:relative; /* Create a positioning context */ - margin:0 0 10px 2em; /* Give each list item a left margin to make room for the numbers */ - padding:10px 80px; /* Add some spacing around the content */ - list-style:none; /* Disable the normal item numbering */ - border-top:2px solid #317EAC; - background:rgba(49, 126, 172, 0.1); -} - -ol > li:before { - content:"Question " counter(li); /* Use the counter as content */ - counter-increment:li; /* Increment the counter by 1 */ - /* Position and style the number */ - position:absolute; - top:-2px; - left:-2em; - -moz-box-sizing:border-box; - -webkit-box-sizing:border-box; - box-sizing:border-box; - width:7em; - /* Some space between the number and the content in browsers that support - generated content but not positioning it (Camino 2 is one example) */ - margin-right:8px; - padding:4px; - border-top:2px solid #317EAC; - color:#fff; - background:#317EAC; - font-weight:bold; - font-family:"Helvetica Neue", Arial, sans-serif; - text-align:center; -} - -li ol, -li ul {margin-top:6px;} - -ol ol{ - counter-reset: subitem; -} - -li li{ - border-top:0px solid #317EAC; - background:rgba(49, 126, 172, 0); - padding:0px 0px; /* No spacing around the content */ -} - -li li:before{ - content: counter(subitem, upper-alpha) '. '; - counter-increment: subitem; - /* Position and style the number */ - position:absolute; - top:-2px; - left:-2em; - /*-moz-box-sizing:border-box;*/ - /*-webkit-box-sizing:border-box;*/ - box-sizing:content-box; - width:1em; - /* Some space between the number and the content in browsers that support - generated content but not positioning it (Camino 2 is one example) */ - margin-right:4px; - padding:2px; - border-top: initial; /*0px solid #317EAC;*/ - color:#317EAC; - background:transparent; - font-weight:bold; - font-family:"Helvetica Neue", Arial, sans-serif; - text-align:center; -} - -div#instructions { - margin-top: 30px; - margin-bottom: 30px; - color: rgba(0, 102, 102, 0.8); - border:1px solid rgba(0, 102, 102, 0.2); - padding: 10px 10px; - background: rgba(204, 255, 255, 0.1); - border-radius: 5px; -} - -div#license { - margin-top: 30px; - margin-bottom: 30px; - color: rgba(76, 114, 29, 0.8); - border:1px solid rgba(76, 114, 29, 0.2); - padding: 10px 10px; - background: rgba(76, 114, 29, 0.1); - border-radius: 5px; -} - -div#boxedtext { - background-color: rgba(86, 155, 189, 0.2); - padding: 20px; - margin-bottom: 20px; - font-size: 10pt; -} - -div#exercise { - position:relative; /* Create a positioning context */ - margin:0 0 10px 0em; /* Give each list item a left margin to make room for the numbers */ - padding:10px 30px; /* Add some spacing around the content */ - border-top:2px solid #35CD4B; - background:rgba(49, 199, 58, 0.1); -} +.fax-slot-machine:before { + content: "\1f3b0" +} + +body { + counter-reset: li; /* initialize counter named li */ +} + +h1 { + font-family:Arial, Helvetica, sans-serif; + font-weight:bold; +} + +h2 { + font-family:Arial, Helvetica, sans-serif; + font-weight:bold; + margin-top: 24px; +} + +hr { + border: 1px solid #357FAA; +} + +ol { + margin-left:0; /* Remove the default left margin */ + padding-left:0; /* Remove the default left padding */ +} + +ol > li { + position:relative; /* Create a positioning context */ + margin:0 0 10px 2em; /* Give each list item a left margin to make room for the numbers */ + padding:10px 80px; /* Add some spacing around the content */ + list-style:none; /* Disable the normal item numbering */ + border-top:2px solid #317EAC; + background:rgba(49, 126, 172, 0.1); +} + +ol > li:before { + content:"Question " counter(li); /* Use the counter as content */ + counter-increment:li; /* Increment the counter by 1 */ + /* Position and style the number */ + position:absolute; + top:-2px; + left:-2em; + -moz-box-sizing:border-box; + -webkit-box-sizing:border-box; + box-sizing:border-box; + width:7em; + /* Some space between the number and the content in browsers that support + generated content but not positioning it (Camino 2 is one example) */ + margin-right:8px; + padding:4px; + border-top:2px solid #317EAC; + color:#fff; + background:#317EAC; + font-weight:bold; + font-family:"Helvetica Neue", Arial, sans-serif; + text-align:center; +} + +li ol, +li ul {margin-top:6px;} + +ol ol{ + counter-reset: subitem; +} + +li li{ + border-top:0px solid #317EAC; + background:rgba(49, 126, 172, 0); + padding:0px 0px; /* No spacing around the content */ +} + +li li:before{ + content: counter(subitem, upper-alpha) '. '; + counter-increment: subitem; + /* Position and style the number */ + position:absolute; + top:-2px; + left:-2em; + /*-moz-box-sizing:border-box;*/ + /*-webkit-box-sizing:border-box;*/ + box-sizing:content-box; + width:1em; + /* Some space between the number and the content in browsers that support + generated content but not positioning it (Camino 2 is one example) */ + margin-right:4px; + padding:2px; + border-top: initial; /*0px solid #317EAC;*/ + color:#317EAC; + background:transparent; + font-weight:bold; + font-family:"Helvetica Neue", Arial, sans-serif; + text-align:center; +} + +div#instructions { + margin-top: 30px; + margin-bottom: 30px; + color: rgba(0, 102, 102, 0.8); + border:1px solid rgba(0, 102, 102, 0.2); + padding: 10px 10px; + background: rgba(204, 255, 255, 0.1); + border-radius: 5px; +} + +div#license { + margin-top: 30px; + margin-bottom: 30px; + color: rgba(76, 114, 29, 0.8); + border:1px solid rgba(76, 114, 29, 0.2); + padding: 10px 10px; + background: rgba(76, 114, 29, 0.1); + border-radius: 5px; +} + +div#boxedtext { + background-color: rgba(86, 155, 189, 0.2); + padding: 20px; + margin-bottom: 20px; + font-size: 10pt; +} + +div#answer { + background-color: rgba(155, 86, 189, 0.2); + padding: 20px; + margin-bottom: 20px; + font-size: 10pt; +} + +div#exercise { + position:relative; /* Create a positioning context */ + margin:0 0 10px 0em; /* Give each list item a left margin to make room for the numbers */ + padding:10px 30px; /* Add some spacing around the content */ + border-top:2px solid #35CD4B; + background:rgba(49, 199, 58, 0.1); +} From 9a7deca378bf3e3465d4b449f442af73dcf857cd Mon Sep 17 00:00:00 2001 From: Alan Arnholt Date: Sat, 25 Jun 2016 08:03:07 -0400 Subject: [PATCH 2/3] account for case when last shot is a miss --- R/calc_streak.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/calc_streak.R b/R/calc_streak.R index 6d08138..d69bc7d 100644 --- a/R/calc_streak.R +++ b/R/calc_streak.R @@ -5,6 +5,10 @@ #' @examples #' data(kobe_basket) #' calc_streak(kobe_basket$shot) +#' test1 <- c("H","M","M","H","H","M","M","M","H","M") +#' test2 <- c("H","M","M","H","H","M","M","M","H","H") +#' calc_streak(test1) +#' calc_streak(test2) #' #' @export @@ -18,6 +22,13 @@ calc_streak = function(x) y = rep(0,length(x)) y[x == "H"] = 1 + # Need to account for case when last shot is a miss + y <- if(y[length(y)]==0){ + y[-length(y)] + }else{ + y + } + # y = c(0, y, 0) wz = which(y == 0) streak = diff(wz) - 1 From 564c3a5ffa0eca06e6a1d13b9aed0e2c3d8d43a3 Mon Sep 17 00:00:00 2001 From: Alan Arnholt Date: Sat, 25 Jun 2016 09:50:48 -0400 Subject: [PATCH 3/3] add test cases to examples --- R/calc_streak.R | 27 ++++++++++++++++----------- man/calc_streak.Rd | 10 ++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/R/calc_streak.R b/R/calc_streak.R index d69bc7d..41471f5 100644 --- a/R/calc_streak.R +++ b/R/calc_streak.R @@ -5,33 +5,38 @@ #' @examples #' data(kobe_basket) #' calc_streak(kobe_basket$shot) +#' barplot(table(calc_streak(kobe_basket$shot)), col = "blue", +#' xlab = "Streak length", ylab = "Frequency") #' test1 <- c("H","M","M","H","H","M","M","M","H","M") #' test2 <- c("H","M","M","H","H","M","M","M","H","H") +#' test3 <- c("M","M","M","H","H","M","M","M","H","H") #' calc_streak(test1) +#' barplot(table(calc_streak(test1)), col = "green", +#' xlab = "Streak length", ylab = "Frequency") #' calc_streak(test2) +#' calc_streak(test3) #' #' @export -calc_streak = function(x) -{ +calc_streak = function(x) { if (!is.atomic(x)) - x = x[,1] - - if (any(!x %in% c("H","M"))) + x = x[, 1] + + if (any(!x %in% c("H", "M"))) stop('Input should only contain hits ("H") and misses ("M")') - y = rep(0,length(x)) + y = rep(0, length(x)) y[x == "H"] = 1 # Need to account for case when last shot is a miss - y <- if(y[length(y)]==0){ + y <- if (y[length(y)] == 0) { y[-length(y)] - }else{ + } else { y } # y = c(0, y, 0) wz = which(y == 0) streak = diff(wz) - 1 - - return(data.frame(length = streak)) -} \ No newline at end of file + return(data.frame(streak_length = streak)) +} + diff --git a/man/calc_streak.Rd b/man/calc_streak.Rd index 50f78b2..09deb29 100644 --- a/man/calc_streak.Rd +++ b/man/calc_streak.Rd @@ -18,6 +18,16 @@ Calculate hit streaks. \examples{ data(kobe_basket) calc_streak(kobe_basket$shot) +barplot(table(calc_streak(kobe_basket$shot)), col = "blue", + xlab = "Streak length", ylab = "Frequency") +test1 <- c("H","M","M","H","H","M","M","M","H","M") +test2 <- c("H","M","M","H","H","M","M","M","H","H") +test3 <- c("M","M","M","H","H","M","M","M","H","H") +calc_streak(test1) +barplot(table(calc_streak(test1)), col = "green", + xlab = "Streak length", ylab = "Frequency") +calc_streak(test2) +calc_streak(test3) }