OLD | NEW |
(Empty) | |
| 1 import os |
| 2 import exceptions |
| 3 |
| 4 import matplotlib |
| 5 matplotlib.use('Agg') |
| 6 import matplotlib.pyplot as plt |
| 7 |
| 8 |
| 9 def extract_values(line): |
| 10 time, ip_address, score = line.strip().split(",") |
| 11 return [time, ip_address, score] |
| 12 |
| 13 |
| 14 def fetch_timestamp_from_latency_update(conf): |
| 15 filename_dir = conf["env"]["out_exp_dir"] |
| 16 filename = os.path.join(filename_dir, |
| 17 'plot_data/latency_data/h1.2-s1-data.txt') |
| 18 with open(filename) as ping_f: |
| 19 lines = ping_f.readlines() |
| 20 first_line = lines[0] |
| 21 last_line = lines[-1] |
| 22 first_timestamp = first_line.split(",")[1] |
| 23 last_timestamp = last_line.split(",")[1] |
| 24 return [first_timestamp, last_timestamp] |
| 25 |
| 26 |
| 27 # plot score with running multiconf_sleep_time, task 2.1 |
| 28 def plot_score_data(conf, target_folder): |
| 29 """ |
| 30 :param conf: |
| 31 :param target_folder: The folder with the CSVs |
| 32 :param save_score: |
| 33 :param title: |
| 34 :return: |
| 35 """ |
| 36 # Assume only one DC |
| 37 |
| 38 number_of_cassandra_nodes = conf['cassandra']['server2dc_map'][0] |
| 39 if not number_of_cassandra_nodes == 3: |
| 40 raise exceptions.Exception('This feature do not work with > 1 DC') |
| 41 |
| 42 for i in range(1, number_of_cassandra_nodes + 1): |
| 43 csv_to_read = 'log.cas1.{0}_run_with_latency.csv'.format(i) |
| 44 with open(os.path.join(target_folder, csv_to_read)) as csv_file: |
| 45 x_1 = [] |
| 46 y_1 = [] |
| 47 x_2 = [] |
| 48 y_2 = [] |
| 49 x_3 = [] |
| 50 y_3 = [] |
| 51 lines = csv_file.readlines()[1:] |
| 52 start_timestamp, end_timestamp = fetch_timestamp_from_latency_update
( |
| 53 conf=conf) |
| 54 for line in lines: |
| 55 timestamp, ip, score = extract_values(line) |
| 56 #only plot scores during the select ping time |
| 57 if float(start_timestamp) < float(timestamp) < float( |
| 58 end_timestamp): |
| 59 if ip == "10.0.1.1": |
| 60 x_1.append(float(timestamp) - float(start_timestamp)) |
| 61 y_1.append(float(score)) |
| 62 elif ip == "10.0.1.2": |
| 63 x_2.append(float(timestamp) - float(start_timestamp)) |
| 64 y_2.append(float(score)) |
| 65 elif ip == "10.0.1.3": |
| 66 x_3.append(float(timestamp) - float(start_timestamp)) |
| 67 y_3.append(float(score)) |
| 68 else: |
| 69 print("IP value error: " + ip) |
| 70 |
| 71 plt.plot(x_1, y_1, '-', label='host1.1', color='green') |
| 72 plt.plot(x_2, y_2, '-', label='host1.2', color='orange') |
| 73 plt.plot(x_3, y_3, '-', label='host1.3', color='red') |
| 74 plt.legend( |
| 75 ) #change label attribute: loc='upper center', fontsize='x-small' |
| 76 plt.ylabel('Score') |
| 77 plt.xlabel('Runtime [s]') |
| 78 plt.title('Time vs Score for cas-{0}'.format(i)) |
| 79 plt.savefig( |
| 80 os.path.join(target_folder, |
| 81 'cas1.{0}-time_vs_score.png'.format(i))) |
| 82 plt.close() |
| 83 |
| 84 |
| 85 def plot_score_data_jitter(conf, target_folder): |
| 86 """ |
| 87 :param conf: |
| 88 :param target_folder: The folder with the CSVs |
| 89 :param save_score: |
| 90 :param title: |
| 91 :return: |
| 92 """ |
| 93 # Assume only one DC |
| 94 |
| 95 number_of_cassandra_nodes = conf['cassandra']['server2dc_map'][0] |
| 96 if not number_of_cassandra_nodes == 3: |
| 97 raise exceptions.Exception('This feature do not work with > 1 DC') |
| 98 |
| 99 for i in range(1, number_of_cassandra_nodes + 1): |
| 100 csv_to_read = 'log.cas1.{0}_run_with_latency_and_jitter.csv'.format(i) |
| 101 with open(os.path.join(target_folder, csv_to_read)) as csv_file: |
| 102 x_1 = [] |
| 103 y_1 = [] |
| 104 x_2 = [] |
| 105 y_2 = [] |
| 106 x_3 = [] |
| 107 y_3 = [] |
| 108 lines = csv_file.readlines()[1:] |
| 109 start_timestamp, end_timestamp = fetch_timestamp_from_latency_update
( |
| 110 conf=conf) |
| 111 for line in lines: |
| 112 timestamp, ip, score = extract_values(line) |
| 113 #only plot scores during the select ping time |
| 114 if float(start_timestamp) < float(timestamp) < float( |
| 115 end_timestamp): |
| 116 if ip == "10.0.1.1": |
| 117 x_1.append(float(timestamp) - float(start_timestamp)) |
| 118 y_1.append(float(score)) |
| 119 elif ip == "10.0.1.2": |
| 120 x_2.append(float(timestamp) - float(start_timestamp)) |
| 121 y_2.append(float(score)) |
| 122 elif ip == "10.0.1.3": |
| 123 x_3.append(float(timestamp) - float(start_timestamp)) |
| 124 y_3.append(float(score)) |
| 125 else: |
| 126 print("IP value error: " + ip) |
| 127 |
| 128 plt.plot(x_1, y_1, '-', label='host1.1', color='green') |
| 129 plt.plot(x_2, y_2, '-', label='host1.2', color='orange') |
| 130 plt.plot(x_3, y_3, '-', label='host1.3', color='red') |
| 131 plt.legend( |
| 132 ) #change label attribute: loc='upper center', fontsize='x-small' |
| 133 plt.ylabel('Score') |
| 134 plt.xlabel('Runtime [s]') |
| 135 plt.title('Time vs Score for cas-{0}'.format(i)) |
| 136 plt.savefig( |
| 137 os.path.join(target_folder, |
| 138 'cas1.{0}-time_vs_score.png'.format(i))) |
| 139 plt.close() |
OLD | NEW |