<commit_before># -*- coding: utf-8 -*-
import os

from datetime import datetime
from subprocess import Popen

import settings


class SignalReceiver():

    _decoding_values = [
        'POCSAG512',
        'POCSAG1200',
        'POCSAG2400',
        'EAS',
        'UFSK1200',
        'CLIPFSK',
        'FMSFSK',
        'AFSK1200',
        'AFSK2400',
        'AFSK2400_2',
        'AFSK2400_3',
        'HAPN4800',
        'FSK9600',
        'DTMF',
        'ZVEI1',
        'ZVEI2',
        'ZVEI3',
        'DZVEI',
        'PZVEI',
        'EEA',
        'EIA',
        'CCIR',
        'MORSE_CW',
        'DUMPCSV',
        'SCOPE'
    ]

    def __init__(self, observation_id, frequency, decoding, **kwargs):
        """ Initialises receiver """

        ##  Check input values

        # we need the observation_id so that it accompanies the serialised output
        if not observation_id:
            raise LookupError('arg not found: observation_id')
        # frequency is needed to pass to rtl_fm
        if not frequency:
            raise LookupError('arg not found: frequency')

        # decoding can be None (PCM encoding/compression) or any predefined value (multmon-ng decoding)
        if decoding not in self._decoding_values and decoding is not None:
            raise LookupError('arg not found: decoding')

        ## Initialise variables
        self.observation_id = observation_id
        self.frequency = frequency
        self.decoding = kwargs.get('decoding', None)
        self.ppm_error = kwargs.get('ppm_error', 100)  # sliding error of receiver. It is normally "about" 100. Part of calibration
        self.pcm_demodulator = kwargs.get('demodulator', 'AFSK1200')  # demodulation of pcm in order to get decoded
        self.modulation = kwargs.get('modulation', 'fm')  # mode of received signal
        self.sample_rate = kwargs.get('sample_rate', 22050)  # sample rate of wav file produced by rtl_fm
        self.aprs = kwargs.get('aprs', True)  # APRS: final decoding format (only available
        ## NOTE: if aprs is True, multimon-ng sets pcm_demodulator to 'AFSK1200' automagically

    def get_decoding_cmd(self):
        """ Provides decoding command."""
        params = {
            '-t': 'raw',  # always raw
            '-a': self.pcm_demodulator,
        }

        args = ['{0}{1}'.format(key, params[key]) for key in params]

        if self.aprs:
            args.append('-A')

        args.append('-')

        return [settings.DECODING_COMMAND] + args

    def get_demodulation_cmd(self):
        """ Provides decoding command."""
        if self.decoding:
            params = {
                '-f': self.frequency,
                '-p': self.ppm_error,
                '-s': self.sample_rate,
                '-M': self.modulation
            }

            args = ['{0} {1}'.format(key, params[key]) for key in params]

            return [settings.DEMODULATION_COMMAND] + args
        raise NotImplementedError

    def get_output_path(self):
        """ Provides output path for serialisation of output."""
        timestamp = datetime.utcnow().isoformat()
        filename = 'satnogs_{0}_{1}.out'.format(self.observation_id, timestamp)
        return os.path.join(settings.OUTPUT_PATH, filename)
<commit_msg>implement oggenc arguments passing (closes #31)<commit_after># -*- coding: utf-8 -*-
import os

from datetime import datetime
from subprocess import Popen

import settings


class SignalReceiver():

    _decoding_values = [
        'POCSAG512',
        'POCSAG1200',
        'POCSAG2400',
        'EAS',
        'UFSK1200',
        'CLIPFSK',
        'FMSFSK',
        'AFSK1200',
        'AFSK2400',
        'AFSK2400_2',
        'AFSK2400_3',
        'HAPN4800',
        'FSK9600',
        'DTMF',
        'ZVEI1',
        'ZVEI2',
        'ZVEI3',
        'DZVEI',
        'PZVEI',
        'EEA',
        'EIA',
        'CCIR',
        'MORSE_CW',
        'DUMPCSV',
        'SCOPE'
    ]

    def __init__(self, observation_id, frequency, decoding=None, **kwargs):
        """ Initialises receiver """

        ##  Check input values

        # we need the observation_id so that it accompanies the serialised output
        if not observation_id:
            raise LookupError('arg not found: observation_id')
        # frequency is needed to pass to rtl_fm
        if not frequency:
            raise LookupError('arg not found: frequency')

        # decoding can be None (PCM encoding/compression) or any predefined value (multmon-ng decoding)
        if decoding not in self._decoding_values and decoding is not None:
            raise LookupError('arg not found: decoding')

        ## Initialise variables
        self.observation_id = observation_id
        self.frequency = frequency
        self.decoding = kwargs.get('decoding', None)
        self.ppm_error = kwargs.get('ppm_error', 100)  # sliding error of receiver. It is normally "about" 100. Part of calibration
        self.pcm_demodulator = kwargs.get('demodulator', 'AFSK1200')  # demodulation of pcm in order to get decoded
        self.modulation = kwargs.get('modulation', 'fm')  # mode of received signal
        self.sample_rate = kwargs.get('sample_rate', 22050)  # sample rate of wav file produced by rtl_fm
        self.aprs = kwargs.get('aprs', True)  # APRS: final decoding format (only available
        ## NOTE: if aprs is True, multimon-ng sets pcm_demodulator to 'AFSK1200' automagically

    def get_decoding_cmd(self):
        """ Provides decoding command."""
        params = {
            '-t': 'raw',  # always raw
            '-a': self.pcm_demodulator,
        }

        args = ['{0}{1}'.format(key, params[key]) for key in params]

        if self.aprs:
            args.append('-A')

        args.append('-')

        return [settings.DECODING_COMMAND] + args

    def get_demodulation_cmd(self):
        """ Provides decoding command."""
        if self.decoding:
            params = {
                '-f': self.frequency,
                '-p': self.ppm_error,
                '-s': self.sample_rate,
                '-M': self.modulation
            }
            args = ['{0} {1}'.format(key, params[key]) for key in params]
        else:
            # oggenc --raw-endianess=0 -R 24k -B 16 -C 1 -r -q 4<br/>
            params = {
                '-R': '24k',
                '-B': '16',
                '-C': '1',
                '-q': '4'
            }
            args = '--raw-endianess=0 -r '
            args += ['{0} {1}'.format(key, params[key]) for key in params]
        return [settings.DEMODULATION_COMMAND] + args

    def get_output_path(self):
        """ Provides output path for serialisation of output."""
        timestamp = datetime.utcnow().isoformat()
        filename = 'satnogs_{0}_{1}.out'.format(self.observation_id, timestamp)
        return os.path.join(settings.OUTPUT_PATH, filename)

{'fraction_non_alphanumeric': 0.11672473867595819, 'fraction_numerical': 0.022938443670150986, 'mean_word_length': 2.025472112428634, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480059', 'n_tokens_mistral': 2212, 'n_tokens_neox': 2072, 'n_words': 555}