# 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
            else:
                # The best per_bin is too small to look good.
                # So just fallback to naive division method.
                num_bins = max_bins
                per_bin = float(bin_range) / max_bins
        boundaries = [int(round(per_bin * n)) for n in range(1, num_bins)]
        bin_sizes = [0] * num_bins
        for score in grade_set:
            bin_index = int(floor((score - bin_min) / per_bin))
            if bin_index >= num_bins:
                bin_index = num_bins - 1
            bin_sizes[bin_index] += 1
        return [{"x": x, "dx": dx, "y": y}
                for x, dx, y in zip([bin_min] + boundaries,
                                    boundaries + [bin_max],
                                    bin_sizes)]

    @staticmethod
    def timeseries_grade_percentiles(c, assignment_name, num_points=40):
        """
        Returns a timeseries of grades with percentiles. Here is an example:

            [["2015-07-17 19:00:36-0700", 0.0, 0.0, 0.0, ... 0.0, 0.0],
             ["2015-07-17 19:10:36-0700", 0.0, 0.0, 0.0, ... 1.0, 2.0],
             ["2015-07-17 19:20:36-0700", 0.0, 0.0, 0.0, ... 3.0, 4.0],
             ["2015-07-17 19:30:36-0700", 0.0, 0.0, 0.5, ... 5.0, 6.0],
             ["2015-07-17 19:40:36-0700", 0.0, 0.0, 1.0, ... 7.0, 8.0]]

        """
        data_keys = range(0, 105, 5)

# 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

            else:
                # The best per_bin is too small to look good.
                # So just fallback to naive division method.
                num_bins = max_bins
                per_bin = float(bin_range) / max_bins
        boundaries = [int(round(per_bin * n)) for n in range(1, num_bins)]
        bin_sizes = [0] * num_bins
        for score in grade_set:
            bin_index = int(floor((score - bin_min) / per_bin))
            if bin_index >= num_bins:
                bin_index = num_bins - 1
            bin_sizes[bin_index] += 1
        return [{"x": x, "dx": dx, "y": y}
                for x, dx, y in zip([bin_min] + boundaries,
                                    boundaries + [bin_max],
                                    bin_sizes)]

    @staticmethod
    def timeseries_grade_percentiles(c, assignment_name, num_points=40):
        """
        Returns a timeseries of grades with percentiles. Here is an example:

            [["2015-07-17 19:00:36-0700", 0.0, 0.0, 0.0, ... 0.0, 0.0],
             ["2015-07-17 19:10:36-0700", 0.0, 0.0, 0.0, ... 1.0, 2.0],
             ["2015-07-17 19:20:36-0700", 0.0, 0.0, 0.0, ... 3.0, 4.0],
             ["2015-07-17 19:30:36-0700", 0.0, 0.0, 0.5, ... 5.0, 6.0],
             ["2015-07-17 19:40:36-0700", 0.0, 0.0, 1.0, ... 7.0, 8.0]]

        """
        data_keys = range(0, 105, 5)

        assignment = get_assignment_by_name(assignment_name)