# 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
        data[timeStamp] = OrderedDict(zip(sweep.keys(), diff))

    return data


def delta_spectrum(spectrum):
    data = OrderedDict()
    if len(spectrum) > 1:
        _t, baseline = spectrum.items()[0]
        for timeStamp, sweep in spectrum.items()[1:]:
            delta = [(freq, sweep[freq] - baseline.get(freq, 0))
                     for freq in sweep.keys()]
            data[timeStamp] = OrderedDict(delta)
    else:
        data = spectrum

    return data


def smooth_spectrum(spectrum, winFunc, ratio):
    data = OrderedDict()
    for timeStamp, sweep in spectrum.items():
        if len(sweep):
            data[timeStamp] = smooth_sweep(sweep, winFunc, ratio)

    return data


def smooth_sweep(sweep, winFunc, ratio):
    pos = WINFUNC[::2].index(winFunc)

# 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

        data[timeStamp] = OrderedDict(zip(sweep.keys(), diff))

    return data


def delta_spectrum(spectrum):
    data = OrderedDict()
    if len(spectrum) > 1:
        _t, baseline = spectrum.items()[0]
        for timeStamp, sweep in spectrum.items()[1:]:
            delta = [(freq, sweep[freq] - baseline.get(freq, 0))
                     for freq in sweep.keys()]
            data[timeStamp] = OrderedDict(delta)
    else:
        data = spectrum

    return data


def smooth_spectrum(spectrum, winFunc, ratio):
    data = OrderedDict()
    for timeStamp, sweep in spectrum.items():
        if len(sweep):
            data[timeStamp] = smooth_sweep(sweep, winFunc, ratio)

    return data


def smooth_sweep(sweep, winFunc, ratio):
    pos = WINFUNC[::2].index(winFunc)

    function = WINFUNC[1::2][pos]