
'''
statistics.py

get the stat from the training data
'''
import sys

import matplotlib.pyplot as plt
import numpy as np

from permission_vector import PERMISSION_LISTS

def load_and_make_stat(filename, analyze_="malware"):
    training_data = np.loadtxt(filename)

    if analyze_ == "malware":
        training_data = training_data[:1260, :150] 
    elif analyze_ == "friendly":
        training_data = training_data[1260:, :150]
    elif analyze_ == "all":
        training_data = training_data[:, :150]
    else:
        raise ValueError("not a valid argument")

    result = [np.sum(training_data[:, i]) for i in range(150)]

    bar_graph = []
    
    for val_pair in sorted(dict(zip(PERMISSION_LISTS, result)).items(), key=lambda x: x[1], reverse=True):
        bar_graph.append(val_pair)

    with plt.style.context('ggplot', after_reset=True):
        x = [i[0] for i in bar_graph][:10]
        y = [i[1] for i in bar_graph][:10]

        plt.bar(np.arange(len(x)), y, align='center', alpha=.5)
        plt.xticks(np.arange(len(x)), x)
        plt.ylabel("Number of Declarations")

        plt.title("Top 10 Permissions Declared by {} Dataset".format(analyze_))
        plt.setp(plt.gca().get_xticklabels(), rotation=30, horizontalalignment='right')
        plt.tight_layout()

        plt.savefig("stat.png", dpi=300)
        
if __name__ == "__main__":
    load_and_make_stat(sys.argv[1], sys.argv[2])




'''
statistics.py

get the stat from the training data
'''
import sys

import matplotlib.pyplot as plt
import numpy as np

from permission_vector import PERMISSION_LISTS

def load_and_make_stat(filename, analyze_="malware"):
    training_data = np.loadtxt(filename)

    if analyze_ == "malware":
        training_data = training_data[:1260, :150] 
    elif analyze_ == "friendly":
        training_data = training_data[1260:, :150]
    elif analyze_ == "all":
        training_data = training_data[:, :150]
    else:
        raise ValueError("not a valid argument")

    result = [np.sum(training_data[:, i]) for i in range(150)]

    bar_graph = []
    
    for val_pair in sorted(dict(zip(PERMISSION_LISTS, result)).items(), key=lambda x: x[1], reverse=True):
        bar_graph.append(val_pair)

    with plt.style.context('ggplot', after_reset=True):
        x = [i[0] for i in bar_graph][:10]
        y = [i[1] for i in bar_graph][:10]

        plt.bar(np.arange(len(x)), y, align='center', alpha=.5)
        plt.xticks(np.arange(len(x)), x)
        plt.ylabel("Number of Declarations")

        plt.title("Top 10 Permissions Declared by {} Dataset".format(analyze_))
        plt.setp(plt.gca().get_xticklabels(), rotation=30, horizontalalignment='right')
        plt.tight_layout()

        plt.savefig("stat.png", dpi=300)
        
if __name__ == "__main__":
    load_and_make_stat(sys.argv[1], sys.argv[2])



statistics.py  get the stat from the training data