Ejemplo n.º 1
0
def create_file(
        station_name, recorder_name, start_time, duration, num_channels=1,
        sample_rate=22050, recorder_channel_nums=(0,),
        mic_outputs=('Mic Output 0',)):
    
    t = datetime.datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S')
    start_time = time_utils.create_utc_datetime(
        t.year, t.month, t.day, t.hour, t.minute, t.second)
    
    h, m, s = duration.split(':')
    delta = datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
    duration = delta.total_seconds()
    length = int(duration * sample_rate)
    
    station = Bunch(name=station_name)
    recorder = Bunch(name=recorder_name)
    
    return Bunch(
        station=station,
        recorder=recorder,
        recorder_channel_nums=recorder_channel_nums,
        mic_outputs=mic_outputs,
        num_channels=num_channels,
        length=length,
        sample_rate=sample_rate,
        start_time=start_time)
Ejemplo n.º 2
0
    def get_recordings(self, station_name, night):
        """
        Gets the archived recordings for the specified station and night.
        
        :Returns:
            a list of recordings for the specified station and night.
        """

        station_id = self._check_station_name(station_name)
        station = self._stations[station_id]

        night_start_time = time_utils.create_utc_datetime(
            night.year,
            night.month,
            night.day,
            12,
            time_zone=station.time_zone)

        night_end_time = night_start_time + datetime.timedelta(days=1)

        # Convert times to strings for database query.
        night_start_time = _format_time(night_start_time)
        night_end_time = _format_time(night_end_time)

        self._cursor.execute(_SELECT_RECORDINGS_SQL,
                             (station_id, night_start_time, night_end_time))

        recordings = [
            self._create_recording(_RecordingTuple._make(row))
            for row in self._cursor
        ]

        return recordings
Ejemplo n.º 3
0
 def local_to_utc(self, dt, is_dst=None):
     
     """
     Converts a station-local time to UTC.
     
     The time is assumed to be in this station's local time zone,
     regardless of its `tzinfo`, if any.
     """
     
     return time_utils.create_utc_datetime(
         dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
         dt.microsecond, self.tz, is_dst)
Ejemplo n.º 4
0
 def local_to_utc(self, dt, is_dst=None):
     
     """
     Converts a station-local time to UTC.
     
     The time is assumed to be in this station's local time zone,
     regardless of its `tzinfo`, if any.
     """
     
     return time_utils.create_utc_datetime(
         dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
         dt.microsecond, self.tz, is_dst)
Ejemplo n.º 5
0
def _create_fake_night_channel_recordings(archive, station, night):
      
    from vesper.archive.recording import Recording as RecordingOld
      
    start_time = time_utils.create_utc_datetime(
        night.year, night.month, night.day, _FAKE_RECORDING_START_HOUR,
        time_zone=station.time_zone)
    
    length = \
        _FAKE_RECORDING_DURATION * 3600 * _FAKE_RECORDING_SAMPLE_RATE
        
    channel = RecordingOld(
        station, start_time, length, _FAKE_RECORDING_SAMPLE_RATE)
    
    return [channel]
Ejemplo n.º 6
0
    def test_create_utc_datetime(self):

        eastern = pytz.timezone('US/Eastern')

        cases = [(2015, 5, 24, 12, 0, 0, 0, None, None, 0),
                 (2015, 5, 24, 12, 0, 0, 0, 'US/Eastern', None, 4),
                 (2015, 5, 24, 22, 0, 0, 0, 'US/Eastern', None, 4),
                 (2014, 12, 31, 22, 0, 0, 0, 'US/Eastern', None, 5),
                 (2015, 3, 8, 1, 59, 59, 999999, 'US/Eastern', None, 5),
                 (2015, 3, 8, 3, 0, 0, 0, eastern, None, 4),
                 (2015, 11, 1, 1, 0, 0, 0, eastern, True, 4),
                 (2015, 11, 1, 1, 0, 0, 0, eastern, False, 5),
                 (2015, 11, 1, 2, 0, 0, 0, eastern, None, 5)]

        for y, M, d, h, m, s, u, z, is_dst, delta in cases:
            expected = _create_utc_datetime(y, M, d, h, m, s, u, delta)
            result = time_utils.create_utc_datetime(y, M, d, h, m, s, u, z,
                                                    is_dst)
            self.assertEqual(result, expected)
Ejemplo n.º 7
0
 def test_create_utc_datetime(self):
     
     eastern = pytz.timezone('US/Eastern')
     
     cases = [
         (2015, 5, 24, 12, 0, 0, 0, None, None, 0),
         (2015, 5, 24, 12, 0, 0, 0, 'US/Eastern', None, 4),
         (2015, 5, 24, 22, 0, 0, 0, 'US/Eastern', None, 4),
         (2014, 12, 31, 22, 0, 0, 0, 'US/Eastern', None, 5),
         (2015, 3, 8, 1, 59, 59, 999999, 'US/Eastern', None, 5),
         (2015, 3, 8, 3, 0, 0, 0, eastern, None, 4),
         (2015, 11, 1, 1, 0, 0, 0, eastern, True, 4),
         (2015, 11, 1, 1, 0, 0, 0, eastern, False, 5),
         (2015, 11, 1, 2, 0, 0, 0, eastern, None, 5)
     ]
     
     for y, M, d, h, m, s, u, z, is_dst, delta in cases:
         expected = _create_utc_datetime(y, M, d, h, m, s, u, delta)
         result = time_utils.create_utc_datetime(
             y, M, d, h, m, s, u, z, is_dst)
         self.assertEqual(result, expected)
def to_utc(dt):
    return time_utils.create_utc_datetime(
        dt.year, dt.month, dt.day, dt.hour,
        dt.minute, dt.second, dt.microsecond, TIME_ZONE)
 def _get_reference_time(self):
     d = self._start_date
     return time_utils.create_utc_datetime(d.year, d.month, d.day)
 def _get_reference_time(self):
     d = self._start_date
     return time_utils.create_utc_datetime(d.year, d.month, d.day)
Ejemplo n.º 11
0
def to_utc(dt):
    return time_utils.create_utc_datetime(dt.year, dt.month, dt.day, dt.hour,
                                          dt.minute, dt.second, dt.microsecond,
                                          TIME_ZONE)