Ejemplo n.º 1
0
def get_jobs_plot(graph, start_day, end_day):
    """Return matplotlib plot of the number of jobs of different page-jobs"""
    graph_config = graphs[graph]
    with quota.get_connection() as cursor:
        cursor.execute(graph_config['query'],
                       graph_config['quota'] + (start_day, end_day))
        data = cursor.fetchall()

    jobs_dict = {row['pages']: row['count'] for row in data}
    jobs_count = [jobs_dict.get(i, 0) for i in range(1, graph_config['quota'][0] + 1)]

    return freq_plot(jobs_count, graph_config['title'])
Ejemplo n.º 2
0
def _semester_histogram():
    with get_connection() as c:
        c.execute("SELECT `user`, `semester` FROM `printed` WHERE `semester` > 0")
        users = [SEMESTERLY_QUOTA - int(r["semester"]) for r in c]

    fig = Figure(figsize=(10, 5))
    ax = fig.add_subplot(1, 1, 1)
    ax.locator_params(nbins=20)
    ax.hist(users, bins=list(range(0, 105, 5)))
    ax.grid(True)
    ax.set_xlim(SEMESTERLY_QUOTA, 0)
    ax.set_ylabel("Number of users")
    ax.set_xlabel("Remaining balance")
    ax.set_title("Remaining balances this semester")

    return fig
Ejemplo n.º 3
0
def get_jobs_plot(graph: str, start_day: datetime, end_day: datetime) -> HttpResponse:
    """Return matplotlib plot of the number of jobs of different page-jobs"""
    graph_config = graphs[graph]
    with quota.get_connection() as cursor:
        # Fix mypy error unsupported left operand type for + (Sequence[Any])
        q: Any = graph_config['quota']
        cursor.execute(
            graph_config['query'],
            q + (start_day, end_day),
        )
        data = cursor.fetchall()

    jobs_dict = {row['pages']: row['count'] for row in data}
    jobs_count = [jobs_dict.get(i, 0) for i in range(1, graph_config['quota'][0] + 1)]

    return freq_plot(jobs_count, graph_config['title'])
Ejemplo n.º 4
0
def _semester_histogram():
    with get_connection() as c:
        c.execute(
            'SELECT `user`, `semester` FROM `printed` WHERE `semester` > 0', )
        users = [SEMESTERLY_QUOTA - int(r['semester']) for r in c]

    fig = Figure(figsize=(10, 5))
    ax = fig.add_subplot(1, 1, 1)
    ax.locator_params(nbins=20)
    ax.hist(users, bins=list(range(0, 105, 5)))
    ax.grid(True)
    ax.set_xlim(SEMESTERLY_QUOTA, 0)
    ax.set_ylabel('Number of users')
    ax.set_xlabel('Remaining balance')
    ax.set_title('Remaining balances this semester')

    return fig
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
#!/usr/bin/env python3
"""Print the quota of a user."""
from ocflib.printing.quota import get_connection
from ocflib.printing.quota import get_quota

if __name__ == '__main__':
    with get_connection() as c:
        print(get_quota(c, input('user: ')))
Ejemplo n.º 8
0
#!/usr/bin/env python3
"""Add a test job."""
import getpass
import random
import string
from datetime import datetime

from ocflib.printing.printers import PRINTERS
from ocflib.printing.quota import add_job
from ocflib.printing.quota import get_connection
from ocflib.printing.quota import Job

if __name__ == '__main__':
    user = '******'
    password = getpass.getpass('{} password: '******'user: '******'pages: ')),
                queue=random.choice(('single', 'double')),
                printer=random.choice(tuple(PRINTERS)),
                doc_name=''.join(
                    random.choice(string.ascii_letters) for _ in range(30)),
                filesize=random.randint(0, 2**28),
            ),
        )
Ejemplo n.º 9
0
"""Add a test job."""
import getpass
import random
import string
from datetime import datetime

from ocflib.printing.printers import PRINTERS
from ocflib.printing.quota import add_job
from ocflib.printing.quota import get_connection
from ocflib.printing.quota import Job


if __name__ == '__main__':
    user = '******'
    password = getpass.getpass('{} password: '******'user: '******'pages: ')),
                queue=random.choice(('single', 'double')),
                printer=random.choice(tuple(PRINTERS)),
                doc_name=''.join(
                    random.choice(string.ascii_letters) for _ in range(30)
                ),
                filesize=random.randint(0, 2**28),
            ),
        )
Ejemplo n.º 10
0
#!/usr/bin/env python3
"""Print the quota of a user."""
from ocflib.printing.quota import get_connection
from ocflib.printing.quota import get_quota


if __name__ == "__main__":
    with get_connection() as c:
        print(get_quota(c, input("user: ")))