102b2d821Sitravivimport os
202b2d821Sitravivimport sys
302b2d821Sitravivimport ELKConnect as ec
402b2d821Sitravivimport AnalyticsConnect as ac
5bfb5a276Sitravivimport TRexDataAnalysis as tr
602b2d821Sitravivimport time
702b2d821Sitravivimport datetime
802b2d821Sitraviv
902b2d821Sitraviv
1002b2d821Sitravivdef main(verbose=False, source='elk', detailed_test_stats='yes'):
1102b2d821Sitraviv    current_date = time.strftime("%Y-%m-%d")
1202b2d821Sitraviv    k_days_ago = datetime.datetime.now() - datetime.timedelta(days=15)
1302b2d821Sitraviv    start_date = str(k_days_ago.date())
1402b2d821Sitraviv    if source == 'ga':
1502b2d821Sitraviv        if verbose:
1602b2d821Sitraviv            print('Retrieving data from Google Analytics')
1702b2d821Sitraviv        analytics = ac.initialize_analyticsreporting()
1802b2d821Sitraviv        response = ac.get_report(analytics, start_date, current_date)
1902b2d821Sitraviv        all_data_dict, setups = ac.export_to_tuples(response)
2002b2d821Sitraviv    if source == 'elk':
2144972cd9Sitraviv        elk_manager = ec.ELKManager(hostname='sceasr-b20', index='trex_perf-*', port=9200)
2202b2d821Sitraviv        all_data_dict = elk_manager.fetch_and_parse()
2302b2d821Sitraviv    dest_path = os.path.join(os.getcwd(), 'build', 'images')
2402b2d821Sitraviv    if verbose:
2502b2d821Sitraviv        print('Saving data to %s' % dest_path)
2602b2d821Sitraviv        if detailed_test_stats:
2702b2d821Sitraviv            print('generating detailed table for test results')
2802b2d821Sitraviv    tr.create_all_data(all_data_dict, current_date, save_path=dest_path,
2902b2d821Sitraviv                       detailed_test_stats=detailed_test_stats)
3002b2d821Sitraviv    if verbose:
3102b2d821Sitraviv        print('Done without errors.')
3202b2d821Sitraviv
3302b2d821Sitraviv
3402b2d821Sitravivif __name__ == "__main__":
3502b2d821Sitraviv    main()
36