# 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
        self.minF = None
        self.maxF = None
        self.minP = None
        self.maxP = None
        self.avgP = None
        self.gMeanP = None
        self.flatness = None
        self.hbw = None
        self.obw = None

        self.__calculate(spectrum, start, end)

    def __calculate(self, spectrum, start, end):
        sweep = slice_spectrum(spectrum, start, end)
        if sweep is None or len(sweep) == 0:
            return

        self.minF = min(sweep)[0]
        self.maxF = max(sweep)[0]
        self.minP = min(sweep, key=lambda v: v[1])
        self.maxP = max(sweep, key=lambda v: v[1])

        powers = [Decimal(db_to_level(p[1])) for p in sweep]
        length = len(powers)

        avg = sum(powers, Decimal(0)) / length
        self.avgP = level_to_db(avg)

        product = reduce(mul, iter(powers))
        gMean = product ** (Decimal(1.0) / length)

# 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

        self.minF = None
        self.maxF = None
        self.minP = None
        self.maxP = None
        self.avgP = None
        self.gMeanP = None
        self.flatness = None
        self.hbw = None
        self.obw = None

        self.__calculate(spectrum, start, end)

    def __calculate(self, spectrum, start, end):
        sweep = slice_spectrum(spectrum, start, end)
        if sweep is None or len(sweep) == 0:
            return

        self.minF = min(sweep)[0]
        self.maxF = max(sweep)[0]
        self.minP = min(sweep, key=lambda v: v[1])
        self.maxP = max(sweep, key=lambda v: v[1])

        powers = [Decimal(db_to_level(p[1])) for p in sweep]
        length = len(powers)

        avg = sum(powers, Decimal(0)) / length
        self.avgP = level_to_db(avg)

        product = reduce(mul, iter(powers))
        gMean = product ** (Decimal(1.0) / length)

        self.gMeanP = level_to_db(gMean)