# -*- coding:utf-8 -*-

import time
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker

def draw_weekly_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='D')).count()["_id"]

    # plot data
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar")
    pic.set_title("weekly newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("day")
    pic.set_xticklabels(stats.index.strftime('%a'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename


def draw_quarterly_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='W-MON')).count()["_id"]

    # plot data
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar", color="green")
    pic.set_title("quarterly newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("week")
    pic.set_xticklabels(stats.index.strftime('%b %d'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename

def draw_all_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()["_id"]

    # draw graph
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar", color="orange")
    pic.set_title("overall newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("month")
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename

c958d723781af22b2c6af2c46c18d4e68a77b987
<mask token>


def draw_all_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='orange')
    pic.set_title('overall newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('month')
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename

<mask token>


def draw_quarterly_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='W-MON')).count()[
        '_id']
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='green')
    pic.set_title('quarterly newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('week')
    pic.set_xticklabels(stats.index.strftime('%b %d'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename


def draw_all_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='orange')
    pic.set_title('overall newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('month')
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename

<mask token>


def draw_weekly_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='D')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar')
    pic.set_title('weekly newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('day')
    pic.set_xticklabels(stats.index.strftime('%a'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename


def draw_quarterly_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='W-MON')).count()[
        '_id']
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='green')
    pic.set_title('quarterly newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('week')
    pic.set_xticklabels(stats.index.strftime('%b %d'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename


def draw_all_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='orange')
    pic.set_title('overall newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('month')
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename

import time
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker


def draw_weekly_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='D')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar')
    pic.set_title('weekly newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('day')
    pic.set_xticklabels(stats.index.strftime('%a'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename


def draw_quarterly_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='W-MON')).count()[
        '_id']
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='green')
    pic.set_title('quarterly newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('week')
    pic.set_xticklabels(stats.index.strftime('%b %d'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename


def draw_all_data(data, filename):
    if data is None:
        return ''
    data = list(data)
    if len(data) == 0:
        return ''
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()['_id'
        ]
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind='bar', color='orange')
    pic.set_title('overall newbies statistics')
    pic.set_ylabel('# of newbies')
    pic.set_xlabel('month')
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()
    return filename

# -*- coding:utf-8 -*-

import time
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker

def draw_weekly_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='D')).count()["_id"]

    # plot data
    fig, ax = plt.subplots(figsize=(8, 6))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar")
    pic.set_title("weekly newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("day")
    pic.set_xticklabels(stats.index.strftime('%a'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename


def draw_quarterly_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='W-MON')).count()["_id"]

    # plot data
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar", color="green")
    pic.set_title("quarterly newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("week")
    pic.set_xticklabels(stats.index.strftime('%b %d'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename

def draw_all_data(data, filename):
    if data is None:
        return ""
    data = list(data)
    if len(data) == 0:
        return ""

    # get stats
    df = pd.DataFrame(data)
    stats = df.set_index('updated').groupby(pd.Grouper(freq='M')).count()["_id"]

    # draw graph
    fig, ax = plt.subplots(figsize=(13, 7))
    ax.yaxis.set_major_locator(mticker.MaxNLocator(integer=True))
    pic = stats.plot(kind="bar", color="orange")
    pic.set_title("overall newbies statistics")
    pic.set_ylabel("# of newbies")
    pic.set_xlabel("month")
    pic.set_xticklabels(stats.index.strftime('%Y/%m'))

    # save to image
    fig.autofmt_xdate()
    plt.savefig(filename)
    plt.clf()

    return filename
