当前位置: 首页>>代码示例>>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;未经允许,请勿转载。