示例#1
0
def get_jobs_plot(day: date) -> Figure:
    """Return matplotlib plot showing the number i-page-job to the day."""

    day_of_week: int = pyday_to_sqlday(day.weekday())
    day_quota: int = quota.daily_quota(
        datetime.combine(day, datetime.min.time()))

    sql_today_freq = '''
    SELECT `pages`,  SUM(`count`) AS `count`
    FROM `public_jobs`
    WHERE
        (`pages` <= %s) AND
        (DAYOFWEEK(`day`) = %s) AND
        (`day` = %s )
    GROUP BY `pages`
    ORDER BY `pages` ASC
    '''

    # executing the sql query to get the data
    with quota.get_connection() as cursor:
        cursor.execute(sql_today_freq, (day_quota, day_of_week, day))
        today_freq_data = cursor.fetchall()

    # converting the data into a list
    today_jobs_dict = {row['pages']: row['count'] for row in today_freq_data}
    today_jobs_count = [
        today_jobs_dict.get(i, 0) for i in range(1, day_quota + 1)
    ]

    # Generating the plot
    fig = Figure(figsize=(10, 4))
    ax = fig.add_subplot(1, 1, 1)

    tickLocations = np.arange(1, day_quota + 1)
    width = 0.8
    ax.bar(tickLocations, today_jobs_count, width)

    ax.set_xticks(ticks=tickLocations)
    ax.yaxis.set_major_locator(MaxNLocator(integer=True))
    ax.yaxis.grid(True)
    ax.set_ylim(bottom=0)
    ax.set_ylabel('Number of Jobs Printed')
    ax.set_title(f'Print Job Distribution {day:%a %b %d}')

    return fig
示例#2
0
def get_jobs_plot(day):
    """Return matplotlib plot showing the number i-page-job to the day."""

    day_of_week = pyday_to_sqlday(day.weekday())
    day_quota = quota.daily_quota(datetime.combine(day, datetime.min.time()))

    sql_today_freq = '''
    SELECT `pages`,  SUM(`count`) AS `count`
    FROM `public_jobs`
    WHERE
        (`pages` <= %s) AND
        (DAYOFWEEK(`day`) = %s) AND
        (`day` = %s )
    GROUP BY `pages`
    ORDER BY `pages` ASC
    '''

    # executing the sql query to get the data
    with quota.get_connection() as cursor:
        cursor.execute(sql_today_freq, (day_quota, day_of_week, day))
        today_freq_data = cursor.fetchall()

    # converting the data into a list
    today_jobs_dict = {row['pages']: row['count'] for row in today_freq_data}
    today_jobs_count = [today_jobs_dict.get(i, 0) for i in range(1, day_quota + 1)]

    # Generating the plot
    fig = Figure(figsize=(10, 4))
    ax = fig.add_subplot(1, 1, 1)

    tickLocations = np.arange(1, day_quota + 1)
    width = 0.8
    ax.bar(tickLocations, today_jobs_count, width)

    ax.set_xticks(ticks=tickLocations)
    ax.yaxis.set_major_locator(MaxNLocator(integer=True))
    ax.yaxis.grid(True)
    ax.set_ylim(ymin=0)
    ax.set_ylabel('Number of Jobs Printed')
    ax.set_title('Print Job Distribution {:%a %b %d}'.format(day))

    return fig
示例#3
0
def test_daily_quota(time, expected):
    """Test that the daily quota returns reasonable things."""
    time = datetime.strptime(time, '%Y-%m-%d')
    with freeze_time(time):
        assert daily_quota() == expected
    assert daily_quota(time) == expected
示例#4
0
def test_daily_quota(time, expected):
    """Test that the daily quota returns reasonable things."""
    time = datetime.strptime(time, '%Y-%m-%d')
    with freeze_time(time):
        assert daily_quota() == expected
    assert daily_quota(time) == expected