<commit_before>import datetime
import pandas
from collections import Counter
from sqlalchemy import create_engine
import os
engine = create_engine('mysql://{}:{}@{}'.format(os.environ["DB_USERNAME"], os.environ["DB_PASSWORD"], os.environ["DB_CONNECTION_STRING"]), echo=False)
def stats(response, args):
    if args[0] == 'time':
        if len(args)!=4:
            return ["ERROR: Please use the following syntax `time <channel> 2/1/17 5/1/18`"]
        return generate_time_graph(args[2::], args[1])

    if args[0] == 'top_users':
        pass

    if args[0] == 'emoji':
        pass

    if args[0] == 'channel':
        pass

    if args[0] == 'help':
        return ["""*List of arguments for GenerateReport (g_r)*
```
time (g_r time random 12/01/15 5/01/17)
    -- Returns time related data on the channel specified, if none given
    then default is slack-wide.
    -- Takes 3 arguments: <channel> <begin date> <end date>```
        """]

def generate_time_graph(range, channel='all'):
    try:
        date_list = [datetime.datetime.strptime(x, "%m/%d/%y").date() for x in range]
    except ValueError:
        return ["Please input time in the syntax of mm/dd/yy"]
    hour_count = None
    if channel == 'all':
        hour_count = engine.execute("SELECT hour FROM channelActivity WHERE day_of_month >= %s and day_of_month <= %s and month >= %s and month <= %s and year >= %s and year <= %s", date_list[0].day, date_list[1].day, date_list[0].month, date_list[1].month, date_list[0].year, date_list[1].year).fetchall()
    else:
        hour_count = engine.execute("SELECT hour FROM channelActivity WHERE channel_id = (SELECT slack_id FROM channels WHERE name = %s) and day_of_month >= %s and day_of_month <= %s and month >= %s and month <= %s and year >= %s and year <= %s", channel, date_list[0].day, date_list[1].day, date_list[0].month, date_list[1].month, date_list[0].year, date_list[1].year).fetchall()

    counter = Counter()
    for hc in hour_count:
        counter[hc[0]] += 1

    hour=range(0, 24)
    count=[counter[h] for h in hour]

    df = pandas.DataFrame({'Count':count}, index=hour)
    df.columns.name = 'Hour'
    return [str(df)]
 <commit_msg>santizes command and breaks up components<commit_after>import datetime
import pandas
from collections import Counter
from sqlalchemy import create_engine
import os
#top_users random 10
#top_users all 10 --emoji
#top_users random --emoji
engine = create_engine('mysql://{}:{}@{}'.format(os.environ["DB_USERNAME"], os.environ["DB_PASSWORD"], os.environ["DB_CONNECTION_STRING"]), echo=False)
def stats(response, args):
    if args[0] == 'time':
        if len(args)!=4:
            return ["ERROR: Please use the following syntax `time <channel> 2/1/17 5/1/18`"]
        return generate_time_graph(args[2::], args[1])

    if args[0] == 'top_users':
        get_emoji_stats = False
        channel = args[1]
        index = 3
        try:
            index = int(args[3])
        except ValueError:
            get_emoji_stats = True

        collect_top_users(index, channel, get_emoji_stats)

        pass

    if args[0] == 'emoji':
        pass

    if args[0] == 'channel':
        pass

    if args[0] == 'help':
        return ["""*List of arguments for GenerateReport (g_r)*
```
time (g_r time random 12/01/15 5/01/17)
    -- Returns time related data on the channel specified, if none given
    then default is slack-wide.
    -- Takes 3 arguments: <channel> <begin date> <end date>```
        """]

def generate_time_graph(range, channel='all'):
    try:
        date_list = [datetime.datetime.strptime(x, "%m/%d/%y").date() for x in range]
    except ValueError:
        return ["Please input time in the syntax of mm/dd/yy"]
    hour_count = None
    if channel == 'all':
        hour_count = engine.execute("SELECT hour FROM channelActivity WHERE day_of_month >= %s and day_of_month <= %s and month >= %s and month <= %s and year >= %s and year <= %s", date_list[0].day, date_list[1].day, date_list[0].month, date_list[1].month, date_list[0].year, date_list[1].year).fetchall()
    else:
        hour_count = engine.execute("SELECT hour FROM channelActivity WHERE channel_id = (SELECT slack_id FROM channels WHERE name = %s) and day_of_month >= %s and day_of_month <= %s and month >= %s and month <= %s and year >= %s and year <= %s", channel, date_list[0].day, date_list[1].day, date_list[0].month, date_list[1].month, date_list[0].year, date_list[1].year).fetchall()

    counter = Counter()
    for hc in hour_count:
        counter[hc[0]] += 1

    hour=range(0, 24)
    count=[counter[h] for h in hour]

    df = pandas.DataFrame({'Count':count}, index=hour)
    df.columns.name = 'Hour'
    return [str(df)]
 

def collect_top_users(index, channel, get_emoji_stats):




{'fraction_non_alphanumeric': 0.1454354669464848, 'fraction_numerical': 0.020356768100734522, 'mean_word_length': 3.3485401459854014, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1152347', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1547, 'n_words': 455}