# Path: kardboard/tasks.py
# @celery.task(name="tasks.normalize_people", ignore_result=True)
# def normalize_people(days=7):
#     logger = normalize_people.get_logger()
#     people_cache = {}
# 
#     if app.config.get('DISABLE_TASK_PEOPLE', False):
#         logger.debug("SKIPPING normalize_people because DISABLE_TASK_PEOPLE is True")
#         return None
# 
#     one_week_ago = datetime.datetime.now() - relativedelta.relativedelta(days=days)
#     kards = Kard.objects.filter(Q(start_date__gte=one_week_ago) | Q(done_date__gte=one_week_ago))
# 
#     for k in kards:
#         logger.debug("Considering %s" % k.key)
#         reporter = k.ticket_system_data.get('reporter', '')
#         devs = k.ticket_system_data.get('developers', [])
#         testers = k.ticket_system_data.get('qaers', [])
# 
#         logger.debug("Reporter: %s / Devs: %s / Testers: %s" % (reporter, devs, testers))
# 
#         if reporter:
#             p = _get_person(reporter, people_cache)
#             p.report(k)
# 
#         for d in devs:
#             p = _get_person(d, people_cache)
#             p.develop(k)
# 
#         for t in testers:
#             p = _get_person(t, people_cache)
#             p.test(k)
# 
#     for name, person in people_cache.items():
#         person.save()
# 
# Path: kardboard/models/person.py
# class Person(app.db.Document):
#     name = app.db.StringField(required=True, unique=True)
#     """A unique string that identifies the person"""
# 
#     reported = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for reporting."""
# 
#     developed = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for developing."""
# 
#     tested = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for testing."""
# 
#     updated_at = app.db.DateTimeField(required=True)
# 
#     def report(self, kard):
#         if kard not in self.reported:
#             self.reported.append(kard)
# 
#     def develop(self, kard):
#         if kard not in self.developed:
#             self.developed.append(kard)
# 
#     def test(self, kard):
#         if kard not in self.tested:
#             self.tested.append(kard)
# 
#     def _is_card(self, kandidate):
#         if isinstance(kandidate, Kard):
#             return True
#         return False
# 
#     def in_progress(self, kardlist):
#         kards = [k for k in kardlist if self._is_card(k)]
#         wip = [k for k in kards if not k.done_date]
#         wip.sort(key=lambda r: r.current_cycle_time())
#         wip.reverse()
#         return wip
# 
#     def is_done(self, kardlist):
#         kards = [k for k in kardlist if self._is_card(k)]
#         kards = [k for k in kards if k.done_date]
#         kards.sort(key=lambda r: r.done_date)
#         kards.reverse()
#         return kards
# 
#     def cleanup(self):
#         [self.reported.remove(k) for k in list(self.reported) if not isinstance(k, Kard)]
#         [self.developed.remove(k) for k in list(self.developed) if not isinstance(k, Kard)]
#         [self.tested.remove(k) for k in list(self.tested) if not isinstance(k, Kard)]
# 
#     def save(self, *args, **kwargs):
#         self.updated_at = datetime.datetime.now()
#         self.cleanup()
#         super(Person, self).save(*args, **kwargs)


from kardboard.tasks import normalize_people
from kardboard.models import Person
"""
Data migration that sets up the initial set of Person
objects. After this is run they'll be created
and updated by the actually_update method of
a card's ticket helper.
"""



def main():
    print Person.objects.count()

# Path: kardboard/tasks.py
# @celery.task(name="tasks.normalize_people", ignore_result=True)
# def normalize_people(days=7):
#     logger = normalize_people.get_logger()
#     people_cache = {}
# 
#     if app.config.get('DISABLE_TASK_PEOPLE', False):
#         logger.debug("SKIPPING normalize_people because DISABLE_TASK_PEOPLE is True")
#         return None
# 
#     one_week_ago = datetime.datetime.now() - relativedelta.relativedelta(days=days)
#     kards = Kard.objects.filter(Q(start_date__gte=one_week_ago) | Q(done_date__gte=one_week_ago))
# 
#     for k in kards:
#         logger.debug("Considering %s" % k.key)
#         reporter = k.ticket_system_data.get('reporter', '')
#         devs = k.ticket_system_data.get('developers', [])
#         testers = k.ticket_system_data.get('qaers', [])
# 
#         logger.debug("Reporter: %s / Devs: %s / Testers: %s" % (reporter, devs, testers))
# 
#         if reporter:
#             p = _get_person(reporter, people_cache)
#             p.report(k)
# 
#         for d in devs:
#             p = _get_person(d, people_cache)
#             p.develop(k)
# 
#         for t in testers:
#             p = _get_person(t, people_cache)
#             p.test(k)
# 
#     for name, person in people_cache.items():
#         person.save()
# 
# Path: kardboard/models/person.py
# class Person(app.db.Document):
#     name = app.db.StringField(required=True, unique=True)
#     """A unique string that identifies the person"""
# 
#     reported = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for reporting."""
# 
#     developed = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for developing."""
# 
#     tested = app.db.ListField(
#         app.db.ReferenceField('Kard', dbref=False),
#         required=False)
#     """The list of cards the person was responsible for testing."""
# 
#     updated_at = app.db.DateTimeField(required=True)
# 
#     def report(self, kard):
#         if kard not in self.reported:
#             self.reported.append(kard)
# 
#     def develop(self, kard):
#         if kard not in self.developed:
#             self.developed.append(kard)
# 
#     def test(self, kard):
#         if kard not in self.tested:
#             self.tested.append(kard)
# 
#     def _is_card(self, kandidate):
#         if isinstance(kandidate, Kard):
#             return True
#         return False
# 
#     def in_progress(self, kardlist):
#         kards = [k for k in kardlist if self._is_card(k)]
#         wip = [k for k in kards if not k.done_date]
#         wip.sort(key=lambda r: r.current_cycle_time())
#         wip.reverse()
#         return wip
# 
#     def is_done(self, kardlist):
#         kards = [k for k in kardlist if self._is_card(k)]
#         kards = [k for k in kards if k.done_date]
#         kards.sort(key=lambda r: r.done_date)
#         kards.reverse()
#         return kards
# 
#     def cleanup(self):
#         [self.reported.remove(k) for k in list(self.reported) if not isinstance(k, Kard)]
#         [self.developed.remove(k) for k in list(self.developed) if not isinstance(k, Kard)]
#         [self.tested.remove(k) for k in list(self.tested) if not isinstance(k, Kard)]
# 
#     def save(self, *args, **kwargs):
#         self.updated_at = datetime.datetime.now()
#         self.cleanup()
#         super(Person, self).save(*args, **kwargs)


# Path: bin/m03-createinitialpeople.py
from kardboard.tasks import normalize_people
from kardboard.models import Person

"""
Data migration that sets up the initial set of Person
objects. After this is run they'll be created
and updated by the actually_update method of
a card's ticket helper.
"""



def main():
    print Person.objects.count()

    r = normalize_people.apply()