diff options
author | itraviv <itraviv@cisco.com> | 2017-01-05 19:21:13 +0200 |
---|---|---|
committer | itraviv <itraviv@cisco.com> | 2017-01-08 10:11:36 +0200 |
commit | 37baac1566350407c06dec958db5b0f1a0101e1b (patch) | |
tree | 75f1fbe8f033c0eb0ab01948f177e174bfc20988 /doc | |
parent | 7b0782636460d395f0ec5f4f4e8401e1caa84f65 (diff) |
new TRexDataAnalysis version, with OOP design
Signed-off-by: itraviv <itraviv@cisco.com>
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/AnalyticsWebReport.py | 6 | ||||
-rwxr-xr-x | doc/TRexDataAnalysisV2.py | 185 |
2 files changed, 188 insertions, 3 deletions
diff --git a/doc/AnalyticsWebReport.py b/doc/AnalyticsWebReport.py index 1806cab9..e3f6504b 100755 --- a/doc/AnalyticsWebReport.py +++ b/doc/AnalyticsWebReport.py @@ -1,7 +1,7 @@ import os
import sys
import AnalyticsConnect as ac
-import TRexDataAnalysis as tr
+import TRexDataAnalysisV2 as tr
import time
import datetime
@@ -20,8 +20,8 @@ def main(verbose=False, detailed_test_stats=''): print('Saving data to %s' % dest_path)
if detailed_test_stats:
print('generating detailed table for test results')
- tr.create_all_data(ga_all_data_dict, setups, start_date, current_date, save_path=dest_path,
- add_stats='yes', detailed_test_stats=detailed_test_stats)
+ tr.create_all_data(ga_all_data_dict, start_date, current_date, save_path=dest_path,
+ detailed_test_stats=detailed_test_stats)
if verbose:
print('Done without errors.')
diff --git a/doc/TRexDataAnalysisV2.py b/doc/TRexDataAnalysisV2.py new file mode 100755 index 00000000..e7e82b20 --- /dev/null +++ b/doc/TRexDataAnalysisV2.py @@ -0,0 +1,185 @@ +#!/scratch/Anaconda2.4.0/bin/python
+import pandas as pd
+import numpy as np
+import matplotlib
+
+matplotlib.use('Agg')
+from matplotlib import pyplot as plt
+import os
+import time
+
+
+### TODO: insert a description of a test query
+
+class Test:
+ def __init__(self, name, setup_name):
+ self.name = name
+ self.setup_name = setup_name
+ self.stats = [] # tuple
+ self.results_df = [] # dataFrame
+ self.latest_result = [] # float
+ self.latest_result_date = '' # string
+
+ def analyze_all_test_data(self, raw_test_data):
+ test_results = []
+ test_dates = []
+ test_build_ids = []
+ test_mins = set()
+ test_maxs = set()
+ for query in raw_test_data:
+ test_results.append(float(query[5]))
+ date_formatted = time.strftime("%d-%m-%Y", time.strptime(query[2], "%Y%m%d"))
+ time_of_res = date_formatted + '-' + query[3] + ':' + query[4]
+ test_dates.append(time_of_res)
+ test_build_ids.append(query[8])
+ test_mins.add(float(query[6]))
+ test_maxs.add(float(query[7]))
+ test_results_df = pd.DataFrame({self.name: test_results, (self.name + ' Date'): test_dates,
+ "Setup": ([self.setup_name] * len(test_results)), "Build Id": test_build_ids})
+ stats = tuple(
+ [float(test_results_df[self.name].mean()), min(test_mins), max(test_maxs)]) # stats = (avg_mpps,min,max)
+ self.latest_result = float(test_results_df[self.name].iloc[-1])
+ self.latest_result_date = str(test_results_df[test_results_df.columns[3]].iloc[-1])
+ self.results_df = test_results_df
+ self.stats = stats
+
+
+class Setup:
+ def __init__(self, name, start_date, end_date, raw_setup_data):
+ self.name = name
+ self.start_date = start_date # string of date
+ self.end_date = end_date # string of date
+ self.tests = [] # list of test objects
+ self.all_tests_data_table = pd.DataFrame() # dataframe
+ self.setup_trend_stats = pd.DataFrame() # dataframe
+ self.latest_test_results = pd.DataFrame() # dataframe
+ self.raw_setup_data = raw_setup_data # dictionary
+ self.test_names = raw_setup_data.keys() # list of names
+
+ def analyze_all_tests(self):
+ for test_name in self.test_names:
+ t = Test(test_name, self.name)
+ t.analyze_all_test_data(self.raw_setup_data[test_name])
+ self.tests.append(t)
+
+ def analyze_latest_test_results(self):
+ test_names = []
+ test_dates = []
+ test_latest_results = []
+ for test in self.tests:
+ test_names.append(test.name)
+ test_dates.append(test.latest_result_date)
+ test_latest_results.append(test.latest_result)
+ self.latest_test_results = pd.DataFrame(
+ {'Date': test_dates, 'Test Name': test_names, 'MPPS\Core (Norm)': test_latest_results},
+ index=range(1, len(test_latest_results) + 1))
+ self.latest_test_results = self.latest_test_results[[2, 1, 0]] # re-order columns to name|MPPS|date
+
+ def analyze_all_tests_stats(self):
+ test_names = []
+ all_test_stats = []
+ for test in self.tests:
+ test_names.append(test.name)
+ all_test_stats.append(test.stats)
+ self.setup_trend_stats = pd.DataFrame(all_test_stats, index=test_names,
+ columns=['Avg MPPS/Core (Norm)', 'Golden Min', 'Golden Max'])
+ self.setup_trend_stats.index.name = 'Test Name'
+
+ def analyze_all_tests_trend(self):
+ all_tests_trend_data = []
+ for test in self.tests:
+ all_tests_trend_data.append(test.results_df)
+ self.all_tests_data_table = reduce(lambda x, y: pd.merge(x, y, how='outer'), all_tests_trend_data)
+
+ def plot_trend_graph_all_tests(self, save_path='', file_name='_trend_graph.png'):
+ for test_name in self.test_names:
+ self.all_tests_data_table[test_name].plot()
+ plt.legend(fontsize='small', loc='best')
+ plt.ylabel('MPPS/Core (Norm)')
+ plt.title('Setup: ' + self.name)
+ plt.tick_params(
+ axis='x',
+ which='both',
+ bottom='off',
+ top='off',
+ labelbottom='off')
+ plt.xlabel('Time Period: ' + self.start_date + ' - ' + self.end_date)
+ if save_path:
+ plt.savefig(os.path.join(save_path, self.name + file_name))
+ if not self.setup_trend_stats.empty:
+ (self.setup_trend_stats.round(2)).to_csv(os.path.join(save_path, self.name +
+ '_trend_stats.csv'))
+ plt.close('all')
+
+ def plot_latest_test_results_bar_chart(self, save_path='', img_file_name='_latest_test_runs.png',
+ stats_file_name='_latest_test_runs_stats.csv'):
+ plt.figure()
+ colors_for_bars = ['b', 'g', 'r', 'c', 'm', 'y']
+ self.latest_test_results[[1]].plot(kind='bar', legend=False,
+ color=colors_for_bars) # plot only mpps data, which is in column 1
+ plt.xticks(rotation='horizontal')
+ plt.xlabel('Index of Tests')
+ plt.ylabel('MPPS/Core (Norm)')
+ plt.title("Test Runs for Setup: " + self.name)
+ if save_path:
+ plt.savefig(os.path.join(save_path, self.name + img_file_name))
+ (self.latest_test_results.round(2)).to_csv(
+ os.path.join(save_path, self.name + stats_file_name))
+ plt.close('all')
+
+ def analyze_all_setup_data(self):
+ self.analyze_all_tests()
+ self.analyze_latest_test_results()
+ self.analyze_all_tests_stats()
+ self.analyze_all_tests_trend()
+
+ def plot_all(self, save_path=''):
+ self.plot_latest_test_results_bar_chart(save_path)
+ self.plot_trend_graph_all_tests(save_path)
+
+
+def latest_runs_comparison_bar_chart(setup_name1, setup_name2, setup1_latest_result, setup2_latest_result,
+ save_path=''
+ ):
+ s1_res = setup1_latest_result[[0, 1]] # column0 is test name, column1 is MPPS\Core
+ s2_res = setup2_latest_result[[0, 1, 2]] # column0 is test name, column1 is MPPS\Core, column2 is Date
+ s1_res.columns = ['Test Name', setup_name1]
+ s2_res.columns = ['Test Name', setup_name2, 'Date']
+ compare_dframe = pd.merge(s1_res, s2_res, on='Test Name')
+ compare_dframe.plot(kind='bar')
+ plt.legend(fontsize='small', loc='best')
+ plt.xticks(rotation='horizontal')
+ plt.xlabel('Index of Tests')
+ plt.ylabel('MPPS/Core (Norm)')
+ plt.title("Comparison between " + setup_name1 + " and " + setup_name2)
+ if save_path:
+ plt.savefig(os.path.join(save_path, "_comparison.png"))
+ compare_dframe = compare_dframe.round(2)
+ compare_dframe.to_csv(os.path.join(save_path, '_comparison_stats_table.csv'))
+
+ # WARNING: if the file _all_stats.csv already exists, this script deletes it, to prevent overflowing of data
+
+
+def create_all_data(ga_data, start_date, end_date, save_path='', detailed_test_stats=''):
+ all_setups = {}
+ all_setups_data = []
+ setup_names = ga_data.keys()
+ for setup_name in setup_names:
+ s = Setup(setup_name, start_date, end_date, ga_data[setup_name])
+ s.analyze_all_setup_data()
+ s.plot_all(save_path)
+ all_setups_data.append(s.all_tests_data_table)
+ all_setups[setup_name] = s
+
+ if detailed_test_stats:
+ if os.path.exists(os.path.join(save_path, '_detailed_table.csv')):
+ os.remove(os.path.join(save_path, '_detailed_table.csv'))
+ all_setups_data_dframe = pd.DataFrame().append(all_setups_data)
+ all_setups_data_dframe.to_csv(os.path.join(save_path, '_detailed_table.csv'))
+
+ trex07setup = all_setups['trex07']
+ trex08setup = all_setups['trex08']
+ latest_runs_comparison_bar_chart('Mellanox ConnectX-4',
+ 'Intel XL710', trex07setup.latest_test_results,
+ trex08setup.latest_test_results,
+ save_path=save_path)
|