import pandas as pd
from log_parse import LogParse


def show_aggie_pride():
    # https://pandas.pydata.org/docs/user_guide/index.html

    df = pd.DataFrame(['Aggie Pride', 'Worldwide', 'Hard Work Yields Results',
                       'Work today for what you want to achieve tomorrow', 'Aggies DO!',
                       'Giving Back Every Day, the Aggie Way', 'Aggies Rule',
                       'When One Door Closes Another One Opens', 'Aggie Pride',
                       'Aggies on fire', 'Aggies Do!'], columns=['Text'])

    return df


def parse_logs():
    parser = LogParse()
    df = parser.parse_syslog_file('syslogs.txt')
    print('Total syslog found', end=': ')
    print(len(df))


def asa_parse():
    # Parse the ASA logfile
    parser = LogParse()
    df = parser.parse_asa_logfile('dmz1_logs.txt')
    print(df.describe())

    # Create a table by hour with the total count of messages seen
    table = df.groupby([pd.Grouper(key='Date', freq='H')]).agg({'ID': 'count'})

    # Create a simple plot and save as a png
    fig = table.plot().get_figure()
    fig.savefig('plot.png')


def team1_asa_parse():
    # Parse the ASA logfile
    parser = LogParse()
    df = parser.parse_asa_logfile('dmz1_logs.txt')
    dft1 = df[df['ID'].isin(['114017', '114013', '114012'])]
    print(dft1.describe())

    # Create a table by hour with the total count of messages seen
    table = dft1.groupby([pd.Grouper(key='Date', freq='H')]).agg({'ID': 'count'})

    # Create a simple plot and save as a png
    fig = table.plot().get_figure()
    fig.savefig('team1plot.png')


def team2_asa_parse():
    # Parse the ASA logfile
    parser = LogParse()
    df = parser.parse_asa_logfile('dmz1_logs.txt')
    dft2 = df[df['ID'].isin(['114011', '114007', '114015'])]
    print(dft2.describe())

    # Create a table by hour with the total count of messages seen
    table = dft2.groupby([pd.Grouper(key='Date', freq='H')]).agg({'ID': 'count'})

    # Create a simple plot and save as a png
    fig = table.plot().get_figure()
    fig.savefig('team2.png')


if __name__ == "__main__":
    print(show_aggie_pride())

    print('\nCalling parse_logs()')
    parse_logs()
    # Uncomment when we start sprint-4
    print('\nCalling asa_parse()')
    asa_parse()
    print('\nCalling team1_asa_parse')
    team1_asa_parse()
    print('\nCalling team2_asa_parse')
    team2_asa_parse()
