# Path: chaosmonkey/planners/planner.py
# class Planner:
#     """
#     Planner interface
#     Planners are responsible for scheduling jobs that executes attacks
# 
#     :param name:    plan name
#     """
# 
#     ref = None  # must override
#     schema = None  # must override
#     example = None  # must override
# 
#     def __init__(self, name):
#         self.name = name
# 
#     def plan(self, planner_config, attack_config):
#         """
#         Plan the jobs.
#         This method should use the config to schedule jobs based on the
#         configuration for the planner
# 
#         :param planner_config:    configuration related to the scheduler
#         :param attack_config:   configuration related to the attack
#         """
#         raise NotImplementedError("Plans should implement this!")
# 
#     @staticmethod
#     def add_plan(name):
#         return manager.add_plan(name)
# 
#     @staticmethod
#     def _add_executor(date, name, attack_config, plan_id):
#         """
#         Add a job to the global scheduler
# 
#         :param date: date to execute the job
#         :param name: job name
#         :param attack_config: configuration related to the attack
#         """
#         date_timezone = manager.scheduler.timezone.localize(date)
#         manager.add_executor(date_timezone, name, attack_config, plan_id)
# 
#     @staticmethod
#     def to_dict():
#         raise NotImplementedError("Planners should implement this!")
# 
#     @staticmethod
#     def _to_dict(ref, schema, example):
#         return {
#             "ref": ref,
#             "schema": schema,
#             "example": example,
#         }


import logging
import random
from datetime import datetime
from chaosmonkey.planners.planner import Planner
        Return an array of datetimes according to the planner args
        """
        planer_args = self.planner_config["args"]
        start_time = datetime.strptime(planer_args["min_time"], "%H:%M").time()
        start_date = datetime.combine(datetime.today().date(), start_time)
        end_time = datetime.strptime(planer_args["max_time"], "%H:%M").time()
        end_date = datetime.combine(datetime.today().date(), end_time)

        random.seed()
        attack_schedule = []
        for start, end in self._split_date_range(start_date, end_date, planer_args["times"]):
            attack_schedule.append(random.uniform(start, end))

        return attack_schedule

    @staticmethod
    def _split_date_range(start, end, intv):
        """
        Splits a daterange in even buckets
        """
        previous = start
        diff = (end - start) / intv
        for i in range(1, intv):
            current = start + diff * i
            yield (previous, current)
            previous = current
        yield (previous, end)

    @staticmethod
    def to_dict():

# Path: chaosmonkey/planners/planner.py
# class Planner:
#     """
#     Planner interface
#     Planners are responsible for scheduling jobs that executes attacks
# 
#     :param name:    plan name
#     """
# 
#     ref = None  # must override
#     schema = None  # must override
#     example = None  # must override
# 
#     def __init__(self, name):
#         self.name = name
# 
#     def plan(self, planner_config, attack_config):
#         """
#         Plan the jobs.
#         This method should use the config to schedule jobs based on the
#         configuration for the planner
# 
#         :param planner_config:    configuration related to the scheduler
#         :param attack_config:   configuration related to the attack
#         """
#         raise NotImplementedError("Plans should implement this!")
# 
#     @staticmethod
#     def add_plan(name):
#         return manager.add_plan(name)
# 
#     @staticmethod
#     def _add_executor(date, name, attack_config, plan_id):
#         """
#         Add a job to the global scheduler
# 
#         :param date: date to execute the job
#         :param name: job name
#         :param attack_config: configuration related to the attack
#         """
#         date_timezone = manager.scheduler.timezone.localize(date)
#         manager.add_executor(date_timezone, name, attack_config, plan_id)
# 
#     @staticmethod
#     def to_dict():
#         raise NotImplementedError("Planners should implement this!")
# 
#     @staticmethod
#     def _to_dict(ref, schema, example):
#         return {
#             "ref": ref,
#             "schema": schema,
#             "example": example,
#         }


# Path: planners/simple_planner.py
import logging
import random
from datetime import datetime
from chaosmonkey.planners.planner import Planner

        Return an array of datetimes according to the planner args
        """
        planer_args = self.planner_config["args"]
        start_time = datetime.strptime(planer_args["min_time"], "%H:%M").time()
        start_date = datetime.combine(datetime.today().date(), start_time)
        end_time = datetime.strptime(planer_args["max_time"], "%H:%M").time()
        end_date = datetime.combine(datetime.today().date(), end_time)

        random.seed()
        attack_schedule = []
        for start, end in self._split_date_range(start_date, end_date, planer_args["times"]):
            attack_schedule.append(random.uniform(start, end))

        return attack_schedule

    @staticmethod
    def _split_date_range(start, end, intv):
        """
        Splits a daterange in even buckets
        """
        previous = start
        diff = (end - start) / intv
        for i in range(1, intv):
            current = start + diff * i
            yield (previous, current)
            previous = current
        yield (previous, end)

    @staticmethod
    def to_dict():

        return Planner._to_dict(SimplePlanner.ref, SimplePlanner.schema, SimplePlanner.example)