# Path: rtlsdr_scanner/constants.py
# WINFUNC = ["Bartlett", numpy.bartlett,
#            "Blackman", numpy.blackman,
#            "Hamming", numpy.hamming,
#            "Hanning", numpy.hanning]
# 
# Path: rtlsdr_scanner/misc.py
# def db_to_level(dB):
#     return math.pow(10, dB / 10.0)
# 
# def level_to_db(level):
#     return 10 * math.log10(level)


from collections import OrderedDict
from decimal import Decimal
from operator import itemgetter, mul
from matplotlib.dates import seconds
from rtlsdr_scanner.constants import WINFUNC
from rtlsdr_scanner.misc import db_to_level, level_to_db
from rtlsdr_scanner.utils_mpl import utc_to_mpl
import numpy
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#




class Extent(object):
    def __init__(self, spectrum):
        self.__clear()
        self.__calc_extent(spectrum)

    def __clear(self):
        self.fMin = float('inf')
        self.fMax = float('-inf')
        self.lMin = float('inf')
        self.lMax = float('-inf')
        self.tMin = float('inf')
        self.tMax = float('-inf')
        self.fPeak = None
        self.lPeak = None
        self.tPeak = None

    def __calc_extent(self, spectrum):
        self.tMin = min(spectrum)
        self.tMax = max(spectrum)

        for timeStamp in spectrum:
            points = spectrum[timeStamp].items()
            if len(points) > 0:
                fMin = min(points, key=itemgetter(0))[0]

# Path: rtlsdr_scanner/constants.py
# WINFUNC = ["Bartlett", numpy.bartlett,
#            "Blackman", numpy.blackman,
#            "Hamming", numpy.hamming,
#            "Hanning", numpy.hanning]
# 
# Path: rtlsdr_scanner/misc.py
# def db_to_level(dB):
#     return math.pow(10, dB / 10.0)
# 
# def level_to_db(level):
#     return 10 * math.log10(level)


# Path: rtlsdr_scanner/spectrum.py
from collections import OrderedDict
from decimal import Decimal
from operator import itemgetter, mul
from matplotlib.dates import seconds
from rtlsdr_scanner.constants import WINFUNC
from rtlsdr_scanner.misc import db_to_level, level_to_db
from rtlsdr_scanner.utils_mpl import utc_to_mpl
import numpy

# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#




class Extent(object):
    def __init__(self, spectrum):
        self.__clear()
        self.__calc_extent(spectrum)

    def __clear(self):
        self.fMin = float('inf')
        self.fMax = float('-inf')
        self.lMin = float('inf')
        self.lMax = float('-inf')
        self.tMin = float('inf')
        self.tMax = float('-inf')
        self.fPeak = None
        self.lPeak = None
        self.tPeak = None

    def __calc_extent(self, spectrum):
        self.tMin = min(spectrum)
        self.tMax = max(spectrum)

        for timeStamp in spectrum:
            points = spectrum[timeStamp].items()
            if len(points) > 0:
                fMin = min(points, key=itemgetter(0))[0]

                fMax = max(points, key=itemgetter(0))[0]