ControlScripts: add basic R script for reading/scanning upload/download speed matrix...
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 14 Aug 2010 09:15:06 +0000 (12:15 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sat, 14 Aug 2010 09:15:06 +0000 (12:15 +0300)
ControlScripts/up_down_matrix_reader.R [new file with mode: 0644]

diff --git a/ControlScripts/up_down_matrix_reader.R b/ControlScripts/up_down_matrix_reader.R
new file mode 100644 (file)
index 0000000..3d356c8
--- /dev/null
@@ -0,0 +1,48 @@
+# R script to read peer-connection upload/download speed matrix files
+#
+# 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+#
+# Sample run (run parse_up_down_log.sh script before running this script)
+#     Rscript up_down_matrix_reader.R --args ../Results/samples/ down_mat_files.lst updown_peer_index.cfg ../Results/samples/down
+
+
+# Read transmitted command line arguments
+args <- commandArgs(trailingOnly = TRUE)
+
+target_folder <- args[2]
+mat_file_list_file <- args[3]
+peer_index_file <- args[4]
+matrix_folder <- args[5]
+rm(args)
+
+# read list matrix files
+mat_file_list <- scan(paste(target_folder, mat_file_list_file, sep="/"), what='character')
+
+# read list of peers
+peers <- scan(paste(target_folder, peer_index_file, sep="/"), list(0, ""))
+
+num_peers <- length(peers[[1]])
+num_intervals <- length(mat_file_list)
+
+"num_peers"
+num_peers
+"num_intervals"
+num_intervals
+
+# allocate array of matrices
+speed_array <- array(dim = c(num_intervals, num_peers, num_peers))
+
+# read matrix files
+for (i in 1:length(mat_file_list)) {
+       input_file <- paste(matrix_folder, mat_file_list[i], sep="/")
+       speed_array[i,,] <- matrix(scan(input_file, n = num_peers*num_peers), num_peers, num_peers, byrow = TRUE)
+}
+
+# print some data
+for (i in 1:length(mat_file_list)) {
+       print("matrix")
+       print(i)
+       print("sum")
+       print(sum(speed_array[i,,]))
+       print("")
+}