vanzanden / ggsolvencyii

@@ -209,6 +209,7 @@
Loading
209 209
                      ## ellipsis
210 210
                        ...
211 211
                      ) {
212 +
        statistics(caller = "stat_geomsiiriskSURFACE.csv")
212 213
        ggplot2::layer(data = data,
213 214
                       stat = stat,
214 215
                       geom = GeomSiiRisksurface,
@@ -319,6 +320,7 @@
Loading
319 320
                  ## ellipsis
320 321
                    ...
321 322
                  ) {
323 +
        statistics(caller = "stat_geomsiiriskOUTLINE.csv")
322 324
        ggplot2::layer( data = data,
323 325
                stat = stat,
324 326
                geom = GeomSiiRiskoutline,
@@ -390,6 +392,7 @@
Loading
390 392
                                  ## ellipsis
391 393
                                    ...
392 394
                                  ) {
395 +
                        statistics(caller = "stat_geomsiiriskCONNECTION.csv")
393 396
                        ggplot2::layer(data = data,
394 397
                        stat = stat,
395 398
                        geom = GeomSiiRiskconnection,

@@ -0,0 +1,208 @@
Loading
1 +
## GNU General Public License version 3 , see file LICENCE ============== =====
2 +
##
3 +
##    sourcefile of package 'ggsolvencyii'
4 +
##    Copyright (C) <2018>  < Marco van Zanden , git@vanzanden.nl >
5 +
##
6 +
##    This program is free software: you can redistribute it and/or modify
7 +
##    it under the terms of the GNU General Public License as published by
8 +
##    the Free Software Foundation, either version 3 of the License, or
9 +
##    (at your option) any later version.
10 +
##
11 +
##    This program is distributed in the hope that it will be useful,
12 +
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 +
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 +
##    GNU General Public License for more details.
15 +
##
16 +
##    You should have received a copy of the GNU General Public License
17 +
##    along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 +
##
19 +
##
20 +
## functions in this file =============================================== =====
21 +
##
22 +
## main:
23 +
##
24 +
## small:
25 +
##
26 +
## ====================================================================== =====
27 +
28 +
29 +
#' statistics
30 +
#'
31 +
#' This behaviour can be switched off by means of calling " "
32 +
#' When switche on a reminder is given in regular intervals. This behaviour can also be switched off by calling " "
33 +
#' @param caller (default = "stat_usage.csv") the filename which will be downloaded, for each geom is a separate file available
34 +
#'
35 +
#' @return nothing
36 +
#'
37 +
#' @examples
38 +
#' # library(ggsolvencyii)
39 +
#' ggsolvencyii:::statistics()
40 +
#' sii_setoption_statistics_httpfailurecounter <- function(cnt = 52)
41 +
#' ggsolvencyii:::statistics(caller = "404notfound.csv")
42 +
#' sii_setoption_statistics_httpfailurecounter <- function(cnt = 0)
43 +
#' sii_setoption_statistics_participate(participate = TRUE)
44 +
statistics <- function(caller = "stat_usage.csv")
45 +
  {
46 +
    P <- getOption("ggsolvencyii_statistics_participate") # returns NULL, or the value
47 +
    if (is.null(P))
48 +
      { sii_setoption_statistics_participate(participate = TRUE, quiet = TRUE)
49 +
        P <- TRUE
50 +
        sii_setoption_statistics_remind(remind = TRUE, quiet = TRUE)
51 +
        sii_setoption_statistics_remindercounter(cnt = 0)
52 +
        sii_setoption_statistics_httpfailurecounter(cnt = 0)
53 +
      }
54 +
    R <- getOption("ggsolvencyii_statistics_remind") # returns the value
55 +
    RC <- getOption("ggsolvencyii_statistics_remindercounter") # returns the value
56 +
    FC <- getOption("ggsolvencyii_statistics_httpfailurecounter")
57 +
58 +
    if (P == TRUE)
59 +
      {
60 +
        callresult <- get_external_data(caller = caller)
61 +
         if (callresult == FALSE)
62 +
          {
63 +
            options("ggsolvencyii_statistics_httpfailurecounter" = FC + 1)
64 +
           if (FC > 50)
65 +
              {
66 +
                  P <- FALSE
67 +
                 sii_setoption_statistics_participate(participate = FALSE, quiet = TRUE)
68 +
              }
69 +
          } else
70 +
          {options("ggsolvencyii_statistics_httpfailurecounter" = 0)}
71 +
      }
72 +
    if (R == TRUE)
73 +
      {
74 +
        sii_setoption_statistics_remindercounter(cnt = RC + 1)
75 +
        if (RC %in% c(1 , 2 , 3 , 5 , 10 ,50, 100 , 200 , 500 , 1000 , 1500 , 2500)) {print("reminder: anonymous userdata is send to www.vanzanden.nl. This behaviour can be switched of by sii_setoption_statistics_participate(participate = FALSE). This reminder can be switched of with sii_setoption_statistics_remind(remind = FALSE)")}
76 +
      }
77 +
    return("done")
78 +
    }
79 +
80 +
81 +
#' sii_setoption_statistics_participate
82 +
#' sets the option to participate in anonymous user statistics, no other data is sent other than the calling geom and the IP adress
83 +
#'
84 +
#' @param participate (boolean, default = TRUE) whether to participate
85 +
#' @param quiet (boolean, default = FALSE) whether to confirm that the option is set
86 +
#'
87 +
#' @return participate
88 +
#' @export
89 +
#'
90 +
#' @examples
91 +
#' library(ggsolvencyii)
92 +
#' sii_setoption_statistics_participate()
93 +
#' sii_setoption_statistics_participate(FALSE)
94 +
#' sii_setoption_statistics_participate(participate = FALSE, quiet = FALSE)
95 +
#'
96 +
sii_setoption_statistics_participate <- function(participate = TRUE, quiet = FALSE){
97 +
  options("ggsolvencyii_statistics_participate" = participate)
98 +
  sii_setoption_statistics_httpfailurecounter() # cnt = 0
99 +
  caller = "stat_statisticsOFF.csv"
100 +
  if ( participate == TRUE) {caller = "stat_statisticsON.csv"}
101 +
  callresult <- get_external_data <- function(caller = caller)
102 +
  if (quiet == FALSE) {print(paste0("option is set: ggsolvencyii_statistics_participate is set to ",participate))}
103 +
  return(participate)
104 +
}
105 +
106 +
107 +
#' sii_setoption_statistics_remind
108 +
#' sets the option to remind that participation is set to TRUE (if that is the case) after 1,2,3,5,10,50,100,200,500,1000,1500,2500 calls
109 +
#'
110 +
#' @param remind (default = TRUE) : whether to remind that participation is set
111 +
#' @param quiet (default = FALSE) : whether to confirm that the option is set
112 +
#'
113 +
#' @return remind
114 +
#' @export
115 +
#'
116 +
#' @examples
117 +
#' library(ggsolvencyii)
118 +
#' sii_setoption_statistics_remind()
119 +
#' sii_setoption_statistics_remind(remind = FALSE)
120 +
#' sii_setoption_statistics_remind(remind = FALSE, quiet = TRUE)
121 +
#'
122 +
sii_setoption_statistics_remind <- function(remind = TRUE,  quiet = FALSE){
123 +
  options("ggsolvencyii_statistics_remind" = remind)
124 +
  caller = "reminderOFF.csv"
125 +
  if ( remind == TRUE) {caller = "stat_reminderON.csv"}
126 +
  callresult <- get_external_data <- function(caller = caller)
127 +
  if (quiet == FALSE) {print(paste0("option is set: ggsolvencyii_statistics_remind is set to ",remind))}
128 +
  return(remind)
129 +
}
130 +
131 +
132 +
#' sii_setoption_statistics_remindercounter
133 +
#'
134 +
#' @param cnt (default = 0)
135 +
#'
136 +
#' @return nothing
137 +
#'
138 +
#' @examples
139 +
#' # library(ggsolvencyii)
140 +
#' ggsolvencyii:::sii_setoption_statistics_remindercounter()
141 +
#' ggsolvencyii:::sii_setoption_statistics_remindercounter(cnt = 10)
142 +
#'
143 +
sii_setoption_statistics_remindercounter <- function(cnt = 0){
144 +
  options("ggsolvencyii_statistics_remindercounter" = cnt)
145 +
}
146 +
147 +
148 +
#' sii_setoption_statistics_httpfailurecounter
149 +
#'
150 +
#' @param cnt (default = 0) the value to be assigned to the counter
151 +
#'
152 +
#' @return nothing
153 +
#'
154 +
#' @examples
155 +
#' # library(ggsolvencyii)
156 +
#' ggsolvencyii:::sii_setoption_statistics_httpfailurecounter()
157 +
#' ggsolvencyii:::sii_setoption_statistics_httpfailurecounter(cnt = 10)
158 +
#'
159 +
sii_setoption_statistics_httpfailurecounter <- function(cnt = 0){
160 +
  options("ggsolvencyii_statistics_httpfailurecounter" = cnt)
161 +
  }
162 +
163 +
164 +
165 +
166 +
#' get_external_data makes a call to website vanzanden.nl. The only purpose is to track the usage of (parts) of the package.
167 +
#'
168 +
#' @param caller (default = "stat_usage.csv") the filename which will be downloaded, for each geom is a separate file available
169 +
#'
170 +
#' @return it returns a list: $success = TRUE/FALSE
171 +
#' @importFrom httr HEAD
172 +
#' @importFrom utils read.csv
173 +
#'
174 +
#' @examples
175 +
#' library(ggsolvencyii)
176 +
#' callresult <- ggsolvencyii:::get_external_data(caller = "stat_usage.csv")
177 +
#' callresult
178 +
get_external_data <- function(caller = "stat_usage.csv")
179 +
{
180 +
  file = paste0("http://www.vanzanden.nl/ggsolvencyii/usetracking/",caller)
181 +
  status <- httr::HEAD(file)
182 +
  # print(status$status_code)
183 +
  callresult = FALSE
184 +
  if (status$status_code == 200) {callresult <- read.csv(file)} # increasing the counter on the vanzanden.nl domain.
185 +
  return(callresult)
186 +
}
187 +
188 +
189 +
190 +
191 +
# options("ggsolvencyii_statistics_participate" = NULL)
192 +
# options("ggsolvencyii_statistics_remind" = NULL)
193 +
# options("ggsolvencyii_statistics_remindercounter" = NULL)
194 +
#
195 +
# getOption("ggsolvencyii_statistics_participate" )
196 +
# getOption("ggsolvencyii_statistics_remind" )
197 +
# getOption("ggsolvencyii_statistics_remindercounter" )
198 +
# getOption("ggsolvencyii_statistics_httpfailurecounter" )
199 +
#
200 +
#
201 +
#
202 +
#
203 +
# statistics
204 +
205 +
206 +
207 +
208 +
Files Coverage
R 95.37%
Project Totals (10 files) 95.37%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading