# Path: ob2/util/config_data.py
# def get_assignment_by_name(name, default=None):
#     global _assignment_by_name
#     if _assignment_by_name is None:
#         _assignment_by_name = {assignment.name: assignment
#                                for assignment in config.assignments}
#     return _assignment_by_name[name]
# 
# Path: ob2/util/time.py
# def format_js_compatible_time(s):
#     """Converts a datetime object to serializable format for JavaScript."""
#     return s.strftime("%Y-%m-%dT%H:%M:%S%z")
# 
# def now():
#     """Gets the current datetime (with timezone) as an object."""
#     timezone_obj = pytz.timezone(config.timezone)
#     return datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(timezone_obj)
# 
# def parse_time(s):
#     """Converts serializable datetime to a datetime object."""
#     return DateParser.parse(s)
# 
# Path: ob2/util/build_constants.py
# SUCCESS = 0


import numpy as np
from math import ceil, floor
from ob2.util.config_data import get_assignment_by_name
from ob2.util.time import format_js_compatible_time, now, parse_time
from ob2.util.build_constants import SUCCESS

class Datasets(object):
    """
    A collection of useful dataset generators. Each dataset should take a database cursor as its
    first argument, followed by the arguments of the dataset itself.

    The return value of each dataset will be None if the arguments do not lead to a valid dataset.

    """

    @classmethod
    def grade_distribution(cls, c, assignment_name, max_bins=None):
        """
        Returns a pre-binned histogram of grades for the assignment. Here is an example of what the
        data looks like:

            [{'x': 0, 'dx': 1, 'y': 3},
             {'x': 1, 'dx': 2, 'y': 0},
             {'x': 2, 'dx': 3, 'y': 0},
             {'x': 3, 'dx': 4, 'y': 0},
             {'x': 4, 'dx': 5, 'y': 1},
             {'x': 5, 'dx': 6, 'y': 2},
             {'x': 6, 'dx': 7, 'y': 5},
             {'x': 7, 'dx': 8, 'y': 11},
             {'x': 8, 'dx': 9, 'y': 7},
             {'x': 9, 'dx': 10, 'y': 15},
             {'x': 10, 'dx': 11, 'y': 35},
             {'x': 11, 'dx': 12, 'y': 92}]

        """

# Path: ob2/util/config_data.py
# def get_assignment_by_name(name, default=None):
#     global _assignment_by_name
#     if _assignment_by_name is None:
#         _assignment_by_name = {assignment.name: assignment
#                                for assignment in config.assignments}
#     return _assignment_by_name[name]
# 
# Path: ob2/util/time.py
# def format_js_compatible_time(s):
#     """Converts a datetime object to serializable format for JavaScript."""
#     return s.strftime("%Y-%m-%dT%H:%M:%S%z")
# 
# def now():
#     """Gets the current datetime (with timezone) as an object."""
#     timezone_obj = pytz.timezone(config.timezone)
#     return datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(timezone_obj)
# 
# def parse_time(s):
#     """Converts serializable datetime to a datetime object."""
#     return DateParser.parse(s)
# 
# Path: ob2/util/build_constants.py
# SUCCESS = 0


# Path: ob2/util/datasets.py
import numpy as np
from math import ceil, floor
from ob2.util.config_data import get_assignment_by_name
from ob2.util.time import format_js_compatible_time, now, parse_time
from ob2.util.build_constants import SUCCESS


class Datasets(object):
    """
    A collection of useful dataset generators. Each dataset should take a database cursor as its
    first argument, followed by the arguments of the dataset itself.

    The return value of each dataset will be None if the arguments do not lead to a valid dataset.

    """

    @classmethod
    def grade_distribution(cls, c, assignment_name, max_bins=None):
        """
        Returns a pre-binned histogram of grades for the assignment. Here is an example of what the
        data looks like:

            [{'x': 0, 'dx': 1, 'y': 3},
             {'x': 1, 'dx': 2, 'y': 0},
             {'x': 2, 'dx': 3, 'y': 0},
             {'x': 3, 'dx': 4, 'y': 0},
             {'x': 4, 'dx': 5, 'y': 1},
             {'x': 5, 'dx': 6, 'y': 2},
             {'x': 6, 'dx': 7, 'y': 5},
             {'x': 7, 'dx': 8, 'y': 11},
             {'x': 8, 'dx': 9, 'y': 7},
             {'x': 9, 'dx': 10, 'y': 15},
             {'x': 10, 'dx': 11, 'y': 35},
             {'x': 11, 'dx': 12, 'y': 92}]

        """

        assignment = get_assignment_by_name(assignment_name)