https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114039
Revision: 114039
Author: rfaulk
Date: 2012-03-16 22:16:36 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
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: trunk/tools/wsor/message_templates/R/R_helper_functions.R
===================================================================
--- trunk/tools/wsor/message_templates/R/R_helper_functions.R 2012-03-16
22:16:15 UTC (rev 114038)
+++ trunk/tools/wsor/message_templates/R/R_helper_functions.R 2012-03-16
22:16:36 UTC (rev 114039)
@@ -203,11 +203,11 @@
# Constructs a concatenated data.frame from files
#
-build.data.frames <- function(template_indices, fname_first_part,
fname_last_part, string_frames=c(0)) {
-
+build.data.frames <- function(template_indices, fname_first_part,
fname_last_part, home_dir, string_frames=c(0)) {
+
# Initialize the data frame
- filename <- paste(fname_first_part, template_indices[1],
fname_last_part, sep="")
+ filename <- paste(home_dir, fname_first_part, template_indices[1],
fname_last_part, sep="")
metrics = read.table(filename, na.strings="\\N", sep="\t",
comment.char="", quote="", header=T)
output <- paste("Processing data from",filename,"....")
print(output)
@@ -216,11 +216,15 @@
if (length(template_indices) > 1)
for (i in 2:length(template_indices))
- {
-
+ {
index <- template_indices[i]
- filename <- paste(fname_first_part, index,
fname_last_part, sep="")
+ # Make an exception for the "0" template
+ if (index == 0)
+ filename <- paste(home_dir, "output/metrics_z",
index, fname_last_part, sep="")
+ else
+ filename <- paste(home_dir, fname_first_part,
index, fname_last_part, sep="")
+
output <- paste("Processing data from",filename,"....")
print(output)
@@ -299,3 +303,21 @@
new_list
}
+
+# FUNCTION :: counts.to.samples
+#
+# Take a list of counts and produce a new list of samples with the same
distribution of those counts
+#
+
+counts.to.samples <- function(sample_values, counts) {
+
+ samples <- c()
+
+ for (i in sample_values)
+ {
+ samples_to_add <- i * (1:counts[i] / 1:counts[i])
+ samples <- c(samples, samples_to_add)
+ }
+
+ samples
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs