Merges George changes
[p2p-testing-infrastructure.git] / ControlScripts / up_down_matrix_reader.R
1 # R script to read peer-connection upload/download speed matrix files
2 #
3 # 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
4 #
5 # Sample run (run parse_up_down_log.sh script before running this script)
6 #     Rscript up_down_matrix_reader.R --args ../Results/samples/ down_mat_files.lst updown_peer_index.cfg ../Results/samples/down
7
8
9 # Read transmitted command line arguments
10 args <- commandArgs(trailingOnly = TRUE)
11
12 target_folder <- args[2]
13 mat_file_list_file <- args[3]
14 peer_index_file <- args[4]
15 matrix_folder <- args[5]
16 rm(args)
17
18 # read list matrix files
19 mat_file_list <- scan(paste(target_folder, mat_file_list_file, sep="/"), what='character')
20
21 # read list of peers
22 peers <- scan(paste(target_folder, peer_index_file, sep="/"), list(0, ""))
23
24 num_peers <- length(peers[[1]])
25 num_intervals <- length(mat_file_list)
26
27 "num_peers"
28 num_peers
29 "num_intervals"
30 num_intervals
31
32 # allocate array of matrices
33 speed_array <- array(dim = c(num_intervals, num_peers, num_peers))
34
35 # read matrix files
36 for (i in 1:length(mat_file_list)) {
37         input_file <- paste(matrix_folder, mat_file_list[i], sep="/")
38         speed_array[i,,] <- matrix(scan(input_file, n = num_peers*num_peers), num_peers, num_peers, byrow = TRUE)
39 }
40
41 # print some data
42 for (i in 1:length(mat_file_list)) {
43         print("matrix")
44         print(i)
45         print("sum")
46         print(sum(speed_array[i,,]))
47         print("")
48 }