<commit_before>import logging
import string
from itertools import combinations, chain, ifilter, product

from timetabler.ssc import SSCConnection
from timetabler.util import check_equal, all_unique
from timetabler.schedule import Schedule


class Scheduler(object):
    def __init__(self, courses, session="2014W", terms=(1, 2), refresh=False):
        """Schedule

        :type  courses: list|tuple
        :param courses: ["CPSC 304", ...]
        :type  session: str|unicode
        :param session: Session you want to schedule for
        :type  terms: tuple|list
        :param terms: List of terms you want to schedule courses in;
            i.e., [1] for only first term, [1, 2] for whole session etc.
        :param refresh: Invalidate all cached data for relevant courses
        """
        self.ssc_conn = SSCConnection()
        self.courses = {c: self.ssc_conn.get_course(c, session, refresh=refresh)
                        for c in courses}
        self.terms = terms
        self.session = session
        self._constraints = []

    ##################
    # Public Methods #
    ##################

    def generate_schedules(self, bad_statuses=("Full", "Blocked")):
        """Generate valid schedules"""
        schedules_by_course = {}
        for name, course in self.courses.items():
            logging.info("Generating schedules for {} ...".format(name))
            acts = course.activities<commit_msg>Check for empty courses; resolves #4<commit_after>import logging
import string
from itertools import combinations, chain, ifilter, product

from timetabler.ssc import SSCConnection
from timetabler.util import check_equal, all_unique
from timetabler.schedule import Schedule


class NoActivitiesError(Exception):
    """No activities for given course"""
    def __init__(self, course_name):
        self.course_name = course_name

    def __str__(self):
        return self.course_name


class Scheduler(object):
    def __init__(self, courses, session="2014W", terms=(1, 2), refresh=False):
        """Schedule

        :type  courses: list|tuple
        :param courses: ["CPSC 304", ...]
        :type  session: str|unicode
        :param session: Session you want to schedule for
        :type  terms: tuple|list
        :param terms: List of terms you want to schedule courses in;
            i.e., [1] for only first term, [1, 2] for whole session etc.
        :param refresh: Invalidate all cached data for relevant courses
        """
        self.ssc_conn = SSCConnection()
        self.courses = {c: self.ssc_conn.get_course(c, session, refresh=refresh)
                        for c in courses}
        self.terms = terms
        self.session = session
        self._constraints = []

    ##################
    # Public Methods #
    ##################

    def generate_schedules(self, bad_statuses=("Full", "Blocked")):
        """Generate valid schedules"""
        schedules_by_course = {}
        for name, course in self.courses.items():
            logging.info("Generating schedules for {} ...".format(name))
            # Courses should have at least one activity
            if not course.activities:
                raise NoActivitiesError(name)
            acts = course.activities
{'fraction_non_alphanumeric': 0.11571782178217822, 'fraction_numerical': 0.007735148514851485, 'mean_word_length': 2.648984198645598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5865933', 'n_tokens_mistral': 906, 'n_tokens_neox': 864, 'n_words': 280}