1import os
2import sys
3import ELKConnect as ec
4import AnalyticsConnect as ac
5import TRexDataAnalysis as tr
6import time
7import datetime
8
9
10def main(verbose=False, source='elk', detailed_test_stats='yes'):
11    current_date = time.strftime("%Y-%m-%d")
12    k_days_ago = datetime.datetime.now() - datetime.timedelta(days=15)
13    start_date = str(k_days_ago.date())
14    if source == 'ga':
15        if verbose:
16            print('Retrieving data from Google Analytics')
17        analytics = ac.initialize_analyticsreporting()
18        response = ac.get_report(analytics, start_date, current_date)
19        all_data_dict, setups = ac.export_to_tuples(response)
20    if source == 'elk':
21        elk_manager = ec.ELKManager(hostname='sceasr-b20', index='trex_perf-*', port=9200)
22        all_data_dict = elk_manager.fetch_and_parse()
23    dest_path = os.path.join(os.getcwd(), 'build', 'images')
24    if verbose:
25        print('Saving data to %s' % dest_path)
26        if detailed_test_stats:
27            print('generating detailed table for test results')
28    tr.create_all_data(all_data_dict, current_date, save_path=dest_path,
29                       detailed_test_stats=detailed_test_stats)
30    if verbose:
31        print('Done without errors.')
32
33
34if __name__ == "__main__":
35    main()
36