LEFT | RIGHT |
1 import os | 1 import os |
2 import exceptions | 2 import exceptions |
3 | 3 |
4 from matplotlib import * | 4 import matplotlib |
5 matplotlib.use('Agg') | 5 matplotlib.use('Agg') |
6 import matplotlib.pyplot as plt | 6 import matplotlib.pyplot as plt |
7 | 7 |
8 from datetime import datetime | 8 from datetime import datetime |
9 | 9 |
10 def plot_score_data(conf, target_folder): | 10 def plot_score_data(conf, target_folder): |
11 """ | 11 """ |
12 :param conf: | 12 :param conf: |
13 :param target_folder: The folder with the CSVs | 13 :param target_folder: The folder with the CSVs |
14 :param save_score: | 14 :param save_score: |
15 :param title: | 15 :param title: |
16 :return: | 16 :return: |
17 """ | 17 """ |
18 number_of_cassandra_nodes = conf['server2dc_map'][0] # Assume only one DC | 18 # Assume only one DC |
19 if not number_of_cassandra_nodes == 1: | 19 number_of_cassandra_nodes = conf['cassandra']['server2dc_map'][0] |
| 20 if not number_of_cassandra_nodes == 3: |
20 raise exceptions.Exception('This feature do not work with > 1 DC') | 21 raise exceptions.Exception('This feature do not work with > 1 DC') |
21 | 22 |
22 for i in range(0, number_of_cassandra_nodes + 1): | 23 for i in range(1, number_of_cassandra_nodes + 1): |
23 csv_to_read = 'score_vs_lateny_cas_{0}.csv'.format(i) | 24 csv_to_read = 'score_vs_lateny_cas_{0}.csv'.format(i) |
24 with open(os.path.join(target_folder, csv_to_read)) as csv_file: | 25 with open(os.path.join(target_folder, csv_to_read)) as csv_file: |
25 x = [] | 26 x = [] |
26 y = [] | 27 y = [] |
27 for line in csv_file.readlines()[1:]: | 28 for line in csv_file.readlines()[1:]: |
28 utc_dt, ip_address, score = line.strip().split(",") | 29 utc_dt, ip_address, score = line.strip().split(",") |
29 parsed_t = datetime.strptime(utc_dt, '%Y-%m-%dT%H:%M:%S,%f') | 30 parsed_t = datetime.strptime(utc_dt, '%Y-%m-%dT%H:%M:%S,%f') |
30 time_sec = parsed_t.strftime('%s') | 31 time_sec = parsed_t.strftime('%s') |
31 x.append(float(time_sec)) | 32 x.append(float(time_sec)) |
32 y.append(score) | 33 y.append(score) |
33 plt.plot(x, y, '-', label='cas-{}'.format(i)) | 34 plt.plot(x, y, '-', label='cas-{}'.format(i)) |
34 plt.ylabel('Score') | 35 plt.ylabel('Score') |
35 plt.xlabel('Timestamp') | 36 plt.xlabel('Timestamp') |
36 plt.title('Timestamp vs Score for cas-{0}'.format(i)) | 37 plt.title('Timestamp vs Score for cas-{0}'.format(i)) |
37 plt.savefig( | 38 plt.savefig( |
38 os.path.join(target_folder, 'cas-{0}-time_vs_score.png'.form
at(i)) | 39 os.path.join(target_folder, 'cas-{0}-time_vs_score.png'.form
at(i)) |
39 ) | 40 ) |
40 plt.close() | 41 plt.close() |
LEFT | RIGHT |