r112748 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112747‎ | r112748 | r112749 >
Date:00:43, 1 March 2012
Author:rfaulk
Status:deferred
Tags:
Comment:
added script for performing basic visualizations on the data
Modified paths:
  • /trunk/tools/wsor/message_templates/R/visualize_edits_decrease.R (added) (history)

Diff [purge]

Index: trunk/tools/wsor/message_templates/R/visualize_edits_decrease.R
@@ -0,0 +1,105 @@
 2+
 3+# source('/home/rfaulkner/trunk/projects/WSOR/message_templates/R/visualize_edits_decrease.R')
 4+#
 5+# Ryan Faulkner, February 28th 2012
 6+#
 7+# Prepare data and visualize
 8+#
 9+
 10+source('/home/rfaulkner/trunk/projects/WSOR/message_templates/R/template_analysis.R')
 11+# library(ggplot2)
 12+
 13+# FUNCTION :: plot.control.vs.test
 14+#
 15+# Basic plotting for te st vs. control
 16+#
 17+
 18+plot.control.vs.test <- function(title, x_label, y_label, test_samples, control_samples) {
 19+
 20+ # Define axis range
 21+
 22+ scaling_factor = 10
 23+ shift_factor = 0.1
 24+ y_axis_range = ((scaling_factor + shift_factor) * min(c(test_samples, control_samples, 0))) : ((scaling_factor + shift_factor) * max(c(test_samples, control_samples)))
 25+ y_axis_range = round(y_axis_range / scaling_factor, digits=2)
 26+ g_range <- range(y_axis_range)
 27+
 28+ # Graph cars using a y axis that ranges from 0 to 12
 29+ plot(edit_decrease_means_test, type="o", col="blue", ylim=c(g_range[1],g_range[2]), axes=FALSE, ann=FALSE)
 30+
 31+ # Make x axis using Mon-Fri labels
 32+
 33+ axis(1, at=1:length(test_samples))
 34+ axis(2, las=1, at=y_axis_range)
 35+ box()
 36+
 37+ # Create a title with a red, bold/italic font
 38+ title(main=title, col.main="red", font.main=4)
 39+
 40+ # Make x axis using Mon-Fri labels
 41+ # Label the x and y axes with dark green text
 42+ title(xlab=x_label, col.lab=rgb(0,0.5,0))
 43+ title(ylab=y_label, col.lab=rgb(0,0.5,0))
 44+
 45+ # Graph trucks with red dashed line and square points
 46+ lines(edit_decrease_means_control, type="o", pch=22, lty=2, col="red")
 47+
 48+ # Create a legend at (1, g_range[2]) that is slightly smaller
 49+ # (cex) and uses the same line colors and points used by
 50+ # the actual plots
 51+ legend(1, 1, c("test","control"), cex=0.8,
 52+ col=c("blue","red"), pch=21:22, lty=1:2);
 53+}
 54+
 55+
 56+plot.control.vs.test.ggplot <- function(test_samples, control_samples) {
 57+
 58+ df <- data.frame(x=1:length(test_samples), y_test=test_samples, y_ctrl=control_samples)
 59+
 60+ ggplot(df,aes(x)) + geom_line(aes(y=y_test,colour="Test")) + geom_line(aes(y=y_ctrl,colour="Control"))
 61+}
 62+
 63+
 64+# IMPORT DATA
 65+
 66+# c(84, 0) c(107,109,111,113,115) c(78,81) c(1,4) c(84,99,101,103,105)
 67+template_indices_control <- c(60,62,64,66,68,70,72,74,76)
 68+
 69+# c(85, 0) c(108,110,114,116) c(79,82) c(2,3) c(85,86,100,102,104,106)
 70+template_indices_test <- c(61,63,65,67,69,71,73,75,77)
 71+
 72+# paste(home_dir,"output/metrics_1108_1202_z",sep="") paste(home_dir,"output/metrics_1122_1222_z",sep="") paste(home_dir,"output/metrics_1109_1209_z",sep="") paste(home_dir,"output/metrics_pt_z",sep="") "/home/rfaulk/WSOR/message_templates/output/metrics_pt_z"
 73+fname_first_part <- paste(home_dir,"output/metrics_1018_1119_z",sep="")
 74+
 75+import.experimental.metrics.data(template_indices_test, template_indices_control, fname_first_part)
 76+
 77+
 78+
 79+# PROCESS DATA
 80+
 81+edit_count_before_filter <- 1:10
 82+
 83+edit_decrease_means_test <- c()
 84+edit_decrease_means_control <- c()
 85+
 86+for (i in edit_count_before_filter)
 87+{
 88+ process.data.frames(i,0,Inf,Inf)
 89+
 90+ edit_decrease_means_test <- c(edit_decrease_means_test, mean(merged_test$edits_decrease))
 91+ edit_decrease_means_control <- c(edit_decrease_means_control, mean(merged_control$edits_decrease))
 92+}
 93+
 94+# PLOT DATA
 95+
 96+# plot.control.vs.test("Huggle Short 2 Experiment - Decrease in Editor Activity", "Minimum Edits before Template Posting", "Mean % Decrease in Edit Activity", edit_decrease_means_test, edit_decrease_means_control)
 97+
 98+# ggplot
 99+
 100+plot_title = "Huggle 3 - % decrease of Edit Actitivity after Posting"
 101+
 102+df <- data.frame(x=1:length(edit_decrease_means_test), y_test=edit_decrease_means_test, y_ctrl=edit_decrease_means_control)
 103+p = ggplot(df,aes(x)) + geom_line(aes(y=y_test,colour="Test")) + geom_line(aes(y=y_ctrl,colour="Control"))
 104+p + scale_x_continuous('Minimum Edits before Template Posting') + scale_y_continuous('Mean % Decrease in Edit Activity') + opts(title = plot_title, legend.title = theme_blank())
 105+ggsave('/home/rfaulkner/trunk/projects/WSOR/message_templates/R/plots/huggle_3.png',width=8)
 106+