# Path: django_datawatch/datawatch.py
# class DatawatchHandler(object):
# class Scheduler(object):
#     def __init__(self):
#     def autodiscover_checks(self, module_name='checks'):
#     def register(self, check_class):
#     def get_all_registered_checks(self):
#     def get_all_registered_check_slugs(self):
#     def get_check_class(self, slug):
#     def get_checks_for_related_model(self, model):
#     def get_checks_for_model(self, model):
#     def get_slug(self, module, class_name):
#     def get_backend(self):
#     def delete_results(self, sender, instance):
#     def update_related(self, sender, instance):
#     def run_checks(self, force=False, slug=None):
#     def get_last_executions(self):
# def make_model_uid(model):
# def delete_results(sender, instance, using, **kwargs):
# def run_checks(sender, instance, created, raw, using, **kwargs):


from django.db import models
from django.db.models.aggregates import Count
from django.db.models.expressions import Case, When, Value
from django.db.models.query_utils import Q
from django.utils import timezone
from django_datawatch.datawatch import datawatch

    def unknown(self):
        return self.filter(status=self.model.STATUS.unknown)

    def unacknowledged(self):
        return self.exclude(acknowledged_until__gt=timezone.now())

    def with_status_name(self):
        case = Case(output_field=models.CharField())
        for status_value in self.model.STATUS._db_values:
            case.cases.append(
                When(status=status_value, then=Value(str(self.model.STATUS[status_value]))),
            )
        return self.annotate(status_name=case)

    def get_stats(self):
        return self.values('status').annotate(amount=Count('id')).with_status_name()

    def ghost_results(self):
        """
        :return: results that do not have checks anymore (check has been deleted)
        """
        return self.exclude(slug__in=datawatch.get_all_registered_check_slugs())


class CheckExecutionQuerySet(models.QuerySet):
    def ghost_executions(self):
        """
        :return: check executions that do not have checks anymore (check has been deleted)
        """

# Path: django_datawatch/datawatch.py
# class DatawatchHandler(object):
# class Scheduler(object):
#     def __init__(self):
#     def autodiscover_checks(self, module_name='checks'):
#     def register(self, check_class):
#     def get_all_registered_checks(self):
#     def get_all_registered_check_slugs(self):
#     def get_check_class(self, slug):
#     def get_checks_for_related_model(self, model):
#     def get_checks_for_model(self, model):
#     def get_slug(self, module, class_name):
#     def get_backend(self):
#     def delete_results(self, sender, instance):
#     def update_related(self, sender, instance):
#     def run_checks(self, force=False, slug=None):
#     def get_last_executions(self):
# def make_model_uid(model):
# def delete_results(sender, instance, using, **kwargs):
# def run_checks(sender, instance, created, raw, using, **kwargs):


# Path: django_datawatch/querysets.py
from django.db import models
from django.db.models.aggregates import Count
from django.db.models.expressions import Case, When, Value
from django.db.models.query_utils import Q
from django.utils import timezone
from django_datawatch.datawatch import datawatch


    def unknown(self):
        return self.filter(status=self.model.STATUS.unknown)

    def unacknowledged(self):
        return self.exclude(acknowledged_until__gt=timezone.now())

    def with_status_name(self):
        case = Case(output_field=models.CharField())
        for status_value in self.model.STATUS._db_values:
            case.cases.append(
                When(status=status_value, then=Value(str(self.model.STATUS[status_value]))),
            )
        return self.annotate(status_name=case)

    def get_stats(self):
        return self.values('status').annotate(amount=Count('id')).with_status_name()

    def ghost_results(self):
        """
        :return: results that do not have checks anymore (check has been deleted)
        """
        return self.exclude(slug__in=datawatch.get_all_registered_check_slugs())


class CheckExecutionQuerySet(models.QuerySet):
    def ghost_executions(self):
        """
        :return: check executions that do not have checks anymore (check has been deleted)
        """

        return self.exclude(slug__in=datawatch.get_all_registered_check_slugs())