# Path: partycrasher/api/thresholds.py
# class Thresholds(Mapping):
#     """
#     Represents the thresholds available under a certain search.
#     """
#     def __init__(self, search):
#         self.search = search
#         # Lazy-load projects
#         self._d = self.get_thresholds()
#     
#     def get_thresholds(self):
#         thresholds = {
#             t: ReportThreshold(self.search, t) for t in self.search.thresholds
#             }
#         return thresholds
#     
#     def __getitem__(self, key):
#         return self._d.__getitem__(key)
#     
#     def __iter__(self):
#         return self._d.__iter__()
# 
#     def __len__(self):
#         return self._d.__len__()
#     
#     def restify(self):
#         d = {}
#         for k, v in self._d.items():
#             d[str(k)] = v
#         return d
# 
# Path: partycrasher/api/cache.py
# def cached_threshold(search):
#     global cached_thresholds
#     if search in cached_thresholds:
#         #DEBUG("HIT")
#         return cached_thresholds[search]
#     else:
#         #DEBUG("MISS " + repr(search._d))
#         if search['threshold'] is None:
#             buckets = Thresholds(search)
#         else:
#             buckets = ReportThreshold(search, search['threshold'])
#         cached_thresholds[search] = buckets
#         return buckets


from six import text_type, string_types
from copy import copy
from partycrasher.crash_type import CrashType
from partycrasher.api.thresholds import Thresholds
from partycrasher.api.search import Search
from partycrasher.api.projects import Projects
from partycrasher.api.cache import cached_threshold
# -*- coding: utf-8 -*-

#  Copyright (C) 2017 Joshua Charles Campbell

#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.




class ReportType(CrashType):
    """
    API object representing a particular type inside a search context.
    """
    def __init__(self, search, report_type):
        super(ReportType, self).__init__(report_type)
        self.original_search = search
        search=Search(search=search, type=report_type)
        self.reports = search

# Path: partycrasher/api/thresholds.py
# class Thresholds(Mapping):
#     """
#     Represents the thresholds available under a certain search.
#     """
#     def __init__(self, search):
#         self.search = search
#         # Lazy-load projects
#         self._d = self.get_thresholds()
#     
#     def get_thresholds(self):
#         thresholds = {
#             t: ReportThreshold(self.search, t) for t in self.search.thresholds
#             }
#         return thresholds
#     
#     def __getitem__(self, key):
#         return self._d.__getitem__(key)
#     
#     def __iter__(self):
#         return self._d.__iter__()
# 
#     def __len__(self):
#         return self._d.__len__()
#     
#     def restify(self):
#         d = {}
#         for k, v in self._d.items():
#             d[str(k)] = v
#         return d
# 
# Path: partycrasher/api/cache.py
# def cached_threshold(search):
#     global cached_thresholds
#     if search in cached_thresholds:
#         #DEBUG("HIT")
#         return cached_thresholds[search]
#     else:
#         #DEBUG("MISS " + repr(search._d))
#         if search['threshold'] is None:
#             buckets = Thresholds(search)
#         else:
#             buckets = ReportThreshold(search, search['threshold'])
#         cached_thresholds[search] = buckets
#         return buckets


# Path: partycrasher/api/report_type.py
from six import text_type, string_types
from copy import copy
from partycrasher.crash_type import CrashType
from partycrasher.api.thresholds import Thresholds
from partycrasher.api.search import Search
from partycrasher.api.projects import Projects
from partycrasher.api.cache import cached_threshold

# -*- coding: utf-8 -*-

#  Copyright (C) 2017 Joshua Charles Campbell

#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.




class ReportType(CrashType):
    """
    API object representing a particular type inside a search context.
    """
    def __init__(self, search, report_type):
        super(ReportType, self).__init__(report_type)
        self.original_search = search
        search=Search(search=search, type=report_type)
        self.reports = search

        self.buckets = cached_threshold(search)