#!/usr/bin/python
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from stats import parse_results, get_percentage, get_avg_per_seed, draw_pie, draw_bars, draw_bars_comparison, draw_avgs

"""
Explanation: Generalized Watts-Strogatz Graph Experiments Output Visualization
End of explanation
"""


pr, eigen, bet = parse_results('test_genws.txt')

"""
Explanation: Parse results
End of explanation
"""


draw_pie(get_percentage(pr))

"""
Explanation: PageRank Seeds Percentage
How many times the "Top X" nodes from PageRank have led to the max infection
End of explanation
"""


draw_bars_comparison('Avg adopters per seeds', 'Avg adopters', np.array(get_avg_per_seed(pr)+[(0, np.mean(pr[:,1]))]))

"""
Explanation: Avg adopters per seed comparison
End of explanation
"""


draw_pie(get_percentage(eigen))

"""
Explanation: Eigenvector Seeds Percentage
How many times the "Top X" nodes from Eigenvector have led to the max infection
End of explanation
"""


draw_bars_comparison('Avg adopters per seeds', 'Avg adopters', np.array(get_avg_per_seed(eigen)+[(0, np.mean(eigen[:,1]))]))

"""
Explanation: Avg adopters per seed comparison
End of explanation
"""


draw_pie(get_percentage(bet))

"""
Explanation: Betweenness Seeds Percentage
How many times the "Top X" nodes from Betweenness have led to the max infection
End of explanation
"""


draw_bars_comparison('Avg adopters per seeds', 'Avg adopters', np.array(get_avg_per_seed(bet)+[(0, np.mean(bet[:,1]))]))

"""
Explanation: Avg adopters per seed comparison
End of explanation
"""


draw_bars(np.sort(pr.view('i8,i8'), order=['f0'], axis=0).view(np.int),
         np.sort(eigen.view('i8,i8'), order=['f0'], axis=0).view(np.int),
         np.sort(bet.view('i8,i8'), order=['f0'], axis=0).view(np.int))

"""
Explanation: 100 runs adopters comparison
End of explanation
"""


pr_mean = np.mean(pr[:,1])
pr_mean_seed = np.mean(pr[:,0])
print 'Avg Seed:',pr_mean_seed, 'Avg adopters:', pr_mean

"""
Explanation: Centrality Measures Averages
PageRank avg adopters and seed
End of explanation
"""


eigen_mean = np.mean(eigen[:,1])
eigen_mean_seed = np.mean(eigen[:,0])
print 'Avg Seed:',eigen_mean_seed, 'Avg adopters:',eigen_mean

"""
Explanation: Eigenv avg adopters and seed
End of explanation
"""


bet_mean = np.mean(bet[:,1])
bet_mean_seed = np.mean(bet[:,0])
print 'Avg Seed:',bet_mean_seed, 'Avg adopters:',bet_mean

draw_avgs([pr_mean, eigen_mean, bet_mean])

"""
Explanation: Betweenness avg adopters and seed
End of explanation
"""


