<commit_before># Copyright 2016, 2017 <NAME> and <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
Provides functions for querying the server for information and printing the
query results.
"""
from time import time, localtime, strftime

from gkeepclient.client_function_decorators import config_parsed, \
    server_interface_connected
from gkeepclient.server_interface import server_interface


@config_parsed
@server_interface_connected
def list_classes():
    """Print the names of all the classes owned by the faculty."""

    for class_name in server_interface.get_classes():
        print(class_name)


@config_parsed
@server_interface_connected
def list_assignments():
    """
    Print the names of all the assignments owned by the faculty, grouped by
    class.
    """

    info = server_interface.get_info()

    for class_name in sorted(info.class_list()):
        print(class_name, ':', sep='')

        for assignment_name in sorted(info.assignment_list(class_name)):
            published = info.is_published(class_name, assignment_name)

            if published:
                published_prefix = 'P'
            else:
                published_prefix = 'U'

            print(published_prefix, assignment_name)

        print()


@config_parsed
@server_interface_connected
def list_students():
    """
    Print all the students in classes owned by the faculty, grouped by class.
    """

    for class_name in server_interface.get_classes():
        print(class_name, ':', sep='')

        for student in server_interface.get_students(class_name):
            print(student)

        print()


@config_parsed
@server_interface_connected
def list_recent(number_of_days):
    """
    Print recent submissions.

    :param number_of_days: submissions past this number of days ago are not
     recent
    """

    if number_of_days is None:
        number_of_days = 1

    print('Recent submissions:')
    print()

    info = server_interface.get_info()


    for class_name in sorted(info.class_list()):
        class_name_printed = False

        for assignment_name in sorted(info.assignment_list(class_name)):
            students_submitted = info.students_submitted_list(class_name,
                                                              assignment_name)

            if students_submitted is None:
                continue

            cutoff_time = time() - (60 * 60 * 24 * number_of_days)

            recent = []

            for username in students_submitted:<commit_msg>Improve query speed<commit_after># Copyright 2016, 2017 <NAME> and <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
Provides functions for querying the server for information and printing the
query results.
"""
from time import time, localtime, strftime

from gkeepclient.client_function_decorators import config_parsed, \
    server_interface_connected
from gkeepclient.server_interface import server_interface


@config_parsed
@server_interface_connected
def list_classes():
    """Print the names of all the classes owned by the faculty."""

    class_list = sorted(server_interface.get_info().class_list())

    for class_name in class_list:
        print(class_name)


@config_parsed
@server_interface_connected
def list_assignments():
    """
    Print the names of all the assignments owned by the faculty, grouped by
    class.
    """

    info = server_interface.get_info()

    for class_name in sorted(info.class_list()):
        print(class_name, ':', sep='')

        for assignment_name in sorted(info.assignment_list(class_name)):
            published = info.is_published(class_name, assignment_name)

            if published:
                published_prefix = 'P'
            else:
                published_prefix = 'U'

            print(published_prefix, assignment_name)

        print()


@config_parsed
@server_interface_connected
def list_students():
    """
    Print all the students in classes owned by the faculty, grouped by class.
    """

    class_list = server_interface.get_info().class_list()

    for class_name in sorted(class_list):
        print(class_name, ':', sep='')

        student_list = server_interface.get_info().student_list(class_name)

        for student in sorted(student_list):
            print(student)

        print()


@config_parsed
@server_interface_connected
def list_recent(number_of_days):
    """
    Print recent submissions.

    :param number_of_days: submissions past this number of days ago are not
     recent
    """

    if number_of_days is None:
        number_of_days = 1

    print('Recent submissions:')
    print()

    info = server_interface.get_info()

    for class_name in sorted(info.class_list()):
        class_name_printed = False

        for assignment_name in sorted(info.assignment_list(class_name)):
            students_submitted = info.students_submitted_list(class_name,
                                                              assignment_name)

            if students_submitted is None:
                continue

            cutoff_time = time() - (60 * 60 * 24 * number_of_days)

            recent = []

            for username in students_submitted:
{'fraction_non_alphanumeric': 0.07415553809897879, 'fraction_numerical': 0.0050274941084053415, 'mean_word_length': 2.9369202226345084, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810083', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1648, 'n_words': 577}