r114039 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114038‎ | r114039 | r114040 >
Date:22:16, 16 March 2012
Author:rfaulk
Status:new
Tags:
Comment:
added method counts.to.samples -- Take a list of counts and produce a new list of samples with the same distribution of those counts

some logic to handle 0 templates that are used as dummy metric files to append data.frames in build.data.frames
Modified paths:
  • /trunk/tools/wsor/message_templates/R/R_helper_functions.R (modified) (history)

Diff [purge]

Index: trunk/tools/wsor/message_templates/R/R_helper_functions.R
@@ -203,11 +203,11 @@
204204 # Constructs a concatenated data.frame from files
205205 #
206206
207 -build.data.frames <- function(template_indices, fname_first_part, fname_last_part, string_frames=c(0)) {
208 -
 207+build.data.frames <- function(template_indices, fname_first_part, fname_last_part, home_dir, string_frames=c(0)) {
 208+
209209 # Initialize the data frame
210210
211 - filename <- paste(fname_first_part, template_indices[1], fname_last_part, sep="")
 211+ filename <- paste(home_dir, fname_first_part, template_indices[1], fname_last_part, sep="")
212212 metrics = read.table(filename, na.strings="\\N", sep="\t", comment.char="", quote="", header=T)
213213 output <- paste("Processing data from",filename,"....")
214214 print(output)
@@ -216,11 +216,15 @@
217217
218218 if (length(template_indices) > 1)
219219 for (i in 2:length(template_indices))
220 - {
221 -
 220+ {
222221 index <- template_indices[i]
223 - filename <- paste(fname_first_part, index, fname_last_part, sep="")
224222
 223+ # Make an exception for the "0" template
 224+ if (index == 0)
 225+ filename <- paste(home_dir, "output/metrics_z", index, fname_last_part, sep="")
 226+ else
 227+ filename <- paste(home_dir, fname_first_part, index, fname_last_part, sep="")
 228+
225229 output <- paste("Processing data from",filename,"....")
226230 print(output)
227231
@@ -299,3 +303,21 @@
300304 new_list
301305 }
302306
 307+
 308+# FUNCTION :: counts.to.samples
 309+#
 310+# Take a list of counts and produce a new list of samples with the same distribution of those counts
 311+#
 312+
 313+counts.to.samples <- function(sample_values, counts) {
 314+
 315+ samples <- c()
 316+
 317+ for (i in sample_values)
 318+ {
 319+ samples_to_add <- i * (1:counts[i] / 1:counts[i])
 320+ samples <- c(samples, samples_to_add)
 321+ }
 322+
 323+ samples
 324+}

Status & tagging log