當前位置: 首頁>>代碼示例>>Python>>正文


Python timestamp.Timestamp類代碼示例

本文整理匯總了Python中apache_beam.utils.timestamp.Timestamp的典型用法代碼示例。如果您正苦於以下問題:Python Timestamp類的具體用法?Python Timestamp怎麽用?Python Timestamp使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Timestamp類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_from_utc_datetime

 def test_from_utc_datetime(self):
   self.assertEqual(
       Timestamp.from_utc_datetime(datetime.datetime(1970, 1, 1,
                                                     tzinfo=pytz.utc)),
       Timestamp(0))
   with self.assertRaisesRegexp(ValueError, r'UTC'):
     Timestamp.from_utc_datetime(datetime.datetime(1970, 1, 1))
開發者ID:JavierRoger,項目名稱:beam,代碼行數:7,代碼來源:timestamp_test.py

示例2: test_from_rfc3339

 def test_from_rfc3339(self):
   test_cases = [
       (10000000, '1970-04-26T17:46:40Z'),
       (10000000.000001, '1970-04-26T17:46:40.000001Z'),
       (1458343379.123456, '2016-03-18T23:22:59.123456Z'),
   ]
   for seconds_float, rfc3339_str in test_cases:
     self.assertEqual(Timestamp(seconds_float),
                      Timestamp.from_rfc3339(rfc3339_str))
     self.assertEqual(rfc3339_str,
                      Timestamp.from_rfc3339(rfc3339_str).to_rfc3339())
開發者ID:JavierRoger,項目名稱:beam,代碼行數:11,代碼來源:timestamp_test.py

示例3: finish_bundle

  def finish_bundle(self):
    data = self._read_from_pubsub(self.source.timestamp_attribute)
    if data:
      output_pcollection = list(self._outputs)[0]
      bundle = self._evaluation_context.create_bundle(output_pcollection)
      # TODO(ccy): Respect the PubSub source's id_label field.
      for timestamp, message in data:
        if self.source.with_attributes:
          element = message
        else:
          element = message.data
        bundle.output(
            GlobalWindows.windowed_value(element, timestamp=timestamp))
      bundles = [bundle]
    else:
      bundles = []
    if self._applied_ptransform.inputs:
      input_pvalue = self._applied_ptransform.inputs[0]
    else:
      input_pvalue = pvalue.PBegin(self._applied_ptransform.transform.pipeline)
    unprocessed_bundle = self._evaluation_context.create_bundle(
        input_pvalue)

    # TODO(udim): Correct value for watermark hold.
    return TransformResult(self, bundles, [unprocessed_bundle], None,
                           {None: Timestamp.of(time.time())})
開發者ID:charlesccychen,項目名稱:incubator-beam,代碼行數:26,代碼來源:transform_evaluator.py

示例4: _get_element

      def _get_element(message):
        parsed_message = PubsubMessage._from_message(message)
        if timestamp_attribute:
          try:
            rfc3339_or_milli = parsed_message.attributes[timestamp_attribute]
          except KeyError as e:
            raise KeyError('Timestamp attribute not found: %s' % e)
          try:
            timestamp = Timestamp.from_rfc3339(rfc3339_or_milli)
          except ValueError:
            try:
              timestamp = Timestamp(micros=int(rfc3339_or_milli) * 1000)
            except ValueError as e:
              raise ValueError('Bad timestamp value: %s' % e)
        else:
          timestamp = Timestamp.from_rfc3339(message.service_timestamp)

        return timestamp, parsed_message
開發者ID:apsaltis,項目名稱:incubator-beam,代碼行數:18,代碼來源:transform_evaluator.py

示例5: __init__

 def __init__(self, start, end):
   if start is not None or end is not None:
     self._start_object = Timestamp.of(start)
     self._end_object = Timestamp.of(end)
     try:
       self._start_micros = self._start_object.micros
     except OverflowError:
       self._start_micros = (
           MIN_TIMESTAMP.micros if self._start_object.micros < 0
           else MAX_TIMESTAMP.micros)
     try:
       self._end_micros = self._end_object.micros
     except OverflowError:
       self._end_micros = (
           MIN_TIMESTAMP.micros if self._end_object.micros < 0
           else MAX_TIMESTAMP.micros)
   else:
     # Micros must be populated elsewhere.
     self._start_object = self._end_object = None
開發者ID:eralmas7,項目名稱:beam,代碼行數:19,代碼來源:windowed_value.py

示例6: __init__

 def __init__(self, value, timestamp, windows):
   # For performance reasons, only timestamp_micros is stored by default
   # (as a C int). The Timestamp object is created on demand below.
   self.value = value
   if isinstance(timestamp, int):
     self.timestamp_micros = timestamp * 1000000
   else:
     self.timestamp_object = (timestamp if isinstance(timestamp, Timestamp)
                              else Timestamp.of(timestamp))
     self.timestamp_micros = self.timestamp_object.micros
   self.windows = windows
開發者ID:amitsela,項目名稱:incubator-beam,代碼行數:11,代碼來源:windowed_value.py

示例7: finish_bundle

 def finish_bundle(self):
   data = self._read_from_pubsub()
   if data:
     output_pcollection = list(self._outputs)[0]
     bundle = self._evaluation_context.create_bundle(output_pcollection)
     # TODO(ccy): we currently do not use the PubSub message timestamp or
     # respect the PubSub source's id_label field.
     now = Timestamp.of(time.time())
     for message_data in data:
       bundle.output(GlobalWindows.windowed_value(message_data, timestamp=now))
     bundles = [bundle]
   else:
     bundles = []
   if self._applied_ptransform.inputs:
     input_pvalue = self._applied_ptransform.inputs[0]
   else:
     input_pvalue = pvalue.PBegin(self._applied_ptransform.transform.pipeline)
   unprocessed_bundle = self._evaluation_context.create_bundle(
       input_pvalue)
   return TransformResult(
       self._applied_ptransform, bundles,
       [unprocessed_bundle], None, {None: Timestamp.of(time.time())})
開發者ID:gamars,項目名稱:beam,代碼行數:22,代碼來源:transform_evaluator.py

示例8: _get_element

    def _get_element(message):
      parsed_message = PubsubMessage._from_message(message)
      if (timestamp_attribute and
          timestamp_attribute in parsed_message.attributes):
        rfc3339_or_milli = parsed_message.attributes[timestamp_attribute]
        try:
          timestamp = Timestamp.from_rfc3339(rfc3339_or_milli)
        except ValueError:
          try:
            timestamp = Timestamp(micros=int(rfc3339_or_milli) * 1000)
          except ValueError as e:
            raise ValueError('Bad timestamp value: %s' % e)
      else:
        timestamp = Timestamp(message.publish_time.seconds,
                              message.publish_time.nanos // 1000)

      return timestamp, parsed_message
開發者ID:charlesccychen,項目名稱:incubator-beam,代碼行數:17,代碼來源:transform_evaluator.py

示例9: __init__

 def __init__(self, size, period, offset=0):
   if size <= 0:
     raise ValueError('The size parameter must be strictly positive.')
   self.size = Duration.of(size)
   self.period = Duration.of(period)
   self.offset = Timestamp.of(offset) % period
開發者ID:dpmills,項目名稱:incubator-beam,代碼行數:6,代碼來源:window.py

示例10: test_timestamps

 def test_timestamps(self):
   wv = windowed_value.WindowedValue(None, 3, ())
   self.assertEqual(wv.timestamp, Timestamp.of(3))
   self.assertTrue(wv.timestamp is wv.timestamp)
   self.assertEqual(windowed_value.WindowedValue(None, -2.5, ()).timestamp,
                    Timestamp.of(-2.5))
開發者ID:JavierRoger,項目名稱:beam,代碼行數:6,代碼來源:windowed_value_test.py

示例11: test_of

 def test_of(self):
   interval = Timestamp(123)
   self.assertEqual(id(interval), id(Timestamp.of(interval)))
   self.assertEqual(interval, Timestamp.of(123.0))
   with self.assertRaises(TypeError):
     Timestamp.of(Duration(10))
開發者ID:aaltay,項目名稱:incubator-beam,代碼行數:6,代碼來源:timestamp_test.py

示例12: test_from_rfc3339_failure

 def test_from_rfc3339_failure(self):
   with self.assertRaisesRegexp(ValueError, 'parse'):
     Timestamp.from_rfc3339('not rfc3339')
   with self.assertRaisesRegexp(ValueError, 'parse'):
     Timestamp.from_rfc3339('2016-03-18T23:22:59.123456Z unparseable')
開發者ID:JavierRoger,項目名稱:beam,代碼行數:5,代碼來源:timestamp_test.py


注:本文中的apache_beam.utils.timestamp.Timestamp類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。